Files
myeasycms-v2/turbo/generators/templates/package/generator.ts
Giancarlo Buomprisco 4cfb4f936f Open-next Cloudflare / Docker / Setup (#248)
* Add Cloudflare generator with Wrangler and OpenNext support

This update introduces a new Cloudflare generator to streamline configuration and deployment via Wrangler and OpenNext. It registers the necessary templates, modifies project files, and adds Cloudflare-specific scripts and dependencies to the package.json. Additionally, .hbs files are updated in .prettierignore for formatting consistency.

* Add GitHub username prompt and improve setup scripts

Introduce a prompt for GitHub username to personalize project setup. Enhance the setup scripts by adding PNPM verification, configuring `upstream` remote, and removing the `origin` remote. Adjust health check and error handling for better reliability.

* Add Dockerfile generator to turbo generators

Introduced a new generator to create Dockerfile configurations for standalone Next.js applications. This includes modifying `next.config.mjs` for standalone output, updating dependencies in `package.json`, and adding a Dockerfile template. The generator is now registered in the turbo setup.

* Add console-based logger implementation. This is required for edge environments such as Cloudflare.

* Remove deprecated Supabase client utilities

The `server-actions-client`, `route-handler-client`, and `server-component-client` utilities have been removed in favor of `getSupabaseServerClient`. This simplifies and consolidates the API, ensuring consistency across server-side usage. Version bumped to 2.9.0 to reflect breaking changes.
2025-04-29 10:12:08 +08:00

90 lines
2.4 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 }}/eslint.config.mjs',
templateFile: 'templates/package/eslint.config.mjs.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';
},
],
});
}