create-fs-app 2.0.0 → 2.0.1
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/README.md +233 -417
- package/dist/core/health-check.d.ts +3 -9
- package/dist/core/health-check.js +59 -174
- package/dist/core/health-check.js.map +1 -1
- package/dist/core/presets.d.ts +4 -0
- package/dist/core/presets.js +33 -7
- package/dist/core/presets.js.map +1 -1
- package/dist/core/registry-fetch.d.ts +20 -0
- package/dist/core/registry-fetch.js +121 -0
- package/dist/core/registry-fetch.js.map +1 -0
- package/dist/core/scaffold.d.ts +8 -0
- package/dist/core/scaffold.js +10 -12
- package/dist/core/scaffold.js.map +1 -1
- package/dist/core/template-cache.js +20 -6
- package/dist/core/template-cache.js.map +1 -1
- package/dist/core/template-clone.d.ts +1 -1
- package/dist/core/template-clone.js +520 -47
- package/dist/core/template-clone.js.map +1 -1
- package/dist/core/template-list.d.ts +33 -22
- package/dist/core/template-list.js +154 -95
- package/dist/core/template-list.js.map +1 -1
- package/dist/core/template-registry.d.ts +52 -31
- package/dist/core/template-registry.js +192 -70
- package/dist/core/template-registry.js.map +1 -1
- package/dist/index.js +539 -217
- package/dist/index.js.bak +872 -0
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +23 -27
- package/dist/types/index.js +24 -8
- package/dist/types/index.js.map +1 -1
- package/dist/utils/validation.d.ts +23 -0
- package/dist/utils/validation.js +47 -10
- package/dist/utils/validation.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,16 +10,18 @@ import updateNotifier from 'update-notifier';
|
|
|
10
10
|
import { readFileSync } from 'fs';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
12
|
import { dirname, join } from 'path';
|
|
13
|
-
import { ProjectConfigSchema, MonorepoFramework, FrontendFramework, BackendFramework, Database, PackageManager } from './types/index.js';
|
|
13
|
+
import { ProjectConfigSchema, MonorepoFramework, FrontendFramework, BackendFramework, Database, PackageManager, ApiStyle, AuthStrategy, } from './types/index.js';
|
|
14
14
|
import { scaffoldProject, validateProjectDirectory, checkTemplateAvailability, TemplateNotFoundError } from './core/scaffold.js';
|
|
15
|
-
import { displayAvailableTemplates,
|
|
16
|
-
import { assertValidProjectName } from './utils/validation.js';
|
|
15
|
+
import { displayAvailableTemplates, getContributedByName, getContributedByUUID, getOfficialByName, } from './core/template-list.js';
|
|
16
|
+
import { assertValidProjectName, isValidUUID } from './utils/validation.js';
|
|
17
17
|
import { Logger } from './utils/logger.js';
|
|
18
|
-
import { loadPreset, listPresets, deletePreset, getBuiltinPreset, BUILTIN_PRESETS } from './core/presets.js';
|
|
18
|
+
import { savePreset, loadPreset, listPresets, deletePreset, getBuiltinPreset, isBuiltinPresetName, userPresetExists, BUILTIN_PRESETS, } from './core/presets.js';
|
|
19
19
|
import { runHealthCheck, displayHealthCheckResults } from './core/health-check.js';
|
|
20
20
|
import { clearCache, getCacheStats } from './core/template-cache.js';
|
|
21
21
|
import { createCustomTemplate } from './core/template-registry.js';
|
|
22
|
-
import {
|
|
22
|
+
import { getRemoteRegistry, clearRegistryCache } from './core/registry-fetch.js';
|
|
23
|
+
import { setActiveRegistry } from './core/template-registry.js';
|
|
24
|
+
import { parseTemplateUrl } from './utils/validation.js';
|
|
23
25
|
const __filename = fileURLToPath(import.meta.url);
|
|
24
26
|
const __dirname = dirname(__filename);
|
|
25
27
|
// Check for updates
|
|
@@ -57,6 +59,19 @@ async function welcome() {
|
|
|
57
59
|
/**
|
|
58
60
|
* Build configuration from CLI options
|
|
59
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
|
+
}
|
|
60
75
|
function buildConfigFromOptions(name, options) {
|
|
61
76
|
// Validate required fields
|
|
62
77
|
if (!name) {
|
|
@@ -75,35 +90,34 @@ function buildConfigFromOptions(name, options) {
|
|
|
75
90
|
console.log(chalk.cyan('💡 Or run without options for interactive mode.\n'));
|
|
76
91
|
process.exit(1);
|
|
77
92
|
}
|
|
78
|
-
|
|
79
|
-
const validateEnum = (value, enumObj, name) => {
|
|
80
|
-
const validValues = Object.values(enumObj);
|
|
81
|
-
const found = validValues.find((v) => v.toLowerCase() === value.toLowerCase());
|
|
82
|
-
if (!found) {
|
|
83
|
-
console.log(chalk.red(`\n❌ Invalid ${name}: "${value}"\n`));
|
|
84
|
-
console.log(chalk.cyan(`Valid options: ${validValues.join(', ')}\n`));
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
return found;
|
|
88
|
-
};
|
|
93
|
+
const frontendFramework = validateEnum(options.frontend, FrontendFramework, 'frontend framework');
|
|
89
94
|
const config = {
|
|
90
95
|
name,
|
|
91
96
|
monorepo: validateEnum(options.monorepo, MonorepoFramework, 'monorepo framework'),
|
|
92
97
|
packageManager: options.packageManager
|
|
93
98
|
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
94
99
|
: PackageManager.NPM,
|
|
100
|
+
ci: options.ci === true,
|
|
95
101
|
apps: {
|
|
96
102
|
frontend: {
|
|
97
|
-
framework:
|
|
98
|
-
// TypeScript is always enabled
|
|
103
|
+
framework: frontendFramework,
|
|
99
104
|
styling: options.styling || 'tailwind',
|
|
100
|
-
|
|
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,
|
|
101
109
|
},
|
|
102
110
|
backend: {
|
|
103
111
|
framework: validateEnum(options.backend, BackendFramework, 'backend framework'),
|
|
104
112
|
database: validateEnum(options.database, Database, 'database'),
|
|
105
113
|
orm: options.orm,
|
|
106
|
-
|
|
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
|
|
107
121
|
}
|
|
108
122
|
}
|
|
109
123
|
};
|
|
@@ -112,137 +126,259 @@ function buildConfigFromOptions(name, options) {
|
|
|
112
126
|
return ProjectConfigSchema.parse(config);
|
|
113
127
|
}
|
|
114
128
|
catch (error) {
|
|
115
|
-
Logger.error('Invalid configuration:');
|
|
116
|
-
console.error(error);
|
|
129
|
+
Logger.error('Invalid configuration: ' + (error instanceof Error ? error.message : String(error)));
|
|
117
130
|
process.exit(1);
|
|
118
131
|
}
|
|
119
132
|
}
|
|
120
133
|
async function promptForConfiguration(projectName) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
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({
|
|
124
142
|
type: 'text',
|
|
125
|
-
name: '
|
|
126
|
-
message: '
|
|
127
|
-
initial: 'my-fs-app'
|
|
128
|
-
|
|
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;
|
|
129
149
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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({
|
|
146
269
|
type: 'select',
|
|
147
|
-
name: '
|
|
148
|
-
message: '
|
|
270
|
+
name: 'apiStyle',
|
|
271
|
+
message: 'API style:',
|
|
149
272
|
choices: [
|
|
150
|
-
{ title: '
|
|
151
|
-
{ title: '
|
|
152
|
-
{ title: '
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}, {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
message: 'Enable ESLint and Prettier?',
|
|
159
|
-
initial: true
|
|
160
|
-
}, {
|
|
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({
|
|
161
281
|
type: 'select',
|
|
162
|
-
name: '
|
|
163
|
-
message: '
|
|
164
|
-
choices: Object.values(BackendFramework).map(v => ({ title: v, value: v }))
|
|
165
|
-
}, {
|
|
166
|
-
type: 'select',
|
|
167
|
-
name: 'database',
|
|
168
|
-
message: 'Select a database:',
|
|
169
|
-
choices: Object.values(Database).map(v => ({ title: v, value: v }))
|
|
170
|
-
}, {
|
|
171
|
-
type: 'select',
|
|
172
|
-
name: 'orm',
|
|
173
|
-
message: 'Select an ORM:',
|
|
282
|
+
name: 'auth',
|
|
283
|
+
message: 'Authentication scaffolding:',
|
|
174
284
|
choices: [
|
|
175
|
-
{ title: '
|
|
176
|
-
{ title: '
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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 ─────────────────────────────────────────────
|
|
193
306
|
const config = {
|
|
194
|
-
name:
|
|
195
|
-
monorepo
|
|
196
|
-
packageManager
|
|
307
|
+
name: name,
|
|
308
|
+
monorepo,
|
|
309
|
+
packageManager,
|
|
310
|
+
ci,
|
|
197
311
|
apps: {
|
|
198
312
|
frontend: {
|
|
199
|
-
framework:
|
|
200
|
-
styling
|
|
201
|
-
|
|
313
|
+
framework: frontendFramework,
|
|
314
|
+
styling,
|
|
315
|
+
eslint,
|
|
316
|
+
prettier,
|
|
317
|
+
turbopack,
|
|
202
318
|
},
|
|
203
319
|
backend: {
|
|
204
|
-
framework:
|
|
205
|
-
database
|
|
206
|
-
orm
|
|
207
|
-
|
|
320
|
+
framework: backendFramework,
|
|
321
|
+
database,
|
|
322
|
+
orm,
|
|
323
|
+
apiStyle,
|
|
324
|
+
auth,
|
|
325
|
+
docker,
|
|
208
326
|
}
|
|
209
327
|
}
|
|
210
328
|
};
|
|
211
|
-
// Validate configuration using Zod
|
|
212
329
|
return ProjectConfigSchema.parse(config);
|
|
213
330
|
}
|
|
214
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(() => { });
|
|
215
341
|
const program = new Command();
|
|
216
342
|
program
|
|
217
343
|
.name('create-fs-app')
|
|
218
344
|
.description('Create a full-stack monorepo application')
|
|
219
|
-
.version(
|
|
345
|
+
.version(pkg.version);
|
|
220
346
|
// Main create command
|
|
221
347
|
program
|
|
222
348
|
.argument('[name]', 'The name of your application')
|
|
223
349
|
.option('-t, --template <name>', 'Use a predefined template')
|
|
224
350
|
.option('--template-url <url>', 'Use a custom template from GitHub URL')
|
|
225
351
|
.option('--preset <name>', 'Use a configuration preset')
|
|
226
|
-
.option('--monorepo <framework>', 'Monorepo framework (turborepo, nx
|
|
352
|
+
.option('--monorepo <framework>', 'Monorepo framework (turborepo, nx)')
|
|
227
353
|
.option('--frontend <framework>', 'Frontend framework (react, next.js, vue, nuxt, angular)')
|
|
228
|
-
.option('--backend <framework>', 'Backend framework (express, nest.js, fastify, koa)')
|
|
354
|
+
.option('--backend <framework>', 'Backend framework (express, nest.js, fastify-ts, koa)')
|
|
229
355
|
.option('--database <db>', 'Database (postgresql, mongodb, mysql, sqlite)')
|
|
230
356
|
.option('--orm <orm>', 'ORM (prisma, typeorm, mongoose, drizzle)')
|
|
231
357
|
.option('--package-manager <pm>', 'Package manager (npm, yarn, pnpm)')
|
|
232
358
|
.option('--styling <style>', 'Styling solution (css, scss, tailwind, styled-components)')
|
|
233
|
-
.option('--
|
|
234
|
-
.option('--no-
|
|
235
|
-
.option('--
|
|
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)')
|
|
236
367
|
.option('--no-docker', 'Skip Docker configuration')
|
|
368
|
+
.option('--ci', 'Add GitHub Actions CI workflow')
|
|
369
|
+
.option('--no-ci', 'Skip GitHub Actions CI')
|
|
237
370
|
.option('--no-git', 'Skip git initialization')
|
|
238
371
|
.option('--no-install', 'Skip package installation')
|
|
239
372
|
.option('--no-cache', 'Skip template caching')
|
|
373
|
+
.option('--local-templates <path>', 'Use local templates repo instead of GitHub (for development)')
|
|
240
374
|
.option('-y, --yes', 'Skip prompts and use defaults')
|
|
241
375
|
.action(async (name, options) => {
|
|
242
376
|
await welcome();
|
|
243
377
|
try {
|
|
244
378
|
let projectConfig;
|
|
245
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;
|
|
246
382
|
// Check if using preset
|
|
247
383
|
if (options.preset) {
|
|
248
384
|
if (!name) {
|
|
@@ -283,34 +419,47 @@ async function main() {
|
|
|
283
419
|
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template-url <url>\n'));
|
|
284
420
|
process.exit(1);
|
|
285
421
|
}
|
|
286
|
-
//
|
|
287
|
-
const
|
|
288
|
-
if (!
|
|
289
|
-
Logger.error(
|
|
422
|
+
// Parse URL — extracts repoUrl, branch, and optional subfolder
|
|
423
|
+
const parsed = parseTemplateUrl(options.templateUrl);
|
|
424
|
+
if (!parsed.valid) {
|
|
425
|
+
Logger.error(parsed.error);
|
|
290
426
|
process.exit(1);
|
|
291
427
|
}
|
|
292
|
-
|
|
293
|
-
|
|
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
|
|
294
432
|
projectConfig = {
|
|
295
433
|
name,
|
|
296
434
|
monorepo: 'turborepo',
|
|
297
|
-
packageManager:
|
|
435
|
+
packageManager: options.packageManager
|
|
436
|
+
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
437
|
+
: PackageManager.NPM,
|
|
438
|
+
ci: options.ci === true,
|
|
298
439
|
apps: {
|
|
299
440
|
frontend: {
|
|
300
441
|
framework: 'react',
|
|
301
442
|
styling: 'tailwind',
|
|
302
|
-
|
|
443
|
+
eslint: true,
|
|
444
|
+
prettier: true,
|
|
445
|
+
turbopack: false,
|
|
303
446
|
},
|
|
304
447
|
backend: {
|
|
305
448
|
framework: 'express',
|
|
306
449
|
database: 'postgresql',
|
|
307
|
-
|
|
450
|
+
apiStyle: 'rest',
|
|
451
|
+
auth: 'none',
|
|
452
|
+
docker: options.docker !== false,
|
|
308
453
|
}
|
|
309
454
|
}
|
|
310
455
|
};
|
|
456
|
+
// Custom template bypasses the registry — skip availability check
|
|
457
|
+
skipAvailabilityCheck = true;
|
|
311
458
|
console.log();
|
|
312
459
|
const infoBox = boxen(chalk.cyan.bold('🔗 Using Custom Template\n\n') +
|
|
313
|
-
chalk.white(
|
|
460
|
+
chalk.white('Repo: ') + chalk.green(repoUrl) + '\n' +
|
|
461
|
+
chalk.white('Branch: ') + chalk.green(branch) +
|
|
462
|
+
(subfolder ? '\n' + chalk.white('Folder: ') + chalk.green(subfolder) : ''), {
|
|
314
463
|
padding: 1,
|
|
315
464
|
margin: 1,
|
|
316
465
|
borderStyle: 'round',
|
|
@@ -318,58 +467,112 @@ async function main() {
|
|
|
318
467
|
});
|
|
319
468
|
console.log(infoBox);
|
|
320
469
|
}
|
|
321
|
-
//
|
|
470
|
+
// --template: contributed templates only (UUID-only mode)
|
|
322
471
|
else if (options.template) {
|
|
323
|
-
|
|
324
|
-
if (!template) {
|
|
325
|
-
|
|
326
|
-
chalk.white(
|
|
327
|
-
chalk.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
borderStyle: 'round',
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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' }));
|
|
334
489
|
process.exit(1);
|
|
335
490
|
}
|
|
336
|
-
// For direct template usage, we still need a project name
|
|
337
491
|
if (!name) {
|
|
338
492
|
console.log(chalk.red('\n❌ Project name is required when using --template.\n'));
|
|
339
|
-
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template <
|
|
493
|
+
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template <uuid>\n'));
|
|
340
494
|
process.exit(1);
|
|
341
495
|
}
|
|
342
|
-
// Extract
|
|
343
|
-
const
|
|
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]);
|
|
344
508
|
projectConfig = {
|
|
345
509
|
name,
|
|
346
510
|
monorepo: parts[0],
|
|
347
|
-
packageManager:
|
|
511
|
+
packageManager: options.packageManager
|
|
512
|
+
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
513
|
+
: PackageManager.NPM,
|
|
514
|
+
ci: options.ci === true,
|
|
348
515
|
apps: {
|
|
349
516
|
frontend: {
|
|
350
|
-
framework:
|
|
351
|
-
// TypeScript is always enabled
|
|
517
|
+
framework: tplFrontend,
|
|
352
518
|
styling: 'tailwind',
|
|
353
|
-
|
|
519
|
+
eslint: true,
|
|
520
|
+
prettier: true,
|
|
521
|
+
turbopack: false,
|
|
354
522
|
},
|
|
355
523
|
backend: {
|
|
356
|
-
framework:
|
|
524
|
+
framework: tplBackend,
|
|
357
525
|
database: parts[3],
|
|
358
526
|
orm: parts[4],
|
|
359
|
-
|
|
527
|
+
apiStyle: 'rest',
|
|
528
|
+
auth: 'none',
|
|
529
|
+
docker: true,
|
|
360
530
|
}
|
|
361
531
|
}
|
|
362
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'));
|
|
363
575
|
console.log();
|
|
364
|
-
const infoBox = boxen(chalk.cyan.bold('🚀 Using Template\n\n') +
|
|
365
|
-
chalk.white(`Template: `) + chalk.green(template.key) + '\n' +
|
|
366
|
-
chalk.white(`Description: `) + chalk.gray(template.metadata.description), {
|
|
367
|
-
padding: 1,
|
|
368
|
-
margin: 1,
|
|
369
|
-
borderStyle: 'round',
|
|
370
|
-
borderColor: 'cyan'
|
|
371
|
-
});
|
|
372
|
-
console.log(infoBox);
|
|
373
576
|
}
|
|
374
577
|
// Check if stack options provided via CLI
|
|
375
578
|
else if (options.monorepo || options.frontend || options.backend) {
|
|
@@ -378,13 +581,23 @@ async function main() {
|
|
|
378
581
|
console.log(chalk.cyan('\n📋 Configuration from CLI options:\n'));
|
|
379
582
|
console.log(chalk.gray(' Project:'), chalk.white(projectConfig.name));
|
|
380
583
|
console.log(chalk.gray(' Monorepo:'), chalk.white(projectConfig.monorepo));
|
|
584
|
+
console.log(chalk.gray(' Pkg manager:'), chalk.white(projectConfig.packageManager));
|
|
381
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
|
+
}
|
|
382
592
|
console.log(chalk.gray(' Backend:'), chalk.white(projectConfig.apps.backend.framework));
|
|
383
593
|
console.log(chalk.gray(' Database:'), chalk.white(projectConfig.apps.backend.database));
|
|
384
594
|
if (projectConfig.apps.backend.orm) {
|
|
385
595
|
console.log(chalk.gray(' ORM:'), chalk.white(projectConfig.apps.backend.orm));
|
|
386
596
|
}
|
|
387
|
-
console.log(chalk.gray('
|
|
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'));
|
|
388
601
|
console.log();
|
|
389
602
|
}
|
|
390
603
|
// Interactive mode
|
|
@@ -393,17 +606,19 @@ async function main() {
|
|
|
393
606
|
}
|
|
394
607
|
// Validate project directory
|
|
395
608
|
await validateProjectDirectory(projectConfig.name);
|
|
396
|
-
// Check if template exists
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
+
}
|
|
407
622
|
}
|
|
408
623
|
const spinner = ora({
|
|
409
624
|
text: 'Creating your full-stack app...',
|
|
@@ -414,7 +629,10 @@ async function main() {
|
|
|
414
629
|
try {
|
|
415
630
|
await scaffoldProject(projectConfig, {
|
|
416
631
|
skipGit: options.git === false,
|
|
417
|
-
skipInstall: options.install === false
|
|
632
|
+
skipInstall: options.install === false,
|
|
633
|
+
skipCache: options.cache === false,
|
|
634
|
+
localTemplatesDir: options.localTemplates,
|
|
635
|
+
customTemplate: customTemplate ?? undefined,
|
|
418
636
|
});
|
|
419
637
|
spinner.succeed(chalk.green.bold('Project created successfully!'));
|
|
420
638
|
}
|
|
@@ -457,64 +675,90 @@ async function main() {
|
|
|
457
675
|
}
|
|
458
676
|
}
|
|
459
677
|
else {
|
|
460
|
-
console.error(chalk.red('\n❌ Error
|
|
461
|
-
console.error(error);
|
|
678
|
+
console.error(chalk.red('\n❌ Error: ') + chalk.red(error instanceof Error ? error.message : String(error)));
|
|
462
679
|
}
|
|
463
680
|
process.exit(1);
|
|
464
681
|
}
|
|
465
682
|
});
|
|
466
683
|
// List templates command
|
|
467
684
|
program
|
|
468
|
-
.command('list')
|
|
469
|
-
.description('List all
|
|
685
|
+
.command('list [search]')
|
|
686
|
+
.description('List templates. Default: official only. Use --contributed or --all to see community templates.')
|
|
470
687
|
.alias('ls')
|
|
471
|
-
.
|
|
472
|
-
|
|
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
|
+
});
|
|
473
698
|
});
|
|
474
699
|
// Template info command
|
|
475
700
|
program
|
|
476
701
|
.command('info <template>')
|
|
477
|
-
.description('Show detailed information about a template')
|
|
478
|
-
.action((templateName) => {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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
|
+
}
|
|
490
724
|
return;
|
|
491
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 ?? '');
|
|
492
748
|
console.log();
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
chalk.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
padding: 1,
|
|
502
|
-
margin: 1,
|
|
503
|
-
borderStyle: 'round',
|
|
504
|
-
borderColor: 'cyan',
|
|
505
|
-
title: chalk.bold.cyan('Template Info'),
|
|
506
|
-
titleAlignment: 'center'
|
|
507
|
-
});
|
|
508
|
-
console.log(infoBox);
|
|
509
|
-
const usageBox = boxen(chalk.cyan(`npx create-fs-app my-app --template ${template.key}`), {
|
|
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), {
|
|
510
757
|
padding: 1,
|
|
511
758
|
margin: { top: 0, bottom: 1, left: 1, right: 1 },
|
|
512
|
-
borderStyle: 'round',
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
titleAlignment: 'left'
|
|
516
|
-
});
|
|
517
|
-
console.log(usageBox);
|
|
759
|
+
borderStyle: 'round', borderColor: 'blue',
|
|
760
|
+
title: chalk.bold.blue('💡 Usage'), titleAlignment: 'left',
|
|
761
|
+
}));
|
|
518
762
|
});
|
|
519
763
|
// Health check command
|
|
520
764
|
program
|
|
@@ -528,7 +772,8 @@ async function main() {
|
|
|
528
772
|
}
|
|
529
773
|
catch (error) {
|
|
530
774
|
Logger.error('Failed to run health check');
|
|
531
|
-
|
|
775
|
+
if (error instanceof Error)
|
|
776
|
+
console.error(chalk.red(error.message));
|
|
532
777
|
process.exit(1);
|
|
533
778
|
}
|
|
534
779
|
});
|
|
@@ -538,12 +783,65 @@ async function main() {
|
|
|
538
783
|
.description('Manage configuration presets');
|
|
539
784
|
presetCmd
|
|
540
785
|
.command('save <name>')
|
|
541
|
-
.description('Save
|
|
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.')
|
|
542
790
|
.option('-d, --description <desc>', 'Preset description')
|
|
543
|
-
.
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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
|
+
}
|
|
547
845
|
});
|
|
548
846
|
presetCmd
|
|
549
847
|
.command('list')
|
|
@@ -554,27 +852,37 @@ async function main() {
|
|
|
554
852
|
const builtinKeys = Object.keys(BUILTIN_PRESETS);
|
|
555
853
|
console.log(chalk.cyan.bold('\n📚 Available Presets\n'));
|
|
556
854
|
// Built-in presets
|
|
557
|
-
console.log(chalk.bold.green('Built-in Presets:'));
|
|
855
|
+
console.log(chalk.bold.green('Built-in Presets:') + chalk.dim(' (read-only — cannot be saved over or deleted)'));
|
|
558
856
|
builtinKeys.forEach(key => {
|
|
559
857
|
const preset = BUILTIN_PRESETS[key];
|
|
858
|
+
const cfg = preset.config;
|
|
560
859
|
console.log(chalk.white(` ${key}`));
|
|
561
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}`));
|
|
562
862
|
});
|
|
563
|
-
// User presets
|
|
564
|
-
|
|
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) {
|
|
565
866
|
console.log(chalk.bold.green('\nYour Presets:'));
|
|
566
|
-
|
|
867
|
+
userPresets.forEach(preset => {
|
|
567
868
|
console.log(chalk.white(` ${preset.name}`));
|
|
568
869
|
if (preset.description) {
|
|
569
870
|
console.log(chalk.gray(` ${preset.description}`));
|
|
570
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}`));
|
|
571
878
|
});
|
|
572
879
|
}
|
|
573
880
|
console.log(chalk.cyan('\n💡 Use: create-fs-app my-app --preset <name>\n'));
|
|
574
881
|
}
|
|
575
882
|
catch (error) {
|
|
576
883
|
Logger.error('Failed to list presets');
|
|
577
|
-
|
|
884
|
+
if (error instanceof Error)
|
|
885
|
+
console.error(chalk.red(error.message));
|
|
578
886
|
process.exit(1);
|
|
579
887
|
}
|
|
580
888
|
});
|
|
@@ -585,13 +893,23 @@ async function main() {
|
|
|
585
893
|
try {
|
|
586
894
|
const deleted = await deletePreset(name);
|
|
587
895
|
if (!deleted) {
|
|
588
|
-
|
|
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
|
+
}
|
|
589
905
|
process.exit(1);
|
|
590
906
|
}
|
|
907
|
+
// deletePreset already logs success
|
|
591
908
|
}
|
|
592
909
|
catch (error) {
|
|
593
910
|
Logger.error('Failed to delete preset');
|
|
594
|
-
|
|
911
|
+
if (error instanceof Error)
|
|
912
|
+
console.error(chalk.red(error.message));
|
|
595
913
|
process.exit(1);
|
|
596
914
|
}
|
|
597
915
|
});
|
|
@@ -601,14 +919,17 @@ async function main() {
|
|
|
601
919
|
.description('Manage template cache');
|
|
602
920
|
cacheCmd
|
|
603
921
|
.command('clear')
|
|
604
|
-
.description('Clear template cache')
|
|
922
|
+
.description('Clear template cache and registry cache')
|
|
605
923
|
.action(async () => {
|
|
606
924
|
try {
|
|
607
925
|
await clearCache();
|
|
926
|
+
await clearRegistryCache();
|
|
927
|
+
console.log(chalk.green('✓ Template cache and registry cache cleared'));
|
|
608
928
|
}
|
|
609
929
|
catch (error) {
|
|
610
930
|
Logger.error('Failed to clear cache');
|
|
611
|
-
|
|
931
|
+
if (error instanceof Error)
|
|
932
|
+
console.error(chalk.red(error.message));
|
|
612
933
|
process.exit(1);
|
|
613
934
|
}
|
|
614
935
|
});
|
|
@@ -632,7 +953,8 @@ async function main() {
|
|
|
632
953
|
}
|
|
633
954
|
catch (error) {
|
|
634
955
|
Logger.error('Failed to get cache stats');
|
|
635
|
-
|
|
956
|
+
if (error instanceof Error)
|
|
957
|
+
console.error(chalk.red(error.message));
|
|
636
958
|
process.exit(1);
|
|
637
959
|
}
|
|
638
960
|
});
|