create-fs-app 1.1.10 → 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 +340 -57
- package/dist/core/health-check.d.ts +15 -0
- package/dist/core/health-check.js +138 -0
- package/dist/core/health-check.js.map +1 -0
- package/dist/core/presets.d.ts +48 -0
- package/dist/core/presets.js +220 -0
- package/dist/core/presets.js.map +1 -0
- 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 +40 -0
- package/dist/core/scaffold.js +104 -0
- package/dist/core/scaffold.js.map +1 -0
- package/dist/core/template-cache.d.ts +38 -0
- package/dist/core/template-cache.js +233 -0
- package/dist/core/template-cache.js.map +1 -0
- package/dist/core/template-clone.d.ts +27 -0
- package/dist/core/template-clone.js +808 -0
- package/dist/core/template-clone.js.map +1 -0
- package/dist/core/template-list.d.ts +45 -0
- package/dist/core/template-list.js +191 -0
- package/dist/core/template-list.js.map +1 -0
- package/dist/core/template-registry.d.ts +78 -0
- package/dist/core/template-registry.js +238 -0
- package/dist/core/template-registry.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +964 -0
- package/dist/index.js.bak +872 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +102 -0
- package/dist/types/index.js +85 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/errors.d.ts +15 -0
- package/dist/utils/errors.js +50 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +37 -0
- package/dist/utils/logger.js +62 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +48 -0
- package/dist/utils/validation.js +100 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +81 -35
- package/.github/workflows/npm-publish-github-packages.yml +0 -36
- package/SECURITY.md +0 -21
- package/assets/logo.png +0 -0
- package/assets/s1.png +0 -0
- package/create-fs-app.js +0 -181
|
@@ -0,0 +1,872 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import gradient from 'gradient-string';
|
|
6
|
+
import figlet from 'figlet';
|
|
7
|
+
import ora from 'ora';
|
|
8
|
+
import boxen from 'boxen';
|
|
9
|
+
import updateNotifier from 'update-notifier';
|
|
10
|
+
import { readFileSync } from 'fs';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import { dirname, join } from 'path';
|
|
13
|
+
import { ProjectConfigSchema, MonorepoFramework, FrontendFramework, BackendFramework, Database, PackageManager, ApiStyle, AuthStrategy, } from './types/index.js';
|
|
14
|
+
import { scaffoldProject, validateProjectDirectory, checkTemplateAvailability, TemplateNotFoundError } from './core/scaffold.js';
|
|
15
|
+
import { displayAvailableTemplates, getTemplateByName } from './core/template-list.js';
|
|
16
|
+
import { assertValidProjectName } from './utils/validation.js';
|
|
17
|
+
import { Logger } from './utils/logger.js';
|
|
18
|
+
import { savePreset, loadPreset, listPresets, deletePreset, getBuiltinPreset, 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 { validateTemplateUrl } 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:');
|
|
130
|
+
console.error(error);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function promptForConfiguration(projectName) {
|
|
135
|
+
const onCancel = () => {
|
|
136
|
+
console.log(chalk.yellow('\n\nOperation cancelled by user'));
|
|
137
|
+
process.exit(0);
|
|
138
|
+
};
|
|
139
|
+
// ── Step 1: Project name ────────────────────────────────────────────────
|
|
140
|
+
let name = projectName;
|
|
141
|
+
if (!name) {
|
|
142
|
+
const { projectName: n } = await prompts({
|
|
143
|
+
type: 'text',
|
|
144
|
+
name: 'projectName',
|
|
145
|
+
message: 'Project name:',
|
|
146
|
+
initial: 'my-fs-app',
|
|
147
|
+
validate: (v) => v.trim().length > 0 || 'Name required'
|
|
148
|
+
}, { onCancel });
|
|
149
|
+
name = n;
|
|
150
|
+
}
|
|
151
|
+
// ── Step 2: Monorepo + package manager ─────────────────────────────────
|
|
152
|
+
const { monorepo, packageManager } = await prompts([
|
|
153
|
+
{
|
|
154
|
+
type: 'select',
|
|
155
|
+
name: 'monorepo',
|
|
156
|
+
message: 'Monorepo tool:',
|
|
157
|
+
choices: [
|
|
158
|
+
{ title: 'Turborepo — fast build caching, simple config', value: 'turborepo' },
|
|
159
|
+
{ title: 'Nx — powerful task graph, generators', value: 'nx' },
|
|
160
|
+
],
|
|
161
|
+
initial: 0
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'select',
|
|
165
|
+
name: 'packageManager',
|
|
166
|
+
message: 'Package manager:',
|
|
167
|
+
choices: [
|
|
168
|
+
{ title: 'npm', value: 'npm' },
|
|
169
|
+
{ title: 'pnpm — faster installs, disk efficient', value: 'pnpm' },
|
|
170
|
+
{ title: 'yarn', value: 'yarn' },
|
|
171
|
+
],
|
|
172
|
+
initial: 0
|
|
173
|
+
},
|
|
174
|
+
], { onCancel });
|
|
175
|
+
// ── Step 3: Frontend ────────────────────────────────────────────────────
|
|
176
|
+
const { frontendFramework, styling } = await prompts([
|
|
177
|
+
{
|
|
178
|
+
type: 'select',
|
|
179
|
+
name: 'frontendFramework',
|
|
180
|
+
message: 'Frontend framework:',
|
|
181
|
+
choices: [
|
|
182
|
+
{ title: 'Next.js — App Router, SSR, RSC', value: 'next.js' },
|
|
183
|
+
{ title: 'React — Vite, SPA/CSR', value: 'react' },
|
|
184
|
+
{ title: 'Vue — Vite, Options/Composition API', value: 'vue' },
|
|
185
|
+
{ title: 'Nuxt — SSR for Vue', value: 'nuxt' },
|
|
186
|
+
{ title: 'Angular — full framework', value: 'angular' },
|
|
187
|
+
],
|
|
188
|
+
initial: 0
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
type: 'select',
|
|
192
|
+
name: 'styling',
|
|
193
|
+
message: 'Styling solution:',
|
|
194
|
+
choices: [
|
|
195
|
+
{ title: 'Tailwind CSS — utility-first', value: 'tailwind' },
|
|
196
|
+
{ title: 'CSS — plain stylesheets', value: 'css' },
|
|
197
|
+
{ title: 'SCSS/Sass — CSS with superpowers', value: 'scss' },
|
|
198
|
+
{ title: 'Styled Components — CSS-in-JS', value: 'styled-components' },
|
|
199
|
+
],
|
|
200
|
+
initial: 0
|
|
201
|
+
},
|
|
202
|
+
], { onCancel });
|
|
203
|
+
// Turbopack — only relevant for Next.js
|
|
204
|
+
let turbopack = false;
|
|
205
|
+
if (frontendFramework === 'next.js') {
|
|
206
|
+
const { tp } = await prompts({
|
|
207
|
+
type: 'confirm',
|
|
208
|
+
name: 'tp',
|
|
209
|
+
message: 'Enable Turbopack? (faster dev server for Next.js)',
|
|
210
|
+
initial: true
|
|
211
|
+
}, { onCancel });
|
|
212
|
+
turbopack = tp;
|
|
213
|
+
}
|
|
214
|
+
// ── Step 4: Code quality ────────────────────────────────────────────────
|
|
215
|
+
const { eslint, prettier } = await prompts([
|
|
216
|
+
{
|
|
217
|
+
type: 'confirm',
|
|
218
|
+
name: 'eslint',
|
|
219
|
+
message: 'Add ESLint?',
|
|
220
|
+
initial: true
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
type: 'confirm',
|
|
224
|
+
name: 'prettier',
|
|
225
|
+
message: 'Add Prettier?',
|
|
226
|
+
initial: true
|
|
227
|
+
},
|
|
228
|
+
], { onCancel });
|
|
229
|
+
// ── Step 5: Backend ─────────────────────────────────────────────────────
|
|
230
|
+
const { backendFramework, database, orm } = await prompts([
|
|
231
|
+
{
|
|
232
|
+
type: 'select',
|
|
233
|
+
name: 'backendFramework',
|
|
234
|
+
message: 'Backend framework:',
|
|
235
|
+
choices: [
|
|
236
|
+
{ title: 'NestJS — TypeScript-first, modular, decorators', value: 'nest.js' },
|
|
237
|
+
{ title: 'Express — minimal, flexible, battle-tested', value: 'express' },
|
|
238
|
+
{ title: 'Fastify — high performance, schema validation', value: 'fastify-ts' },
|
|
239
|
+
{ title: 'Koa — lightweight, async middleware', value: 'koa' },
|
|
240
|
+
],
|
|
241
|
+
initial: 0
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
type: 'select',
|
|
245
|
+
name: 'database',
|
|
246
|
+
message: 'Database:',
|
|
247
|
+
choices: [
|
|
248
|
+
{ title: 'PostgreSQL — relational, ACID, powerful', value: 'postgresql' },
|
|
249
|
+
{ title: 'MongoDB — document, flexible schema', value: 'mongodb' },
|
|
250
|
+
{ title: 'MySQL — relational, widely supported', value: 'mysql' },
|
|
251
|
+
{ title: 'SQLite — file-based, zero setup', value: 'sqlite' },
|
|
252
|
+
],
|
|
253
|
+
initial: 0
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
type: 'select',
|
|
257
|
+
name: 'orm',
|
|
258
|
+
message: 'ORM / ODM:',
|
|
259
|
+
choices: [
|
|
260
|
+
{ title: 'Prisma — type-safe, migrations, Studio', value: 'prisma' },
|
|
261
|
+
{ title: 'TypeORM — decorators, ActiveRecord/DataMapper', value: 'typeorm' },
|
|
262
|
+
{ title: 'Mongoose — MongoDB ODM, schemas', value: 'mongoose' },
|
|
263
|
+
{ title: 'Drizzle — lightweight, SQL-like', value: 'drizzle' },
|
|
264
|
+
],
|
|
265
|
+
initial: 0
|
|
266
|
+
},
|
|
267
|
+
], { onCancel });
|
|
268
|
+
// ── Step 6: API style ───────────────────────────────────────────────────
|
|
269
|
+
const { apiStyle } = await prompts({
|
|
270
|
+
type: 'select',
|
|
271
|
+
name: 'apiStyle',
|
|
272
|
+
message: 'API style:',
|
|
273
|
+
choices: [
|
|
274
|
+
{ title: 'REST — standard HTTP endpoints (recommended)', value: 'rest' },
|
|
275
|
+
{ title: 'GraphQL — flexible queries with Apollo/Mercurius', value: 'graphql' },
|
|
276
|
+
{ title: 'Both — REST + GraphQL side by side', value: 'both' },
|
|
277
|
+
],
|
|
278
|
+
initial: 0
|
|
279
|
+
}, { onCancel });
|
|
280
|
+
// ── Step 7: Auth ────────────────────────────────────────────────────────
|
|
281
|
+
const { auth } = await prompts({
|
|
282
|
+
type: 'select',
|
|
283
|
+
name: 'auth',
|
|
284
|
+
message: 'Authentication scaffolding:',
|
|
285
|
+
choices: [
|
|
286
|
+
{ title: 'None — skip auth, add manually later', value: 'none' },
|
|
287
|
+
{ title: 'JWT — login/register endpoints + guards/middleware', value: 'jwt' },
|
|
288
|
+
],
|
|
289
|
+
initial: 0
|
|
290
|
+
}, { onCancel });
|
|
291
|
+
// ── Step 8: Docker + CI ────────────────────────────────────────────────
|
|
292
|
+
const { docker, ci } = await prompts([
|
|
293
|
+
{
|
|
294
|
+
type: 'confirm',
|
|
295
|
+
name: 'docker',
|
|
296
|
+
message: 'Include Docker / Docker Compose?',
|
|
297
|
+
initial: true
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
type: 'confirm',
|
|
301
|
+
name: 'ci',
|
|
302
|
+
message: 'Add GitHub Actions CI? (lint → build on push/PR)',
|
|
303
|
+
initial: false
|
|
304
|
+
},
|
|
305
|
+
], { onCancel });
|
|
306
|
+
// ── Build + validate config ─────────────────────────────────────────────
|
|
307
|
+
const config = {
|
|
308
|
+
name: name,
|
|
309
|
+
monorepo,
|
|
310
|
+
packageManager,
|
|
311
|
+
ci,
|
|
312
|
+
apps: {
|
|
313
|
+
frontend: {
|
|
314
|
+
framework: frontendFramework,
|
|
315
|
+
styling,
|
|
316
|
+
eslint,
|
|
317
|
+
prettier,
|
|
318
|
+
turbopack,
|
|
319
|
+
},
|
|
320
|
+
backend: {
|
|
321
|
+
framework: backendFramework,
|
|
322
|
+
database,
|
|
323
|
+
orm,
|
|
324
|
+
apiStyle,
|
|
325
|
+
auth,
|
|
326
|
+
docker,
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
return ProjectConfigSchema.parse(config);
|
|
331
|
+
}
|
|
332
|
+
async function main() {
|
|
333
|
+
// ── Hydrate registry from GitHub (non-blocking, 5 s timeout) ────────────
|
|
334
|
+
// Silently falls back to the hardcoded registry on any failure so the CLI
|
|
335
|
+
// always works offline. New templates published to the templates repo are
|
|
336
|
+
// picked up automatically without a CLI release.
|
|
337
|
+
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('--no-install', 'Skip package installation')
|
|
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
|
+
// Check if using preset
|
|
381
|
+
if (options.preset) {
|
|
382
|
+
if (!name) {
|
|
383
|
+
Logger.error('Project name is required when using --preset.');
|
|
384
|
+
console.log(chalk.cyan('Usage: create-fs-app <project-name> --preset <preset-name>\n'));
|
|
385
|
+
process.exit(1);
|
|
386
|
+
}
|
|
387
|
+
// Try built-in preset first
|
|
388
|
+
let preset = getBuiltinPreset(options.preset);
|
|
389
|
+
// If not built-in, try user preset
|
|
390
|
+
if (!preset) {
|
|
391
|
+
preset = await loadPreset(options.preset);
|
|
392
|
+
}
|
|
393
|
+
if (!preset) {
|
|
394
|
+
Logger.error(`Preset "${options.preset}" not found`);
|
|
395
|
+
console.log(chalk.cyan('\n💡 Use ') + chalk.white.bold('create-fs-app preset list') + chalk.cyan(' to see available presets.\n'));
|
|
396
|
+
process.exit(1);
|
|
397
|
+
}
|
|
398
|
+
projectConfig = {
|
|
399
|
+
name,
|
|
400
|
+
...preset.config
|
|
401
|
+
};
|
|
402
|
+
console.log();
|
|
403
|
+
const infoBox = boxen(chalk.cyan.bold('🎯 Using Preset\n\n') +
|
|
404
|
+
chalk.white(`Preset: `) + chalk.green(preset.name) + '\n' +
|
|
405
|
+
(preset.description ? chalk.white(`Description: `) + chalk.gray(preset.description) : ''), {
|
|
406
|
+
padding: 1,
|
|
407
|
+
margin: 1,
|
|
408
|
+
borderStyle: 'round',
|
|
409
|
+
borderColor: 'cyan'
|
|
410
|
+
});
|
|
411
|
+
console.log(infoBox);
|
|
412
|
+
}
|
|
413
|
+
// Check if using custom template URL
|
|
414
|
+
else if (options.templateUrl) {
|
|
415
|
+
if (!name) {
|
|
416
|
+
Logger.error('Project name is required when using --template-url.');
|
|
417
|
+
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template-url <url>\n'));
|
|
418
|
+
process.exit(1);
|
|
419
|
+
}
|
|
420
|
+
// Validate URL
|
|
421
|
+
const validation = validateTemplateUrl(options.templateUrl);
|
|
422
|
+
if (!validation.valid) {
|
|
423
|
+
Logger.error(validation.error);
|
|
424
|
+
process.exit(1);
|
|
425
|
+
}
|
|
426
|
+
// Create minimal config for custom template
|
|
427
|
+
customTemplate = createCustomTemplate(options.templateUrl);
|
|
428
|
+
projectConfig = {
|
|
429
|
+
name,
|
|
430
|
+
monorepo: 'turborepo',
|
|
431
|
+
packageManager: 'npm',
|
|
432
|
+
ci: false,
|
|
433
|
+
apps: {
|
|
434
|
+
frontend: {
|
|
435
|
+
framework: 'react',
|
|
436
|
+
styling: 'tailwind',
|
|
437
|
+
eslint: true,
|
|
438
|
+
prettier: true,
|
|
439
|
+
turbopack: false,
|
|
440
|
+
},
|
|
441
|
+
backend: {
|
|
442
|
+
framework: 'express',
|
|
443
|
+
database: 'postgresql',
|
|
444
|
+
apiStyle: 'rest',
|
|
445
|
+
auth: 'none',
|
|
446
|
+
docker: true,
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
console.log();
|
|
451
|
+
const infoBox = boxen(chalk.cyan.bold('🔗 Using Custom Template\n\n') +
|
|
452
|
+
chalk.white(`URL: `) + chalk.green(options.templateUrl), {
|
|
453
|
+
padding: 1,
|
|
454
|
+
margin: 1,
|
|
455
|
+
borderStyle: 'round',
|
|
456
|
+
borderColor: 'cyan'
|
|
457
|
+
});
|
|
458
|
+
console.log(infoBox);
|
|
459
|
+
}
|
|
460
|
+
// Check if using direct template
|
|
461
|
+
else if (options.template) {
|
|
462
|
+
const template = getTemplateByName(options.template);
|
|
463
|
+
if (!template) {
|
|
464
|
+
const errorBox = boxen(chalk.red.bold('❌ Template Not Found\n\n') +
|
|
465
|
+
chalk.white(`Template "${options.template}" doesn't exist.\n\n`) +
|
|
466
|
+
chalk.cyan('💡 Use ') + chalk.white.bold('create-fs-app list') + chalk.cyan(' to see available templates.'), {
|
|
467
|
+
padding: 1,
|
|
468
|
+
margin: 1,
|
|
469
|
+
borderStyle: 'round',
|
|
470
|
+
borderColor: 'red'
|
|
471
|
+
});
|
|
472
|
+
console.log(errorBox);
|
|
473
|
+
process.exit(1);
|
|
474
|
+
}
|
|
475
|
+
// For direct template usage, we still need a project name
|
|
476
|
+
if (!name) {
|
|
477
|
+
console.log(chalk.red('\n❌ Project name is required when using --template.\n'));
|
|
478
|
+
console.log(chalk.cyan('Usage: create-fs-app <project-name> --template <template-name>\n'));
|
|
479
|
+
process.exit(1);
|
|
480
|
+
}
|
|
481
|
+
// Extract configuration from template key automatically
|
|
482
|
+
const parts = template.key.split('-');
|
|
483
|
+
const tplFrontend = (parts[1] === 'nextjs' ? 'next.js' : parts[1]);
|
|
484
|
+
projectConfig = {
|
|
485
|
+
name,
|
|
486
|
+
monorepo: parts[0],
|
|
487
|
+
packageManager: options.packageManager
|
|
488
|
+
? validateEnum(options.packageManager, PackageManager, 'package manager')
|
|
489
|
+
: PackageManager.NPM,
|
|
490
|
+
ci: options.ci === true,
|
|
491
|
+
apps: {
|
|
492
|
+
frontend: {
|
|
493
|
+
framework: tplFrontend,
|
|
494
|
+
styling: 'tailwind',
|
|
495
|
+
eslint: true,
|
|
496
|
+
prettier: true,
|
|
497
|
+
turbopack: false,
|
|
498
|
+
},
|
|
499
|
+
backend: {
|
|
500
|
+
framework: (parts[2] === 'nestjs' ? 'nest.js' : parts[2]),
|
|
501
|
+
database: parts[3],
|
|
502
|
+
orm: parts[4],
|
|
503
|
+
apiStyle: 'rest',
|
|
504
|
+
auth: 'none',
|
|
505
|
+
docker: true,
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
console.log();
|
|
510
|
+
const infoBox = boxen(chalk.cyan.bold('🚀 Using Template\n\n') +
|
|
511
|
+
chalk.white(`Template: `) + chalk.green(template.key) + '\n' +
|
|
512
|
+
chalk.white(`Description: `) + chalk.gray(template.metadata.description), {
|
|
513
|
+
padding: 1,
|
|
514
|
+
margin: 1,
|
|
515
|
+
borderStyle: 'round',
|
|
516
|
+
borderColor: 'cyan'
|
|
517
|
+
});
|
|
518
|
+
console.log(infoBox);
|
|
519
|
+
}
|
|
520
|
+
// --yes: fill missing flags with saas-starter defaults, skip all prompts
|
|
521
|
+
else if (options.yes) {
|
|
522
|
+
if (!name) {
|
|
523
|
+
Logger.error('Project name is required when using --yes.');
|
|
524
|
+
console.log(chalk.cyan('Usage: create-fs-app <project-name> [options] --yes\n'));
|
|
525
|
+
process.exit(1);
|
|
526
|
+
}
|
|
527
|
+
// Merge any explicit flags with defaults — explicit always wins
|
|
528
|
+
const withDefaults = {
|
|
529
|
+
...options,
|
|
530
|
+
monorepo: options.monorepo ?? 'turborepo',
|
|
531
|
+
frontend: options.frontend ?? 'next.js',
|
|
532
|
+
backend: options.backend ?? 'nest.js',
|
|
533
|
+
database: options.database ?? 'postgresql',
|
|
534
|
+
orm: options.orm ?? 'prisma',
|
|
535
|
+
};
|
|
536
|
+
projectConfig = buildConfigFromOptions(name, withDefaults);
|
|
537
|
+
// Show resolved configuration
|
|
538
|
+
console.log(chalk.cyan('\n⚡ Using defaults (--yes)\n'));
|
|
539
|
+
console.log(chalk.gray(' Project:'), chalk.white(projectConfig.name));
|
|
540
|
+
console.log(chalk.gray(' Monorepo:'), chalk.white(projectConfig.monorepo));
|
|
541
|
+
console.log(chalk.gray(' Pkg manager:'), chalk.white(projectConfig.packageManager));
|
|
542
|
+
console.log(chalk.gray(' Frontend:'), chalk.white(projectConfig.apps.frontend.framework));
|
|
543
|
+
console.log(chalk.gray(' Styling:'), chalk.white(projectConfig.apps.frontend.styling));
|
|
544
|
+
console.log(chalk.gray(' Backend:'), chalk.white(projectConfig.apps.backend.framework));
|
|
545
|
+
console.log(chalk.gray(' Database:'), chalk.white(projectConfig.apps.backend.database));
|
|
546
|
+
console.log(chalk.gray(' ORM:'), chalk.white(projectConfig.apps.backend.orm ?? 'none'));
|
|
547
|
+
console.log(chalk.gray(' Docker:'), chalk.white(projectConfig.apps.backend.docker ? 'yes' : 'no'));
|
|
548
|
+
console.log(chalk.gray(' CI:'), chalk.white(projectConfig.ci ? 'yes' : 'no'));
|
|
549
|
+
console.log();
|
|
550
|
+
}
|
|
551
|
+
// Check if stack options provided via CLI
|
|
552
|
+
else if (options.monorepo || options.frontend || options.backend) {
|
|
553
|
+
projectConfig = buildConfigFromOptions(name, options);
|
|
554
|
+
// Show detected configuration
|
|
555
|
+
console.log(chalk.cyan('\n📋 Configuration from CLI options:\n'));
|
|
556
|
+
console.log(chalk.gray(' Project:'), chalk.white(projectConfig.name));
|
|
557
|
+
console.log(chalk.gray(' Monorepo:'), chalk.white(projectConfig.monorepo));
|
|
558
|
+
console.log(chalk.gray(' Pkg manager:'), chalk.white(projectConfig.packageManager));
|
|
559
|
+
console.log(chalk.gray(' Frontend:'), chalk.white(projectConfig.apps.frontend.framework));
|
|
560
|
+
console.log(chalk.gray(' Styling:'), chalk.white(projectConfig.apps.frontend.styling));
|
|
561
|
+
console.log(chalk.gray(' ESLint:'), chalk.white(projectConfig.apps.frontend.eslint ? 'yes' : 'no'));
|
|
562
|
+
console.log(chalk.gray(' Prettier:'), chalk.white(projectConfig.apps.frontend.prettier ? 'yes' : 'no'));
|
|
563
|
+
if (projectConfig.apps.frontend.turbopack) {
|
|
564
|
+
console.log(chalk.gray(' Turbopack:'), chalk.white('yes'));
|
|
565
|
+
}
|
|
566
|
+
console.log(chalk.gray(' Backend:'), chalk.white(projectConfig.apps.backend.framework));
|
|
567
|
+
console.log(chalk.gray(' Database:'), chalk.white(projectConfig.apps.backend.database));
|
|
568
|
+
if (projectConfig.apps.backend.orm) {
|
|
569
|
+
console.log(chalk.gray(' ORM:'), chalk.white(projectConfig.apps.backend.orm));
|
|
570
|
+
}
|
|
571
|
+
console.log(chalk.gray(' API style:'), chalk.white(projectConfig.apps.backend.apiStyle));
|
|
572
|
+
console.log(chalk.gray(' Auth:'), chalk.white(projectConfig.apps.backend.auth));
|
|
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
|
+
// Interactive mode
|
|
578
|
+
else {
|
|
579
|
+
projectConfig = await promptForConfiguration(name);
|
|
580
|
+
}
|
|
581
|
+
// Validate project directory
|
|
582
|
+
await validateProjectDirectory(projectConfig.name);
|
|
583
|
+
// Check if template exists
|
|
584
|
+
const availability = checkTemplateAvailability(projectConfig);
|
|
585
|
+
if (!availability.available) {
|
|
586
|
+
console.log(chalk.yellow('\n⚠️ No exact template match found for your configuration.'));
|
|
587
|
+
console.log(chalk.cyan('\n📋 Available similar templates:'));
|
|
588
|
+
availability.suggestions?.forEach((s, i) => {
|
|
589
|
+
console.log(chalk.cyan(` ${i + 1}. ${s}`));
|
|
590
|
+
});
|
|
591
|
+
console.log(chalk.yellow('\n💡 Tip: You can contribute this template combination to our repository!'));
|
|
592
|
+
console.log(chalk.blue(' Visit: https://github.com/create-fs-app-templates\n'));
|
|
593
|
+
process.exit(0);
|
|
594
|
+
}
|
|
595
|
+
const spinner = ora({
|
|
596
|
+
text: 'Creating your full-stack app...',
|
|
597
|
+
spinner: 'dots',
|
|
598
|
+
color: 'cyan',
|
|
599
|
+
hideCursor: true
|
|
600
|
+
}).start();
|
|
601
|
+
try {
|
|
602
|
+
await scaffoldProject(projectConfig, {
|
|
603
|
+
skipGit: options.git === false,
|
|
604
|
+
skipInstall: options.install === false,
|
|
605
|
+
skipCache: options.cache === false,
|
|
606
|
+
localTemplatesDir: options.localTemplates,
|
|
607
|
+
});
|
|
608
|
+
spinner.succeed(chalk.green.bold('Project created successfully!'));
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
spinner.fail(chalk.red.bold('Project creation failed!'));
|
|
612
|
+
throw error;
|
|
613
|
+
}
|
|
614
|
+
finally {
|
|
615
|
+
// Ensure cursor is visible
|
|
616
|
+
process.stdout.write('\x1B[?25h');
|
|
617
|
+
}
|
|
618
|
+
console.log();
|
|
619
|
+
// Success box
|
|
620
|
+
const successMsg = boxen(chalk.white.bold(`🎉 ${projectConfig.name} is ready!\n\n`) +
|
|
621
|
+
chalk.cyan.bold('Next Steps:\n\n') +
|
|
622
|
+
chalk.white(`${chalk.green('1.')} ${chalk.cyan(`cd ${projectConfig.name}`)}\n`) +
|
|
623
|
+
chalk.white(`${chalk.green('2.')} ${chalk.cyan(options.install === false ? `${projectConfig.packageManager} install` : `${projectConfig.packageManager} run dev`)}\n`) +
|
|
624
|
+
chalk.white(`${chalk.green('3.')} ${chalk.cyan('Start building! 🚀')}\n\n`) +
|
|
625
|
+
chalk.gray('Documentation:\n') +
|
|
626
|
+
chalk.gray('• README.md - Project overview\n') +
|
|
627
|
+
chalk.gray('• .env.example - Environment setup'), {
|
|
628
|
+
padding: 1,
|
|
629
|
+
margin: 1,
|
|
630
|
+
borderStyle: 'round',
|
|
631
|
+
borderColor: 'green',
|
|
632
|
+
title: chalk.bold.green('✨ Success'),
|
|
633
|
+
titleAlignment: 'center'
|
|
634
|
+
});
|
|
635
|
+
console.log(successMsg);
|
|
636
|
+
console.log();
|
|
637
|
+
}
|
|
638
|
+
catch (error) {
|
|
639
|
+
if (error instanceof TemplateNotFoundError) {
|
|
640
|
+
console.log(error.message);
|
|
641
|
+
if (error.suggestions.length > 0) {
|
|
642
|
+
console.log(chalk.cyan('\n📋 Similar templates you might like:'));
|
|
643
|
+
error.suggestions.forEach((s, i) => {
|
|
644
|
+
console.log(chalk.cyan(` ${i + 1}. ${s}`));
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
console.error(chalk.red('\n❌ Error creating project:'));
|
|
650
|
+
console.error(error);
|
|
651
|
+
}
|
|
652
|
+
process.exit(1);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
// List templates command
|
|
656
|
+
program
|
|
657
|
+
.command('list')
|
|
658
|
+
.description('List all available templates')
|
|
659
|
+
.alias('ls')
|
|
660
|
+
.action(() => {
|
|
661
|
+
displayAvailableTemplates();
|
|
662
|
+
});
|
|
663
|
+
// Template info command
|
|
664
|
+
program
|
|
665
|
+
.command('info <template>')
|
|
666
|
+
.description('Show detailed information about a template')
|
|
667
|
+
.action((templateName) => {
|
|
668
|
+
const template = getTemplateByName(templateName);
|
|
669
|
+
if (!template) {
|
|
670
|
+
const errorBox = boxen(chalk.red.bold('❌ Template Not Found\n\n') +
|
|
671
|
+
chalk.white(`"${templateName}" doesn't exist.\n\n`) +
|
|
672
|
+
chalk.gray('Use ') + chalk.cyan('create-fs-app list') + chalk.gray(' to see available templates.'), {
|
|
673
|
+
padding: 1,
|
|
674
|
+
margin: 1,
|
|
675
|
+
borderStyle: 'round',
|
|
676
|
+
borderColor: 'red'
|
|
677
|
+
});
|
|
678
|
+
console.log(errorBox);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
console.log();
|
|
682
|
+
const infoBox = boxen(chalk.bold.white(`📦 ${template.key}\n\n`) +
|
|
683
|
+
chalk.gray('Description:\n') +
|
|
684
|
+
chalk.white(`${template.metadata.description}\n\n`) +
|
|
685
|
+
chalk.gray('Features:\n') +
|
|
686
|
+
template.metadata.features.map((f) => chalk.green(`✓ ${f}`)).join('\n') +
|
|
687
|
+
'\n\n' +
|
|
688
|
+
chalk.gray('Repository:\n') +
|
|
689
|
+
chalk.cyan.underline(template.metadata.url), {
|
|
690
|
+
padding: 1,
|
|
691
|
+
margin: 1,
|
|
692
|
+
borderStyle: 'round',
|
|
693
|
+
borderColor: 'cyan',
|
|
694
|
+
title: chalk.bold.cyan('Template Info'),
|
|
695
|
+
titleAlignment: 'center'
|
|
696
|
+
});
|
|
697
|
+
console.log(infoBox);
|
|
698
|
+
const usageBox = boxen(chalk.cyan(`npx create-fs-app my-app --template ${template.key}`), {
|
|
699
|
+
padding: 1,
|
|
700
|
+
margin: { top: 0, bottom: 1, left: 1, right: 1 },
|
|
701
|
+
borderStyle: 'round',
|
|
702
|
+
borderColor: 'blue',
|
|
703
|
+
title: chalk.bold.blue('💡 Usage'),
|
|
704
|
+
titleAlignment: 'left'
|
|
705
|
+
});
|
|
706
|
+
console.log(usageBox);
|
|
707
|
+
});
|
|
708
|
+
// Health check command
|
|
709
|
+
program
|
|
710
|
+
.command('health')
|
|
711
|
+
.description('Run health check on current project')
|
|
712
|
+
.action(async () => {
|
|
713
|
+
try {
|
|
714
|
+
const result = await runHealthCheck();
|
|
715
|
+
displayHealthCheckResults(result);
|
|
716
|
+
process.exit(result.passed ? 0 : 1);
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
Logger.error('Failed to run health check');
|
|
720
|
+
console.error(error);
|
|
721
|
+
process.exit(1);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
// Preset commands
|
|
725
|
+
const presetCmd = program
|
|
726
|
+
.command('preset')
|
|
727
|
+
.description('Manage configuration presets');
|
|
728
|
+
presetCmd
|
|
729
|
+
.command('save <name>')
|
|
730
|
+
.description('Save a stack configuration as a reusable preset')
|
|
731
|
+
.option('-d, --description <desc>', 'Preset description')
|
|
732
|
+
.option('--monorepo <framework>', 'Monorepo framework (default: turborepo)')
|
|
733
|
+
.option('--frontend <framework>', 'Frontend framework (default: next.js)')
|
|
734
|
+
.option('--backend <framework>', 'Backend framework (default: nest.js)')
|
|
735
|
+
.option('--database <db>', 'Database (default: postgresql)')
|
|
736
|
+
.option('--orm <orm>', 'ORM (default: prisma)')
|
|
737
|
+
.option('--package-manager <pm>', 'Package manager (default: npm)')
|
|
738
|
+
.option('--styling <style>', 'Styling solution (default: tailwind)')
|
|
739
|
+
.option('--api-style <style>', 'API style (default: rest)')
|
|
740
|
+
.option('--auth <strategy>', 'Auth strategy (default: none)')
|
|
741
|
+
.option('--docker', 'Include Docker (default: true)')
|
|
742
|
+
.option('--no-docker', 'Skip Docker')
|
|
743
|
+
.option('--ci', 'Include GitHub Actions CI')
|
|
744
|
+
.option('--no-ci', 'Skip CI (default)')
|
|
745
|
+
.action(async (presetName, options) => {
|
|
746
|
+
try {
|
|
747
|
+
// Fill defaults for any unspecified flags (same defaults as --yes)
|
|
748
|
+
const withDefaults = {
|
|
749
|
+
...options,
|
|
750
|
+
monorepo: options.monorepo ?? 'turborepo',
|
|
751
|
+
frontend: options.frontend ?? 'next.js',
|
|
752
|
+
backend: options.backend ?? 'nest.js',
|
|
753
|
+
database: options.database ?? 'postgresql',
|
|
754
|
+
orm: options.orm ?? 'prisma',
|
|
755
|
+
};
|
|
756
|
+
// Build and validate the config (dummy project name — stripped by savePreset)
|
|
757
|
+
const config = buildConfigFromOptions('preset-placeholder', withDefaults);
|
|
758
|
+
await savePreset(presetName, config, options.description);
|
|
759
|
+
console.log(chalk.green(`\n✓ Preset "${presetName}" saved\n`));
|
|
760
|
+
console.log(chalk.gray(' Monorepo:'), chalk.white(config.monorepo));
|
|
761
|
+
console.log(chalk.gray(' Pkg manager:'), chalk.white(config.packageManager));
|
|
762
|
+
console.log(chalk.gray(' Frontend:'), chalk.white(config.apps.frontend.framework));
|
|
763
|
+
console.log(chalk.gray(' Backend:'), chalk.white(config.apps.backend.framework));
|
|
764
|
+
console.log(chalk.gray(' Database:'), chalk.white(config.apps.backend.database));
|
|
765
|
+
console.log(chalk.gray(' ORM:'), chalk.white(config.apps.backend.orm ?? 'none'));
|
|
766
|
+
console.log(chalk.gray(' Docker:'), chalk.white(config.apps.backend.docker ? 'yes' : 'no'));
|
|
767
|
+
console.log();
|
|
768
|
+
console.log(chalk.cyan(`💡 Use it: create-fs-app my-app --preset ${presetName}\n`));
|
|
769
|
+
}
|
|
770
|
+
catch (error) {
|
|
771
|
+
Logger.error('Failed to save preset');
|
|
772
|
+
console.error(error);
|
|
773
|
+
process.exit(1);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
presetCmd
|
|
777
|
+
.command('list')
|
|
778
|
+
.description('List all saved presets')
|
|
779
|
+
.action(async () => {
|
|
780
|
+
try {
|
|
781
|
+
const presets = await listPresets();
|
|
782
|
+
const builtinKeys = Object.keys(BUILTIN_PRESETS);
|
|
783
|
+
console.log(chalk.cyan.bold('\n📚 Available Presets\n'));
|
|
784
|
+
// Built-in presets
|
|
785
|
+
console.log(chalk.bold.green('Built-in Presets:'));
|
|
786
|
+
builtinKeys.forEach(key => {
|
|
787
|
+
const preset = BUILTIN_PRESETS[key];
|
|
788
|
+
console.log(chalk.white(` ${key}`));
|
|
789
|
+
console.log(chalk.gray(` ${preset.description}`));
|
|
790
|
+
});
|
|
791
|
+
// User presets
|
|
792
|
+
if (presets.length > 0) {
|
|
793
|
+
console.log(chalk.bold.green('\nYour Presets:'));
|
|
794
|
+
presets.forEach(preset => {
|
|
795
|
+
console.log(chalk.white(` ${preset.name}`));
|
|
796
|
+
if (preset.description) {
|
|
797
|
+
console.log(chalk.gray(` ${preset.description}`));
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
console.log(chalk.cyan('\n💡 Use: create-fs-app my-app --preset <name>\n'));
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
Logger.error('Failed to list presets');
|
|
805
|
+
console.error(error);
|
|
806
|
+
process.exit(1);
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
presetCmd
|
|
810
|
+
.command('delete <name>')
|
|
811
|
+
.description('Delete a saved preset')
|
|
812
|
+
.action(async (name) => {
|
|
813
|
+
try {
|
|
814
|
+
const deleted = await deletePreset(name);
|
|
815
|
+
if (!deleted) {
|
|
816
|
+
Logger.error(`Preset "${name}" not found`);
|
|
817
|
+
process.exit(1);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
Logger.error('Failed to delete preset');
|
|
822
|
+
console.error(error);
|
|
823
|
+
process.exit(1);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
// Cache commands
|
|
827
|
+
const cacheCmd = program
|
|
828
|
+
.command('cache')
|
|
829
|
+
.description('Manage template cache');
|
|
830
|
+
cacheCmd
|
|
831
|
+
.command('clear')
|
|
832
|
+
.description('Clear template cache and registry cache')
|
|
833
|
+
.action(async () => {
|
|
834
|
+
try {
|
|
835
|
+
await clearCache();
|
|
836
|
+
await clearRegistryCache();
|
|
837
|
+
console.log(chalk.green('✓ Template cache and registry cache cleared'));
|
|
838
|
+
}
|
|
839
|
+
catch (error) {
|
|
840
|
+
Logger.error('Failed to clear cache');
|
|
841
|
+
console.error(error);
|
|
842
|
+
process.exit(1);
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
cacheCmd
|
|
846
|
+
.command('stats')
|
|
847
|
+
.description('Show cache statistics')
|
|
848
|
+
.action(async () => {
|
|
849
|
+
try {
|
|
850
|
+
const stats = await getCacheStats();
|
|
851
|
+
console.log(chalk.cyan.bold('\n📊 Cache Statistics\n'));
|
|
852
|
+
console.log(chalk.white(`Total templates: ${stats.totalTemplates}`));
|
|
853
|
+
console.log(chalk.white(`Cache size: ${stats.cacheSize}`));
|
|
854
|
+
if (stats.templates.length > 0) {
|
|
855
|
+
console.log(chalk.bold('\nCached Templates:'));
|
|
856
|
+
stats.templates.forEach(t => {
|
|
857
|
+
console.log(chalk.gray(` ${t.key}`));
|
|
858
|
+
console.log(chalk.gray(` Last used: ${new Date(t.lastUsed).toLocaleDateString()}`));
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
console.log();
|
|
862
|
+
}
|
|
863
|
+
catch (error) {
|
|
864
|
+
Logger.error('Failed to get cache stats');
|
|
865
|
+
console.error(error);
|
|
866
|
+
process.exit(1);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
program.parse();
|
|
870
|
+
}
|
|
871
|
+
main().catch(console.error);
|
|
872
|
+
//# sourceMappingURL=index.js.map
|