Files
myeasycms-v2/turbo/generators/templates/package/generator.ts
Giancarlo Buomprisco 7ebff31475 Next.js Supabase V3 (#463)
Version 3 of the kit:
- Radix UI replaced with Base UI (using the Shadcn UI patterns)
- next-intl replaces react-i18next
- enhanceAction deprecated; usage moved to next-safe-action
- main layout now wrapped with [locale] path segment
- Teams only mode
- Layout updates
- Zod v4
- Next.js 16.2
- Typescript 6
- All other dependencies updated
- Removed deprecated Edge CSRF
- Dynamic Github Action runner
2026-03-24 13:40:38 +08:00

84 lines
2.2 KiB
TypeScript

import type { PlopTypes } from '@turbo/gen';
import { execSync } from 'node:child_process';
export function createPackageGenerator(plop: PlopTypes.NodePlopAPI) {
plop.setGenerator('package', {
description: 'Generate a new package for the Monorepo',
prompts: [
{
type: 'input',
name: 'name',
message:
'What is the name of the package? (You can skip the `@kit/` prefix)',
},
{
type: 'input',
name: 'deps',
message:
'Enter a space separated list of dependencies you would like to install',
},
],
actions: [
(answers) => {
if ('name' in answers && typeof answers.name === 'string') {
if (answers.name.startsWith('@kit/')) {
answers.name = answers.name.replace('@kit/', '');
}
}
return 'Config sanitized';
},
{
type: 'add',
path: 'packages/{{ name }}/package.json',
templateFile: 'templates/package/package.json.hbs',
},
{
type: 'add',
path: 'packages/{{ name }}/tsconfig.json',
templateFile: 'templates/package/tsconfig.json.hbs',
},
{
type: 'add',
path: 'packages/{{ name }}/index.ts',
template: "export * from './src';",
},
{
type: 'add',
path: 'packages/{{ name }}/src/index.ts',
template: "export const name = '{{ name }}';",
},
{
type: 'modify',
path: 'packages/{{ name }}/package.json',
async transform(content, answers) {
const pkg = JSON.parse(content);
for (const dep of answers.deps.split(' ').filter(Boolean)) {
const version = await fetch(
`https://registry.npmjs.org/-/package/${dep}/dist-tags`,
)
.then((res) => res.json())
.then((json) => json.latest);
pkg.dependencies![dep] = `^${version}`;
}
return JSON.stringify(pkg, null, 2);
},
},
async () => {
/**
* Install deps and format everything
*/
execSync('pnpm i', {
stdio: 'inherit',
});
execSync(`pnpm run format:fix`);
return 'Package scaffolded';
},
],
});
}