create-fs-app 2.0.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +254 -150
- package/dist/cli/output.js +223 -0
- package/dist/cli/program.js +403 -0
- package/dist/cli/resolve-config.js +264 -0
- package/dist/cli/ui/errors.js +27 -0
- package/dist/cli/ui/help.js +43 -0
- package/dist/cli/ui/hints.js +22 -0
- package/dist/cli/ui/layer-log.js +109 -0
- package/dist/cli/ui/list.js +115 -0
- package/dist/cli/ui/text.js +56 -0
- package/dist/cli/wizard.js +275 -0
- package/dist/core/auth/jwt.js +478 -0
- package/dist/core/download.js +109 -0
- package/dist/core/health-check.js +42 -44
- package/dist/core/presets.js +75 -117
- package/dist/core/registry-fetch.js +101 -81
- package/dist/core/registry.fallback.json +892 -0
- package/dist/core/scaffold.js +121 -75
- package/dist/core/stack.js +109 -0
- package/dist/core/template-cache.js +95 -154
- package/dist/core/template-clone.js +351 -655
- package/dist/core/template-list.js +19 -141
- package/dist/core/template-registry.js +116 -216
- package/dist/index.js +13 -963
- package/dist/types/index.js +30 -82
- package/dist/utils/cli-error.js +15 -0
- package/dist/utils/exec.js +62 -0
- package/dist/utils/logger.js +10 -9
- package/dist/utils/theme.js +87 -0
- package/dist/utils/validation.js +24 -13
- package/package.json +22 -25
- package/dist/core/health-check.d.ts +0 -15
- package/dist/core/health-check.js.map +0 -1
- package/dist/core/presets.d.ts +0 -48
- package/dist/core/presets.js.map +0 -1
- package/dist/core/registry-fetch.d.ts +0 -20
- package/dist/core/registry-fetch.js.map +0 -1
- package/dist/core/scaffold.d.ts +0 -40
- package/dist/core/scaffold.js.map +0 -1
- package/dist/core/template-cache.d.ts +0 -38
- package/dist/core/template-cache.js.map +0 -1
- package/dist/core/template-clone.d.ts +0 -27
- package/dist/core/template-clone.js.map +0 -1
- package/dist/core/template-list.d.ts +0 -45
- package/dist/core/template-list.js.map +0 -1
- package/dist/core/template-registry.d.ts +0 -78
- package/dist/core/template-registry.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -102
- package/dist/types/index.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -15
- package/dist/utils/errors.js +0 -50
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -37
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -48
- package/dist/utils/validation.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,964 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { displayAvailableTemplates, getContributedByName, getContributedByUUID, getOfficialByName, } from './core/template-list.js';
|
|
16
|
-
import { assertValidProjectName, isValidUUID } from './utils/validation.js';
|
|
17
|
-
import { Logger } from './utils/logger.js';
|
|
18
|
-
import { savePreset, loadPreset, listPresets, deletePreset, getBuiltinPreset, isBuiltinPresetName, userPresetExists, BUILTIN_PRESETS, } from './core/presets.js';
|
|
19
|
-
import { runHealthCheck, displayHealthCheckResults } from './core/health-check.js';
|
|
20
|
-
import { clearCache, getCacheStats } from './core/template-cache.js';
|
|
21
|
-
import { createCustomTemplate } from './core/template-registry.js';
|
|
22
|
-
import { getRemoteRegistry, clearRegistryCache } from './core/registry-fetch.js';
|
|
23
|
-
import { setActiveRegistry } from './core/template-registry.js';
|
|
24
|
-
import { parseTemplateUrl } from './utils/validation.js';
|
|
25
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
-
const __dirname = dirname(__filename);
|
|
27
|
-
// Check for updates
|
|
28
|
-
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
|
29
|
-
updateNotifier({ pkg }).notify();
|
|
30
|
-
const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
-
async function welcome() {
|
|
32
|
-
// Add spacing to separate from previous commands without clearing history
|
|
33
|
-
console.log('\n'.repeat(2));
|
|
34
|
-
// ASCII art title with filled/solid characters
|
|
35
|
-
const title = figlet.textSync('create-fs-app', {
|
|
36
|
-
font: 'ANSI Shadow',
|
|
37
|
-
horizontalLayout: 'fitted'
|
|
38
|
-
});
|
|
39
|
-
console.log(gradient.pastel.multiline(title));
|
|
40
|
-
console.log();
|
|
41
|
-
// Welcome box
|
|
42
|
-
const welcomeMsg = boxen(chalk.white.bold('Create production-ready full-stack applications\n') +
|
|
43
|
-
chalk.gray('Template-based • Fast • Customizable\n\n') +
|
|
44
|
-
chalk.cyan('✓ TypeScript only (no JavaScript projects)\n') +
|
|
45
|
-
chalk.cyan('✓ Multiple monorepo frameworks\n') +
|
|
46
|
-
chalk.cyan('✓ Customizable frontend & backend\n') +
|
|
47
|
-
chalk.cyan('✓ Database & ORM selection\n') +
|
|
48
|
-
chalk.cyan('✓ Docker & Testing setup'), {
|
|
49
|
-
padding: 1,
|
|
50
|
-
margin: 1,
|
|
51
|
-
borderStyle: 'round',
|
|
52
|
-
borderColor: 'cyan',
|
|
53
|
-
title: chalk.bold.cyan(`v${pkg.version}`),
|
|
54
|
-
titleAlignment: 'center'
|
|
55
|
-
});
|
|
56
|
-
console.log(welcomeMsg);
|
|
57
|
-
console.log();
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Build configuration from CLI options
|
|
61
|
-
*/
|
|
62
|
-
/**
|
|
63
|
-
* Case-insensitive enum validator — shared by buildConfigFromOptions and --yes/--template paths.
|
|
64
|
-
*/
|
|
65
|
-
function validateEnum(value, enumObj, fieldName) {
|
|
66
|
-
const validValues = Object.values(enumObj);
|
|
67
|
-
const found = validValues.find((v) => v.toLowerCase() === value.toLowerCase());
|
|
68
|
-
if (!found) {
|
|
69
|
-
console.log(chalk.red(`\n❌ Invalid ${fieldName}: "${value}"\n`));
|
|
70
|
-
console.log(chalk.cyan(`Valid options: ${validValues.join(', ')}\n`));
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
return found;
|
|
74
|
-
}
|
|
75
|
-
function buildConfigFromOptions(name, options) {
|
|
76
|
-
// Validate required fields
|
|
77
|
-
if (!name) {
|
|
78
|
-
Logger.error('Project name is required.');
|
|
79
|
-
console.log(chalk.cyan('Usage: create-fs-app <project-name> [options]\n'));
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
82
|
-
// Validate project name
|
|
83
|
-
assertValidProjectName(name);
|
|
84
|
-
if (!options.monorepo || !options.frontend || !options.backend || !options.database) {
|
|
85
|
-
Logger.error('When using CLI options, you must provide:');
|
|
86
|
-
console.log(chalk.yellow(' --monorepo <framework>'));
|
|
87
|
-
console.log(chalk.yellow(' --frontend <framework>'));
|
|
88
|
-
console.log(chalk.yellow(' --backend <framework>'));
|
|
89
|
-
console.log(chalk.yellow(' --database <db>\n'));
|
|
90
|
-
console.log(chalk.cyan('💡 Or run without options for interactive mode.\n'));
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
const frontendFramework = validateEnum(options.frontend, FrontendFramework, 'frontend framework');
|
|
94
|
-
const config = {
|
|
95
|
-
name,
|
|
96
|
-
monorepo: validateEnum(options.monorepo, MonorepoFramework, 'monorepo framework'),
|
|
97
|
-
packageManager: options.packageManager
|
|
98
|
-
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
99
|
-
: PackageManager.NPM,
|
|
100
|
-
ci: options.ci === true,
|
|
101
|
-
apps: {
|
|
102
|
-
frontend: {
|
|
103
|
-
framework: frontendFramework,
|
|
104
|
-
styling: options.styling || 'tailwind',
|
|
105
|
-
eslint: options.eslint !== false, // default true
|
|
106
|
-
prettier: options.prettier !== false, // default true
|
|
107
|
-
// Turbopack only valid for Next.js
|
|
108
|
-
turbopack: frontendFramework === 'next.js' && options.turbopack === true,
|
|
109
|
-
},
|
|
110
|
-
backend: {
|
|
111
|
-
framework: validateEnum(options.backend, BackendFramework, 'backend framework'),
|
|
112
|
-
database: validateEnum(options.database, Database, 'database'),
|
|
113
|
-
orm: options.orm,
|
|
114
|
-
apiStyle: options.apiStyle
|
|
115
|
-
? validateEnum(options.apiStyle, ApiStyle, 'API style')
|
|
116
|
-
: ApiStyle.REST,
|
|
117
|
-
auth: options.auth
|
|
118
|
-
? validateEnum(options.auth, AuthStrategy, 'auth strategy')
|
|
119
|
-
: AuthStrategy.None,
|
|
120
|
-
docker: options.docker !== false, // default true
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
// Validate the config with Zod
|
|
125
|
-
try {
|
|
126
|
-
return ProjectConfigSchema.parse(config);
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
Logger.error('Invalid configuration: ' + (error instanceof Error ? error.message : String(error)));
|
|
130
|
-
process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async function promptForConfiguration(projectName) {
|
|
134
|
-
const onCancel = () => {
|
|
135
|
-
console.log(chalk.yellow('\n\nOperation cancelled by user'));
|
|
136
|
-
process.exit(0);
|
|
137
|
-
};
|
|
138
|
-
// ── Step 1: Project name ────────────────────────────────────────────────
|
|
139
|
-
let name = projectName;
|
|
140
|
-
if (!name) {
|
|
141
|
-
const { projectName: n } = await prompts({
|
|
142
|
-
type: 'text',
|
|
143
|
-
name: 'projectName',
|
|
144
|
-
message: 'Project name:',
|
|
145
|
-
initial: 'my-fs-app',
|
|
146
|
-
validate: (v) => v.trim().length > 0 || 'Name required'
|
|
147
|
-
}, { onCancel });
|
|
148
|
-
name = n;
|
|
149
|
-
}
|
|
150
|
-
// ── Step 2: Monorepo + package manager ─────────────────────────────────
|
|
151
|
-
const { monorepo, packageManager } = await prompts([
|
|
152
|
-
{
|
|
153
|
-
type: 'select',
|
|
154
|
-
name: 'monorepo',
|
|
155
|
-
message: 'Monorepo tool:',
|
|
156
|
-
choices: [
|
|
157
|
-
{ title: 'Turborepo — fast build caching, simple config', value: 'turborepo' },
|
|
158
|
-
{ title: 'Nx — powerful task graph, generators', value: 'nx' },
|
|
159
|
-
],
|
|
160
|
-
initial: 0
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
type: 'select',
|
|
164
|
-
name: 'packageManager',
|
|
165
|
-
message: 'Package manager:',
|
|
166
|
-
choices: [
|
|
167
|
-
{ title: 'npm', value: 'npm' },
|
|
168
|
-
{ title: 'pnpm — faster installs, disk efficient', value: 'pnpm' },
|
|
169
|
-
{ title: 'yarn', value: 'yarn' },
|
|
170
|
-
],
|
|
171
|
-
initial: 0
|
|
172
|
-
},
|
|
173
|
-
], { onCancel });
|
|
174
|
-
// ── Step 3: Frontend ────────────────────────────────────────────────────
|
|
175
|
-
const { frontendFramework, styling } = await prompts([
|
|
176
|
-
{
|
|
177
|
-
type: 'select',
|
|
178
|
-
name: 'frontendFramework',
|
|
179
|
-
message: 'Frontend framework:',
|
|
180
|
-
choices: [
|
|
181
|
-
{ title: 'Next.js — App Router, SSR, RSC', value: 'next.js' },
|
|
182
|
-
{ title: 'React — Vite, SPA/CSR', value: 'react' },
|
|
183
|
-
{ title: 'Vue — Vite, Options/Composition API', value: 'vue' },
|
|
184
|
-
{ title: 'Nuxt — SSR for Vue', value: 'nuxt' },
|
|
185
|
-
{ title: 'Angular — full framework', value: 'angular' },
|
|
186
|
-
],
|
|
187
|
-
initial: 0
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
type: 'select',
|
|
191
|
-
name: 'styling',
|
|
192
|
-
message: 'Styling solution:',
|
|
193
|
-
choices: [
|
|
194
|
-
{ title: 'Tailwind CSS — utility-first', value: 'tailwind' },
|
|
195
|
-
{ title: 'CSS — plain stylesheets', value: 'css' },
|
|
196
|
-
{ title: 'SCSS/Sass — CSS with superpowers', value: 'scss' },
|
|
197
|
-
{ title: 'Styled Components — CSS-in-JS', value: 'styled-components' },
|
|
198
|
-
],
|
|
199
|
-
initial: 0
|
|
200
|
-
},
|
|
201
|
-
], { onCancel });
|
|
202
|
-
// Turbopack — only relevant for Next.js
|
|
203
|
-
let turbopack = false;
|
|
204
|
-
if (frontendFramework === 'next.js') {
|
|
205
|
-
const { tp } = await prompts({
|
|
206
|
-
type: 'confirm',
|
|
207
|
-
name: 'tp',
|
|
208
|
-
message: 'Enable Turbopack? (faster dev server for Next.js)',
|
|
209
|
-
initial: true
|
|
210
|
-
}, { onCancel });
|
|
211
|
-
turbopack = tp;
|
|
212
|
-
}
|
|
213
|
-
// ── Step 4: Code quality ────────────────────────────────────────────────
|
|
214
|
-
const { eslint, prettier } = await prompts([
|
|
215
|
-
{
|
|
216
|
-
type: 'confirm',
|
|
217
|
-
name: 'eslint',
|
|
218
|
-
message: 'Add ESLint?',
|
|
219
|
-
initial: true
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
type: 'confirm',
|
|
223
|
-
name: 'prettier',
|
|
224
|
-
message: 'Add Prettier?',
|
|
225
|
-
initial: true
|
|
226
|
-
},
|
|
227
|
-
], { onCancel });
|
|
228
|
-
// ── Step 5: Backend ─────────────────────────────────────────────────────
|
|
229
|
-
const { backendFramework, database, orm } = await prompts([
|
|
230
|
-
{
|
|
231
|
-
type: 'select',
|
|
232
|
-
name: 'backendFramework',
|
|
233
|
-
message: 'Backend framework:',
|
|
234
|
-
choices: [
|
|
235
|
-
{ title: 'NestJS — TypeScript-first, modular, decorators', value: 'nest.js' },
|
|
236
|
-
{ title: 'Express — minimal, flexible, battle-tested', value: 'express' },
|
|
237
|
-
{ title: 'Fastify — high performance, schema validation', value: 'fastify-ts' },
|
|
238
|
-
{ title: 'Koa — lightweight, async middleware', value: 'koa' },
|
|
239
|
-
],
|
|
240
|
-
initial: 0
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
type: 'select',
|
|
244
|
-
name: 'database',
|
|
245
|
-
message: 'Database:',
|
|
246
|
-
choices: [
|
|
247
|
-
{ title: 'PostgreSQL — relational, ACID, powerful', value: 'postgresql' },
|
|
248
|
-
{ title: 'MongoDB — document, flexible schema', value: 'mongodb' },
|
|
249
|
-
{ title: 'MySQL — relational, widely supported', value: 'mysql' },
|
|
250
|
-
{ title: 'SQLite — file-based, zero setup', value: 'sqlite' },
|
|
251
|
-
],
|
|
252
|
-
initial: 0
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
type: 'select',
|
|
256
|
-
name: 'orm',
|
|
257
|
-
message: 'ORM / ODM:',
|
|
258
|
-
choices: [
|
|
259
|
-
{ title: 'Prisma — type-safe, migrations, Studio', value: 'prisma' },
|
|
260
|
-
{ title: 'TypeORM — decorators, ActiveRecord/DataMapper', value: 'typeorm' },
|
|
261
|
-
{ title: 'Mongoose — MongoDB ODM, schemas', value: 'mongoose' },
|
|
262
|
-
{ title: 'Drizzle — lightweight, SQL-like', value: 'drizzle' },
|
|
263
|
-
],
|
|
264
|
-
initial: 0
|
|
265
|
-
},
|
|
266
|
-
], { onCancel });
|
|
267
|
-
// ── Step 6: API style ───────────────────────────────────────────────────
|
|
268
|
-
const { apiStyle } = await prompts({
|
|
269
|
-
type: 'select',
|
|
270
|
-
name: 'apiStyle',
|
|
271
|
-
message: 'API style:',
|
|
272
|
-
choices: [
|
|
273
|
-
{ title: 'REST — standard HTTP endpoints (recommended)', value: 'rest' },
|
|
274
|
-
{ title: 'GraphQL — flexible queries with Apollo/Mercurius', value: 'graphql' },
|
|
275
|
-
{ title: 'Both — REST + GraphQL side by side', value: 'both' },
|
|
276
|
-
],
|
|
277
|
-
initial: 0
|
|
278
|
-
}, { onCancel });
|
|
279
|
-
// ── Step 7: Auth ────────────────────────────────────────────────────────
|
|
280
|
-
const { auth } = await prompts({
|
|
281
|
-
type: 'select',
|
|
282
|
-
name: 'auth',
|
|
283
|
-
message: 'Authentication scaffolding:',
|
|
284
|
-
choices: [
|
|
285
|
-
{ title: 'None — skip auth, add manually later', value: 'none' },
|
|
286
|
-
{ title: 'JWT — login/register endpoints + guards/middleware', value: 'jwt' },
|
|
287
|
-
],
|
|
288
|
-
initial: 0
|
|
289
|
-
}, { onCancel });
|
|
290
|
-
// ── Step 8: Docker + CI ────────────────────────────────────────────────
|
|
291
|
-
const { docker, ci } = await prompts([
|
|
292
|
-
{
|
|
293
|
-
type: 'confirm',
|
|
294
|
-
name: 'docker',
|
|
295
|
-
message: 'Include Docker / Docker Compose?',
|
|
296
|
-
initial: true
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
type: 'confirm',
|
|
300
|
-
name: 'ci',
|
|
301
|
-
message: 'Add GitHub Actions CI? (lint → build on push/PR)',
|
|
302
|
-
initial: false
|
|
303
|
-
},
|
|
304
|
-
], { onCancel });
|
|
305
|
-
// ── Build + validate config ─────────────────────────────────────────────
|
|
306
|
-
const config = {
|
|
307
|
-
name: name,
|
|
308
|
-
monorepo,
|
|
309
|
-
packageManager,
|
|
310
|
-
ci,
|
|
311
|
-
apps: {
|
|
312
|
-
frontend: {
|
|
313
|
-
framework: frontendFramework,
|
|
314
|
-
styling,
|
|
315
|
-
eslint,
|
|
316
|
-
prettier,
|
|
317
|
-
turbopack,
|
|
318
|
-
},
|
|
319
|
-
backend: {
|
|
320
|
-
framework: backendFramework,
|
|
321
|
-
database,
|
|
322
|
-
orm,
|
|
323
|
-
apiStyle,
|
|
324
|
-
auth,
|
|
325
|
-
docker,
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
return ProjectConfigSchema.parse(config);
|
|
330
|
-
}
|
|
331
|
-
async function main() {
|
|
332
|
-
// ── Hydrate registry from GitHub (non-blocking, 5 s timeout) ────────────
|
|
333
|
-
// Silently falls back to the hardcoded registry on any failure so the CLI
|
|
334
|
-
// always works offline. New templates published to the templates repo are
|
|
335
|
-
// picked up automatically without a CLI release.
|
|
336
|
-
// Store promise so list/info commands can await it (max 3 s)
|
|
337
|
-
const registryReady = getRemoteRegistry()
|
|
338
|
-
.then((remote) => { if (remote)
|
|
339
|
-
setActiveRegistry(remote); })
|
|
340
|
-
.catch(() => { });
|
|
341
|
-
const program = new Command();
|
|
342
|
-
program
|
|
343
|
-
.name('create-fs-app')
|
|
344
|
-
.description('Create a full-stack monorepo application')
|
|
345
|
-
.version(pkg.version);
|
|
346
|
-
// Main create command
|
|
347
|
-
program
|
|
348
|
-
.argument('[name]', 'The name of your application')
|
|
349
|
-
.option('-t, --template <name>', 'Use a predefined template')
|
|
350
|
-
.option('--template-url <url>', 'Use a custom template from GitHub URL')
|
|
351
|
-
.option('--preset <name>', 'Use a configuration preset')
|
|
352
|
-
.option('--monorepo <framework>', 'Monorepo framework (turborepo, nx)')
|
|
353
|
-
.option('--frontend <framework>', 'Frontend framework (react, next.js, vue, nuxt, angular)')
|
|
354
|
-
.option('--backend <framework>', 'Backend framework (express, nest.js, fastify-ts, koa)')
|
|
355
|
-
.option('--database <db>', 'Database (postgresql, mongodb, mysql, sqlite)')
|
|
356
|
-
.option('--orm <orm>', 'ORM (prisma, typeorm, mongoose, drizzle)')
|
|
357
|
-
.option('--package-manager <pm>', 'Package manager (npm, yarn, pnpm)')
|
|
358
|
-
.option('--styling <style>', 'Styling solution (css, scss, tailwind, styled-components)')
|
|
359
|
-
.option('--eslint', 'Enable ESLint (default: true)')
|
|
360
|
-
.option('--no-eslint', 'Disable ESLint')
|
|
361
|
-
.option('--prettier', 'Enable Prettier (default: true)')
|
|
362
|
-
.option('--no-prettier', 'Disable Prettier')
|
|
363
|
-
.option('--turbopack', 'Enable Turbopack dev server (Next.js only)')
|
|
364
|
-
.option('--api-style <style>', 'API style: rest | graphql | both (default: rest)')
|
|
365
|
-
.option('--auth <strategy>', 'Auth scaffolding: none | jwt (default: none)')
|
|
366
|
-
.option('--docker', 'Include Docker / Docker Compose (default: true)')
|
|
367
|
-
.option('--no-docker', 'Skip Docker configuration')
|
|
368
|
-
.option('--ci', 'Add GitHub Actions CI workflow')
|
|
369
|
-
.option('--no-ci', 'Skip GitHub Actions CI')
|
|
370
|
-
.option('--no-git', 'Skip git initialization')
|
|
371
|
-
.option('--install', 'Install dependencies after scaffolding (default: false)')
|
|
372
|
-
.option('--no-cache', 'Skip template caching')
|
|
373
|
-
.option('--local-templates <path>', 'Use local templates repo instead of GitHub (for development)')
|
|
374
|
-
.option('-y, --yes', 'Skip prompts and use defaults')
|
|
375
|
-
.action(async (name, options) => {
|
|
376
|
-
await welcome();
|
|
377
|
-
try {
|
|
378
|
-
let projectConfig;
|
|
379
|
-
let customTemplate = null;
|
|
380
|
-
// When true the availability check against the registry is skipped (custom URL supplies its own template)
|
|
381
|
-
let skipAvailabilityCheck = false;
|
|
382
|
-
// Check if using preset
|
|
383
|
-
if (options.preset) {
|
|
384
|
-
if (!name) {
|
|
385
|
-
Logger.error('Project name is required when using --preset.');
|
|
386
|
-
console.log(chalk.cyan('Usage: create-fs-app <project-name> --preset <preset-name>\n'));
|
|
387
|
-
process.exit(1);
|
|
388
|
-
}
|
|
389
|
-
// Try built-in preset first
|
|
390
|
-
let preset = getBuiltinPreset(options.preset);
|
|
391
|
-
// If not built-in, try user preset
|
|
392
|
-
if (!preset) {
|
|
393
|
-
preset = await loadPreset(options.preset);
|
|
394
|
-
}
|
|
395
|
-
if (!preset) {
|
|
396
|
-
Logger.error(`Preset "${options.preset}" not found`);
|
|
397
|
-
console.log(chalk.cyan('\n💡 Use ') + chalk.white.bold('create-fs-app preset list') + chalk.cyan(' to see available presets.\n'));
|
|
398
|
-
process.exit(1);
|
|
399
|
-
}
|
|
400
|
-
projectConfig = {
|
|
401
|
-
name,
|
|
402
|
-
...preset.config
|
|
403
|
-
};
|
|
404
|
-
console.log();
|
|
405
|
-
const infoBox = boxen(chalk.cyan.bold('🎯 Using Preset\n\n') +
|
|
406
|
-
chalk.white(`Preset: `) + chalk.green(preset.name) + '\n' +
|
|
407
|
-
(preset.description ? chalk.white(`Description: `) + chalk.gray(preset.description) : ''), {
|
|
408
|
-
padding: 1,
|
|
409
|
-
margin: 1,
|
|
410
|
-
borderStyle: 'round',
|
|
411
|
-
borderColor: 'cyan'
|
|
412
|
-
});
|
|
413
|
-
console.log(infoBox);
|
|
414
|
-
}
|
|
415
|
-
// Check if using custom template URL
|
|
416
|
-
else if (options.templateUrl) {
|
|
417
|
-
if (!name) {
|
|
418
|
-
Logger.error('Project name is required when using --template-url.');
|
|
419
|
-
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template-url <url>\n'));
|
|
420
|
-
process.exit(1);
|
|
421
|
-
}
|
|
422
|
-
// Parse URL — extracts repoUrl, branch, and optional subfolder
|
|
423
|
-
const parsed = parseTemplateUrl(options.templateUrl);
|
|
424
|
-
if (!parsed.valid) {
|
|
425
|
-
Logger.error(parsed.error);
|
|
426
|
-
process.exit(1);
|
|
427
|
-
}
|
|
428
|
-
const { repoUrl, branch, subfolder } = parsed.parsed;
|
|
429
|
-
// Build the TemplateMetadata directly from the parsed URL
|
|
430
|
-
customTemplate = createCustomTemplate(repoUrl, branch, subfolder);
|
|
431
|
-
// Minimal projectConfig — only name and pm matter here; the registry is not used
|
|
432
|
-
projectConfig = {
|
|
433
|
-
name,
|
|
434
|
-
monorepo: 'turborepo',
|
|
435
|
-
packageManager: options.packageManager
|
|
436
|
-
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
437
|
-
: PackageManager.NPM,
|
|
438
|
-
ci: options.ci === true,
|
|
439
|
-
apps: {
|
|
440
|
-
frontend: {
|
|
441
|
-
framework: 'react',
|
|
442
|
-
styling: 'tailwind',
|
|
443
|
-
eslint: true,
|
|
444
|
-
prettier: true,
|
|
445
|
-
turbopack: false,
|
|
446
|
-
},
|
|
447
|
-
backend: {
|
|
448
|
-
framework: 'express',
|
|
449
|
-
database: 'postgresql',
|
|
450
|
-
apiStyle: 'rest',
|
|
451
|
-
auth: 'none',
|
|
452
|
-
docker: options.docker !== false,
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
// Custom template bypasses the registry — skip availability check
|
|
457
|
-
skipAvailabilityCheck = true;
|
|
458
|
-
console.log();
|
|
459
|
-
const infoBox = boxen(chalk.cyan.bold('🔗 Using Custom Template\n\n') +
|
|
460
|
-
chalk.white('Repo: ') + chalk.green(repoUrl) + '\n' +
|
|
461
|
-
chalk.white('Branch: ') + chalk.green(branch) +
|
|
462
|
-
(subfolder ? '\n' + chalk.white('Folder: ') + chalk.green(subfolder) : ''), {
|
|
463
|
-
padding: 1,
|
|
464
|
-
margin: 1,
|
|
465
|
-
borderStyle: 'round',
|
|
466
|
-
borderColor: 'cyan'
|
|
467
|
-
});
|
|
468
|
-
console.log(infoBox);
|
|
469
|
-
}
|
|
470
|
-
// --template: contributed templates only (UUID-only mode)
|
|
471
|
-
else if (options.template) {
|
|
472
|
-
// --template only accepts UUID v4
|
|
473
|
-
if (!isValidUUID(options.template)) {
|
|
474
|
-
console.log(boxen(chalk.red.bold('❌ Invalid --template value\n\n') +
|
|
475
|
-
chalk.white('--template only accepts a UUID v4 (the unique ID of a contributed template).\n\n') +
|
|
476
|
-
chalk.gray('Find the UUID with:\n') +
|
|
477
|
-
chalk.cyan(' create-fs-app list --contributed\n\n') +
|
|
478
|
-
chalk.gray('Then use it:\n') +
|
|
479
|
-
chalk.cyan(` create-fs-app my-app --template <uuid>`), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'red' }));
|
|
480
|
-
process.exit(1);
|
|
481
|
-
}
|
|
482
|
-
// Find in contributed registry only
|
|
483
|
-
const match = getContributedByUUID(options.template);
|
|
484
|
-
if (!match) {
|
|
485
|
-
console.log(boxen(chalk.red.bold('❌ Contributed Template Not Found\n\n') +
|
|
486
|
-
chalk.white(`No contributed template has UUID "${options.template}".\n\n`) +
|
|
487
|
-
chalk.cyan('💡 Browse contributed templates and copy a UUID:\n') +
|
|
488
|
-
chalk.cyan(' create-fs-app list --contributed'), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'red' }));
|
|
489
|
-
process.exit(1);
|
|
490
|
-
}
|
|
491
|
-
if (!name) {
|
|
492
|
-
console.log(chalk.red('\n❌ Project name is required when using --template.\n'));
|
|
493
|
-
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template <uuid>\n'));
|
|
494
|
-
process.exit(1);
|
|
495
|
-
}
|
|
496
|
-
// Extract stack config from the base 5 segments of the key
|
|
497
|
-
const FRAMEWORK_MAP = {
|
|
498
|
-
nextjs: 'next.js',
|
|
499
|
-
nestjs: 'nest.js',
|
|
500
|
-
fastifyts: 'fastify-ts',
|
|
501
|
-
react: 'react',
|
|
502
|
-
express: 'express',
|
|
503
|
-
koa: 'koa',
|
|
504
|
-
};
|
|
505
|
-
const parts = match.key.split('-');
|
|
506
|
-
const tplFrontend = (FRAMEWORK_MAP[parts[1]] ?? parts[1]);
|
|
507
|
-
const tplBackend = (FRAMEWORK_MAP[parts[2]] ?? parts[2]);
|
|
508
|
-
projectConfig = {
|
|
509
|
-
name,
|
|
510
|
-
monorepo: parts[0],
|
|
511
|
-
packageManager: options.packageManager
|
|
512
|
-
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
513
|
-
: PackageManager.NPM,
|
|
514
|
-
ci: options.ci === true,
|
|
515
|
-
apps: {
|
|
516
|
-
frontend: {
|
|
517
|
-
framework: tplFrontend,
|
|
518
|
-
styling: 'tailwind',
|
|
519
|
-
eslint: true,
|
|
520
|
-
prettier: true,
|
|
521
|
-
turbopack: false,
|
|
522
|
-
},
|
|
523
|
-
backend: {
|
|
524
|
-
framework: tplBackend,
|
|
525
|
-
database: parts[3],
|
|
526
|
-
orm: parts[4],
|
|
527
|
-
apiStyle: 'rest',
|
|
528
|
-
auth: 'none',
|
|
529
|
-
docker: true,
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
customTemplate = match.metadata;
|
|
534
|
-
skipAvailabilityCheck = true;
|
|
535
|
-
const contrib = match.metadata.contributor;
|
|
536
|
-
console.log();
|
|
537
|
-
console.log(boxen(chalk.yellow.bold('◆ Using Contributed Template\n\n') +
|
|
538
|
-
chalk.white('Template: ') + chalk.yellow(match.key) + '\n' +
|
|
539
|
-
chalk.white('UUID: ') + chalk.dim(match.metadata.id ?? options.template) + '\n' +
|
|
540
|
-
(contrib
|
|
541
|
-
? chalk.white('By: ') + chalk.cyan(`@${contrib.github}`) + chalk.dim(` ${contrib.url}`) + '\n' +
|
|
542
|
-
chalk.white('Repo: ') + chalk.dim(contrib.repoUrl) + '\n'
|
|
543
|
-
: '') +
|
|
544
|
-
chalk.white('Description: ') + chalk.gray(match.metadata.description), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'yellow' }));
|
|
545
|
-
}
|
|
546
|
-
// --yes: fill missing flags with saas-starter defaults, skip all prompts
|
|
547
|
-
else if (options.yes) {
|
|
548
|
-
if (!name) {
|
|
549
|
-
Logger.error('Project name is required when using --yes.');
|
|
550
|
-
console.log(chalk.cyan('Usage: create-fs-app <project-name> [options] --yes\n'));
|
|
551
|
-
process.exit(1);
|
|
552
|
-
}
|
|
553
|
-
// Merge any explicit flags with defaults — explicit always wins
|
|
554
|
-
const withDefaults = {
|
|
555
|
-
...options,
|
|
556
|
-
monorepo: options.monorepo ?? 'turborepo',
|
|
557
|
-
frontend: options.frontend ?? 'next.js',
|
|
558
|
-
backend: options.backend ?? 'nest.js',
|
|
559
|
-
database: options.database ?? 'postgresql',
|
|
560
|
-
orm: options.orm ?? 'prisma',
|
|
561
|
-
};
|
|
562
|
-
projectConfig = buildConfigFromOptions(name, withDefaults);
|
|
563
|
-
// Show resolved configuration
|
|
564
|
-
console.log(chalk.cyan('\n⚡ Using defaults (--yes)\n'));
|
|
565
|
-
console.log(chalk.gray(' Project:'), chalk.white(projectConfig.name));
|
|
566
|
-
console.log(chalk.gray(' Monorepo:'), chalk.white(projectConfig.monorepo));
|
|
567
|
-
console.log(chalk.gray(' Pkg manager:'), chalk.white(projectConfig.packageManager));
|
|
568
|
-
console.log(chalk.gray(' Frontend:'), chalk.white(projectConfig.apps.frontend.framework));
|
|
569
|
-
console.log(chalk.gray(' Styling:'), chalk.white(projectConfig.apps.frontend.styling));
|
|
570
|
-
console.log(chalk.gray(' Backend:'), chalk.white(projectConfig.apps.backend.framework));
|
|
571
|
-
console.log(chalk.gray(' Database:'), chalk.white(projectConfig.apps.backend.database));
|
|
572
|
-
console.log(chalk.gray(' ORM:'), chalk.white(projectConfig.apps.backend.orm ?? 'none'));
|
|
573
|
-
console.log(chalk.gray(' Docker:'), chalk.white(projectConfig.apps.backend.docker ? 'yes' : 'no'));
|
|
574
|
-
console.log(chalk.gray(' CI:'), chalk.white(projectConfig.ci ? 'yes' : 'no'));
|
|
575
|
-
console.log();
|
|
576
|
-
}
|
|
577
|
-
// Check if stack options provided via CLI
|
|
578
|
-
else if (options.monorepo || options.frontend || options.backend) {
|
|
579
|
-
projectConfig = buildConfigFromOptions(name, options);
|
|
580
|
-
// Show detected configuration
|
|
581
|
-
console.log(chalk.cyan('\n📋 Configuration from CLI options:\n'));
|
|
582
|
-
console.log(chalk.gray(' Project:'), chalk.white(projectConfig.name));
|
|
583
|
-
console.log(chalk.gray(' Monorepo:'), chalk.white(projectConfig.monorepo));
|
|
584
|
-
console.log(chalk.gray(' Pkg manager:'), chalk.white(projectConfig.packageManager));
|
|
585
|
-
console.log(chalk.gray(' Frontend:'), chalk.white(projectConfig.apps.frontend.framework));
|
|
586
|
-
console.log(chalk.gray(' Styling:'), chalk.white(projectConfig.apps.frontend.styling));
|
|
587
|
-
console.log(chalk.gray(' ESLint:'), chalk.white(projectConfig.apps.frontend.eslint ? 'yes' : 'no'));
|
|
588
|
-
console.log(chalk.gray(' Prettier:'), chalk.white(projectConfig.apps.frontend.prettier ? 'yes' : 'no'));
|
|
589
|
-
if (projectConfig.apps.frontend.turbopack) {
|
|
590
|
-
console.log(chalk.gray(' Turbopack:'), chalk.white('yes'));
|
|
591
|
-
}
|
|
592
|
-
console.log(chalk.gray(' Backend:'), chalk.white(projectConfig.apps.backend.framework));
|
|
593
|
-
console.log(chalk.gray(' Database:'), chalk.white(projectConfig.apps.backend.database));
|
|
594
|
-
if (projectConfig.apps.backend.orm) {
|
|
595
|
-
console.log(chalk.gray(' ORM:'), chalk.white(projectConfig.apps.backend.orm));
|
|
596
|
-
}
|
|
597
|
-
console.log(chalk.gray(' API style:'), chalk.white(projectConfig.apps.backend.apiStyle));
|
|
598
|
-
console.log(chalk.gray(' Auth:'), chalk.white(projectConfig.apps.backend.auth));
|
|
599
|
-
console.log(chalk.gray(' Docker:'), chalk.white(projectConfig.apps.backend.docker ? 'yes' : 'no'));
|
|
600
|
-
console.log(chalk.gray(' CI:'), chalk.white(projectConfig.ci ? 'yes' : 'no'));
|
|
601
|
-
console.log();
|
|
602
|
-
}
|
|
603
|
-
// Interactive mode
|
|
604
|
-
else {
|
|
605
|
-
projectConfig = await promptForConfiguration(name);
|
|
606
|
-
}
|
|
607
|
-
// Validate project directory
|
|
608
|
-
await validateProjectDirectory(projectConfig.name);
|
|
609
|
-
// Check if a registry template exists (skipped for --template-url which supplies its own)
|
|
610
|
-
if (!skipAvailabilityCheck) {
|
|
611
|
-
const availability = checkTemplateAvailability(projectConfig);
|
|
612
|
-
if (!availability.available) {
|
|
613
|
-
console.log(chalk.yellow('\n⚠️ No exact template match found for your configuration.'));
|
|
614
|
-
console.log(chalk.cyan('\n📋 Available similar templates:'));
|
|
615
|
-
availability.suggestions?.forEach((s, i) => {
|
|
616
|
-
console.log(chalk.cyan(` ${i + 1}. ${s}`));
|
|
617
|
-
});
|
|
618
|
-
console.log(chalk.yellow('\n💡 Tip: You can contribute this template combination to our repository!'));
|
|
619
|
-
console.log(chalk.blue(' Visit: https://github.com/create-fs-app-templates\n'));
|
|
620
|
-
process.exit(0);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
const spinner = ora({
|
|
624
|
-
text: 'Creating your full-stack app...',
|
|
625
|
-
spinner: 'dots',
|
|
626
|
-
color: 'cyan',
|
|
627
|
-
hideCursor: true
|
|
628
|
-
}).start();
|
|
629
|
-
try {
|
|
630
|
-
await scaffoldProject(projectConfig, {
|
|
631
|
-
skipGit: options.git === false,
|
|
632
|
-
skipInstall: options.install !== true,
|
|
633
|
-
skipCache: options.cache === false,
|
|
634
|
-
localTemplatesDir: options.localTemplates,
|
|
635
|
-
customTemplate: customTemplate ?? undefined,
|
|
636
|
-
});
|
|
637
|
-
spinner.succeed(chalk.green.bold('Project created successfully!'));
|
|
638
|
-
}
|
|
639
|
-
catch (error) {
|
|
640
|
-
spinner.fail(chalk.red.bold('Project creation failed!'));
|
|
641
|
-
throw error;
|
|
642
|
-
}
|
|
643
|
-
finally {
|
|
644
|
-
// Ensure cursor is visible
|
|
645
|
-
process.stdout.write('\x1B[?25h');
|
|
646
|
-
}
|
|
647
|
-
console.log();
|
|
648
|
-
// Success box
|
|
649
|
-
const successMsg = boxen(chalk.white.bold(`🎉 ${projectConfig.name} is ready!\n\n`) +
|
|
650
|
-
chalk.cyan.bold('Next Steps:\n\n') +
|
|
651
|
-
chalk.white(`${chalk.green('1.')} ${chalk.cyan(`cd ${projectConfig.name}`)}\n`) +
|
|
652
|
-
chalk.white(`${chalk.green('2.')} ${chalk.cyan(options.install === true ? `${projectConfig.packageManager} run dev` : `${projectConfig.packageManager} install`)}\n`) +
|
|
653
|
-
chalk.white(`${chalk.green('3.')} ${chalk.cyan('Start building! 🚀')}\n\n`) +
|
|
654
|
-
chalk.gray('Documentation:\n') +
|
|
655
|
-
chalk.gray('• README.md - Project overview\n') +
|
|
656
|
-
chalk.gray('• .env.example - Environment setup'), {
|
|
657
|
-
padding: 1,
|
|
658
|
-
margin: 1,
|
|
659
|
-
borderStyle: 'round',
|
|
660
|
-
borderColor: 'green',
|
|
661
|
-
title: chalk.bold.green('✨ Success'),
|
|
662
|
-
titleAlignment: 'center'
|
|
663
|
-
});
|
|
664
|
-
console.log(successMsg);
|
|
665
|
-
console.log();
|
|
666
|
-
}
|
|
667
|
-
catch (error) {
|
|
668
|
-
if (error instanceof TemplateNotFoundError) {
|
|
669
|
-
console.log(error.message);
|
|
670
|
-
if (error.suggestions.length > 0) {
|
|
671
|
-
console.log(chalk.cyan('\n📋 Similar templates you might like:'));
|
|
672
|
-
error.suggestions.forEach((s, i) => {
|
|
673
|
-
console.log(chalk.cyan(` ${i + 1}. ${s}`));
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
console.error(chalk.red('\n❌ Error: ') + chalk.red(error instanceof Error ? error.message : String(error)));
|
|
679
|
-
}
|
|
680
|
-
process.exit(1);
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
// List templates command
|
|
684
|
-
program
|
|
685
|
-
.command('list [search]')
|
|
686
|
-
.description('List templates. Default: official only. Use --contributed or --all to see community templates.')
|
|
687
|
-
.alias('ls')
|
|
688
|
-
.option('--contributed', 'Show only contributed (community) templates')
|
|
689
|
-
.option('--all', 'Show official and contributed templates')
|
|
690
|
-
.action(async (search, cmdOpts) => {
|
|
691
|
-
// Await registry hydration (max 3 s) before displaying
|
|
692
|
-
await Promise.race([registryReady, new Promise(r => setTimeout(r, 3000))]);
|
|
693
|
-
displayAvailableTemplates({
|
|
694
|
-
search: search?.trim() || undefined,
|
|
695
|
-
contributed: cmdOpts.contributed,
|
|
696
|
-
all: cmdOpts.all,
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
// Template info command
|
|
700
|
-
program
|
|
701
|
-
.command('info <template>')
|
|
702
|
-
.description('Show detailed information about a specific template')
|
|
703
|
-
.action(async (templateName) => {
|
|
704
|
-
await Promise.race([registryReady, new Promise(r => setTimeout(r, 3000))]);
|
|
705
|
-
// Search official first, then contributed
|
|
706
|
-
const officialRes = getOfficialByName(templateName);
|
|
707
|
-
const contributedRes = getContributedByName(templateName);
|
|
708
|
-
// Collect all ambiguous across both registries
|
|
709
|
-
const allAmbiguous = [
|
|
710
|
-
...(officialRes.ambiguous ?? []),
|
|
711
|
-
...(contributedRes.ambiguous ?? []),
|
|
712
|
-
];
|
|
713
|
-
if (!officialRes.match && !contributedRes.match) {
|
|
714
|
-
if (allAmbiguous.length > 0) {
|
|
715
|
-
const lines = allAmbiguous.map(t => ` ${chalk.cyan(t.key)} ${t.metadata.contributor ? chalk.dim('community') : chalk.green('✦ official')}`).join('\n');
|
|
716
|
-
console.log(boxen(chalk.yellow.bold('⚠️ Ambiguous — multiple templates match\n\n') + lines + '\n\n' +
|
|
717
|
-
chalk.gray('Use the full key: ') + chalk.cyan('create-fs-app info <full-key>'), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'yellow' }));
|
|
718
|
-
}
|
|
719
|
-
else {
|
|
720
|
-
console.log(boxen(chalk.red.bold('❌ Template Not Found\n\n') +
|
|
721
|
-
chalk.white(`"${templateName}" doesn't match any template.\n\n`) +
|
|
722
|
-
chalk.gray('Run ') + chalk.cyan('create-fs-app list --all') + chalk.gray(' to browse everything.'), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'red' }));
|
|
723
|
-
}
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
const isOfficial = !!officialRes.match;
|
|
727
|
-
const { key, metadata } = (officialRes.match ?? contributedRes.match);
|
|
728
|
-
const borderColor = isOfficial ? 'cyan' : 'yellow';
|
|
729
|
-
const badge = isOfficial
|
|
730
|
-
? chalk.green('✦ official')
|
|
731
|
-
: (() => {
|
|
732
|
-
const c = metadata.contributor;
|
|
733
|
-
return chalk.yellow('◆ contributed') +
|
|
734
|
-
(c ? chalk.dim(` by @${c.github} ${c.url}`) : '');
|
|
735
|
-
})();
|
|
736
|
-
let body = chalk.bold.white(`📦 ${key}\n`) + badge + '\n\n';
|
|
737
|
-
if (!isOfficial && metadata.contributor) {
|
|
738
|
-
body += chalk.gray('Contributor repo: ') + chalk.dim(metadata.contributor.repoUrl) + '\n\n';
|
|
739
|
-
}
|
|
740
|
-
body +=
|
|
741
|
-
chalk.gray('Description:\n') + chalk.white(`${metadata.description}\n\n`) +
|
|
742
|
-
chalk.gray('Features:\n') +
|
|
743
|
-
metadata.features.map((f) => chalk.green(`✓ ${f}`)).join('\n') + '\n\n' +
|
|
744
|
-
chalk.gray('Supports: ') +
|
|
745
|
-
Object.entries(metadata.supports ?? {}).filter(([, v]) => v).map(([k]) => chalk.yellow(k)).join(', ') +
|
|
746
|
-
'\n\n' +
|
|
747
|
-
chalk.gray('Repository: ') + chalk.cyan.underline(metadata.url ?? '');
|
|
748
|
-
console.log();
|
|
749
|
-
console.log(boxen(body, {
|
|
750
|
-
padding: 1, margin: 1, borderStyle: 'round', borderColor,
|
|
751
|
-
title: chalk.bold('Template Info'), titleAlignment: 'center',
|
|
752
|
-
}));
|
|
753
|
-
const usageCmd = isOfficial
|
|
754
|
-
? `npx create-fs-app my-app # wizard auto-selects for this stack`
|
|
755
|
-
: `npx create-fs-app my-app --template ${key}`;
|
|
756
|
-
console.log(boxen(chalk.cyan(usageCmd), {
|
|
757
|
-
padding: 1,
|
|
758
|
-
margin: { top: 0, bottom: 1, left: 1, right: 1 },
|
|
759
|
-
borderStyle: 'round', borderColor: 'blue',
|
|
760
|
-
title: chalk.bold.blue('💡 Usage'), titleAlignment: 'left',
|
|
761
|
-
}));
|
|
762
|
-
});
|
|
763
|
-
// Health check command
|
|
764
|
-
program
|
|
765
|
-
.command('health')
|
|
766
|
-
.description('Run health check on current project')
|
|
767
|
-
.action(async () => {
|
|
768
|
-
try {
|
|
769
|
-
const result = await runHealthCheck();
|
|
770
|
-
displayHealthCheckResults(result);
|
|
771
|
-
process.exit(result.passed ? 0 : 1);
|
|
772
|
-
}
|
|
773
|
-
catch (error) {
|
|
774
|
-
Logger.error('Failed to run health check');
|
|
775
|
-
if (error instanceof Error)
|
|
776
|
-
console.error(chalk.red(error.message));
|
|
777
|
-
process.exit(1);
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
// Preset commands
|
|
781
|
-
const presetCmd = program
|
|
782
|
-
.command('preset')
|
|
783
|
-
.description('Manage configuration presets');
|
|
784
|
-
presetCmd
|
|
785
|
-
.command('save <name>')
|
|
786
|
-
.description('Save a stack configuration as a reusable preset.\n' +
|
|
787
|
-
' Pass the same stack flags as the main command (--frontend, --backend,\n' +
|
|
788
|
-
' --database, --orm, --package-manager, etc.).\n' +
|
|
789
|
-
' Unspecified flags default to the saas-starter stack.')
|
|
790
|
-
.option('-d, --description <desc>', 'Preset description')
|
|
791
|
-
.option('-f, --force', 'Overwrite an existing preset without prompting')
|
|
792
|
-
.action(async (presetName, cmdOptions) => {
|
|
793
|
-
try {
|
|
794
|
-
// ── Guard: block built-in names ─────────────────────────────────────
|
|
795
|
-
if (isBuiltinPresetName(presetName)) {
|
|
796
|
-
Logger.error(`"${presetName}" is a built-in preset and cannot be overwritten.`);
|
|
797
|
-
console.log(chalk.cyan('Built-in presets: ' + Object.keys(BUILTIN_PRESETS).join(', ') + '\n'));
|
|
798
|
-
process.exit(1);
|
|
799
|
-
}
|
|
800
|
-
// ── Guard: warn on duplicate user preset ────────────────────────────
|
|
801
|
-
const exists = await userPresetExists(presetName);
|
|
802
|
-
if (exists && !cmdOptions.force) {
|
|
803
|
-
Logger.error(`Preset "${presetName}" already exists.`);
|
|
804
|
-
console.log(chalk.cyan(` Use --force to overwrite: create-fs-app preset save ${presetName} --force\n`));
|
|
805
|
-
process.exit(1);
|
|
806
|
-
}
|
|
807
|
-
// Stack flags are defined on the root program and consumed there —
|
|
808
|
-
// read them back via program.opts().
|
|
809
|
-
const rootOpts = program.opts();
|
|
810
|
-
// Merge with saas-starter defaults for anything not specified
|
|
811
|
-
const withDefaults = {
|
|
812
|
-
monorepo: rootOpts.monorepo ?? 'turborepo',
|
|
813
|
-
frontend: rootOpts.frontend ?? 'next.js',
|
|
814
|
-
backend: rootOpts.backend ?? 'nest.js',
|
|
815
|
-
database: rootOpts.database ?? 'postgresql',
|
|
816
|
-
orm: rootOpts.orm ?? 'prisma',
|
|
817
|
-
packageManager: rootOpts.packageManager,
|
|
818
|
-
styling: rootOpts.styling,
|
|
819
|
-
apiStyle: rootOpts.apiStyle,
|
|
820
|
-
auth: rootOpts.auth,
|
|
821
|
-
docker: rootOpts.docker,
|
|
822
|
-
ci: rootOpts.ci,
|
|
823
|
-
};
|
|
824
|
-
// Build and validate the config (dummy project name — stripped by savePreset)
|
|
825
|
-
const config = buildConfigFromOptions('preset-placeholder', withDefaults);
|
|
826
|
-
await savePreset(presetName, config, cmdOptions.description);
|
|
827
|
-
const verb = exists ? chalk.yellow('updated') : chalk.green('saved');
|
|
828
|
-
console.log(`\n✓ Preset "${presetName}" ${verb}\n`);
|
|
829
|
-
console.log(chalk.gray(' Monorepo:'), chalk.white(config.monorepo));
|
|
830
|
-
console.log(chalk.gray(' Pkg manager:'), chalk.white(config.packageManager));
|
|
831
|
-
console.log(chalk.gray(' Frontend:'), chalk.white(config.apps.frontend.framework));
|
|
832
|
-
console.log(chalk.gray(' Backend:'), chalk.white(config.apps.backend.framework));
|
|
833
|
-
console.log(chalk.gray(' Database:'), chalk.white(config.apps.backend.database));
|
|
834
|
-
console.log(chalk.gray(' ORM:'), chalk.white(config.apps.backend.orm ?? 'none'));
|
|
835
|
-
console.log(chalk.gray(' Docker:'), chalk.white(config.apps.backend.docker ? 'yes' : 'no'));
|
|
836
|
-
console.log();
|
|
837
|
-
console.log(chalk.cyan(`💡 Use it: create-fs-app my-app --preset ${presetName}\n`));
|
|
838
|
-
}
|
|
839
|
-
catch (error) {
|
|
840
|
-
Logger.error('Failed to save preset');
|
|
841
|
-
if (error instanceof Error)
|
|
842
|
-
console.error(chalk.red(error.message));
|
|
843
|
-
process.exit(1);
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
presetCmd
|
|
847
|
-
.command('list')
|
|
848
|
-
.description('List all saved presets')
|
|
849
|
-
.action(async () => {
|
|
850
|
-
try {
|
|
851
|
-
const presets = await listPresets();
|
|
852
|
-
const builtinKeys = Object.keys(BUILTIN_PRESETS);
|
|
853
|
-
console.log(chalk.cyan.bold('\n📚 Available Presets\n'));
|
|
854
|
-
// Built-in presets
|
|
855
|
-
console.log(chalk.bold.green('Built-in Presets:') + chalk.dim(' (read-only — cannot be saved over or deleted)'));
|
|
856
|
-
builtinKeys.forEach(key => {
|
|
857
|
-
const preset = BUILTIN_PRESETS[key];
|
|
858
|
-
const cfg = preset.config;
|
|
859
|
-
console.log(chalk.white(` ${key}`));
|
|
860
|
-
console.log(chalk.gray(` ${preset.description}`));
|
|
861
|
-
console.log(chalk.dim(` Stack: ${cfg.apps.frontend.framework} + ${cfg.apps.backend.framework} + ${cfg.apps.backend.database}`));
|
|
862
|
-
});
|
|
863
|
-
// User presets — exclude any builtin names that may have leaked into the file
|
|
864
|
-
const userPresets = presets.filter(p => !isBuiltinPresetName(p.name));
|
|
865
|
-
if (userPresets.length > 0) {
|
|
866
|
-
console.log(chalk.bold.green('\nYour Presets:'));
|
|
867
|
-
userPresets.forEach(preset => {
|
|
868
|
-
console.log(chalk.white(` ${preset.name}`));
|
|
869
|
-
if (preset.description) {
|
|
870
|
-
console.log(chalk.gray(` ${preset.description}`));
|
|
871
|
-
}
|
|
872
|
-
console.log(chalk.dim(` Created: ${new Date(preset.createdAt).toLocaleString()}`));
|
|
873
|
-
if (preset.lastUsed) {
|
|
874
|
-
console.log(chalk.dim(` Last used: ${new Date(preset.lastUsed).toLocaleString()}`));
|
|
875
|
-
}
|
|
876
|
-
const cfg = preset.config;
|
|
877
|
-
console.log(chalk.dim(` Stack: ${cfg.apps.frontend.framework} + ${cfg.apps.backend.framework} + ${cfg.apps.backend.database}`));
|
|
878
|
-
});
|
|
879
|
-
}
|
|
880
|
-
console.log(chalk.cyan('\n💡 Use: create-fs-app my-app --preset <name>\n'));
|
|
881
|
-
}
|
|
882
|
-
catch (error) {
|
|
883
|
-
Logger.error('Failed to list presets');
|
|
884
|
-
if (error instanceof Error)
|
|
885
|
-
console.error(chalk.red(error.message));
|
|
886
|
-
process.exit(1);
|
|
887
|
-
}
|
|
888
|
-
});
|
|
889
|
-
presetCmd
|
|
890
|
-
.command('delete <name>')
|
|
891
|
-
.description('Delete a saved preset')
|
|
892
|
-
.action(async (name) => {
|
|
893
|
-
try {
|
|
894
|
-
const deleted = await deletePreset(name);
|
|
895
|
-
if (!deleted) {
|
|
896
|
-
// Not in user file — check if it's a builtin to give a better message
|
|
897
|
-
if (isBuiltinPresetName(name)) {
|
|
898
|
-
Logger.error(`"${name}" is a built-in preset and cannot be deleted.`);
|
|
899
|
-
console.log(chalk.cyan('Built-in presets: ' + Object.keys(BUILTIN_PRESETS).join(', ') + '\n'));
|
|
900
|
-
}
|
|
901
|
-
else {
|
|
902
|
-
Logger.error(`Preset "${name}" not found.`);
|
|
903
|
-
console.log(chalk.cyan('\nRun create-fs-app preset list to see available presets.\n'));
|
|
904
|
-
}
|
|
905
|
-
process.exit(1);
|
|
906
|
-
}
|
|
907
|
-
// deletePreset already logs success
|
|
908
|
-
}
|
|
909
|
-
catch (error) {
|
|
910
|
-
Logger.error('Failed to delete preset');
|
|
911
|
-
if (error instanceof Error)
|
|
912
|
-
console.error(chalk.red(error.message));
|
|
913
|
-
process.exit(1);
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
// Cache commands
|
|
917
|
-
const cacheCmd = program
|
|
918
|
-
.command('cache')
|
|
919
|
-
.description('Manage template cache');
|
|
920
|
-
cacheCmd
|
|
921
|
-
.command('clear')
|
|
922
|
-
.description('Clear template cache and registry cache')
|
|
923
|
-
.action(async () => {
|
|
924
|
-
try {
|
|
925
|
-
await clearCache();
|
|
926
|
-
await clearRegistryCache();
|
|
927
|
-
console.log(chalk.green('✓ Template cache and registry cache cleared'));
|
|
928
|
-
}
|
|
929
|
-
catch (error) {
|
|
930
|
-
Logger.error('Failed to clear cache');
|
|
931
|
-
if (error instanceof Error)
|
|
932
|
-
console.error(chalk.red(error.message));
|
|
933
|
-
process.exit(1);
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
cacheCmd
|
|
937
|
-
.command('stats')
|
|
938
|
-
.description('Show cache statistics')
|
|
939
|
-
.action(async () => {
|
|
940
|
-
try {
|
|
941
|
-
const stats = await getCacheStats();
|
|
942
|
-
console.log(chalk.cyan.bold('\n📊 Cache Statistics\n'));
|
|
943
|
-
console.log(chalk.white(`Total templates: ${stats.totalTemplates}`));
|
|
944
|
-
console.log(chalk.white(`Cache size: ${stats.cacheSize}`));
|
|
945
|
-
if (stats.templates.length > 0) {
|
|
946
|
-
console.log(chalk.bold('\nCached Templates:'));
|
|
947
|
-
stats.templates.forEach(t => {
|
|
948
|
-
console.log(chalk.gray(` ${t.key}`));
|
|
949
|
-
console.log(chalk.gray(` Last used: ${new Date(t.lastUsed).toLocaleDateString()}`));
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
console.log();
|
|
953
|
-
}
|
|
954
|
-
catch (error) {
|
|
955
|
-
Logger.error('Failed to get cache stats');
|
|
956
|
-
if (error instanceof Error)
|
|
957
|
-
console.error(chalk.red(error.message));
|
|
958
|
-
process.exit(1);
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
program.parse();
|
|
962
|
-
}
|
|
963
|
-
main().catch(console.error);
|
|
964
|
-
//# sourceMappingURL=index.js.map
|
|
2
|
+
// Keep this file free of imports: it must run on old Node versions to print the error.
|
|
3
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
4
|
+
if (major < 20 || (major === 20 && minor < 19)) {
|
|
5
|
+
console.error([
|
|
6
|
+
'✗ create-fs-app needs Node.js 20.19 or newer',
|
|
7
|
+
` You have ${process.versions.node}.`,
|
|
8
|
+
' Try: install Node.js 22 LTS from https://nodejs.org',
|
|
9
|
+
].join('\n'));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
const { main } = await import('./cli/program.js');
|
|
13
|
+
await main();
|
|
14
|
+
export {};
|