Skip to content

Instantly share code, notes, and snippets.

@ygkn
Last active March 25, 2022 03:21
Show Gist options
  • Save ygkn/954f34992aa13211f2b6277805ef2521 to your computer and use it in GitHub Desktop.
Save ygkn/954f34992aa13211f2b6277805ef2521 to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S deno run
const dirs =
`members/[memberId]/reflections/[reflectionId]/categories/[categoryId]`.split(
'/'
);
const toUpperCamelCase = (str: string) =>
`${str[0].toUpperCase()}${str.slice(1)}`;
for (const i of dirs.keys()) {
const pageComponentName = `${toUpperCamelCase(
dirs[i][0] === '[' ? dirs[i].slice(1, -3) : `${dirs[i]}List`
)}Page`;
const title = `${toUpperCamelCase(
dirs[i][0] === '[' ? dirs[i].slice(1, -3) : `${dirs[i]} 一覧`
)}`;
const path = dirs
.slice(0, i + 1)
.concat('index.page.tsx')
.join('/');
const content = `import type { NextPage } from 'next';
import { ContentLayout } from '@/components/Layout/ContentLayout';
const ${pageComponentName}: NextPage = () => {
return (
<ContentLayout title="${title}">
<div></div>
</ContentLayout>
);
};
export default ${pageComponentName};
`;
Deno.writeTextFileSync(path, content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment