create-fs-app 2.0.5 → 3.1.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 +271 -158
- 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 +113 -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 +46 -44
- package/dist/core/presets.js +75 -117
- package/dist/core/registry-fetch.js +101 -81
- package/dist/core/registry.fallback.json +904 -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 +353 -656
- 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 +38 -32
- 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
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flags / preset / --yes → project config.
|
|
3
|
+
*
|
|
4
|
+
* Stack values are validated against the active registry field by field
|
|
5
|
+
* (monorepo → frontend → backend → database → orm); a field with a single
|
|
6
|
+
* remaining option is picked automatically. When values are missing, an
|
|
7
|
+
* interactive terminal gets the wizard (pre-filled with the given flags);
|
|
8
|
+
* anything else gets "Missing required options" and exit 1.
|
|
9
|
+
*/
|
|
10
|
+
import { AUTH_STRATEGIES, PACKAGE_MANAGERS, PackageManagerSchema, ProjectConfigSchema, } from '../types/index.js';
|
|
11
|
+
import { STACK_FIELDS, availableOptions, autoPick, labelFor, normalizeValue, } from '../core/stack.js';
|
|
12
|
+
import { createCustomTemplate, getOfficialTemplates, } from '../core/template-registry.js';
|
|
13
|
+
import { getContributedByUUID } from '../core/template-list.js';
|
|
14
|
+
import { getBuiltinPreset, listPresets, loadPreset } from '../core/presets.js';
|
|
15
|
+
import { AUTH_SUPPORT, supportsAuth } from '../core/auth/jwt.js';
|
|
16
|
+
import { isValidUUID, parseTemplateUrl } from '../utils/validation.js';
|
|
17
|
+
import { UsageError, warn } from './output.js';
|
|
18
|
+
/** Prompts only when both stdin and stdout are terminals and CI is not set. */
|
|
19
|
+
export function isInteractive() {
|
|
20
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY && !process.env.CI);
|
|
21
|
+
}
|
|
22
|
+
/** --yes defaults, in preference order per field (else the first available). */
|
|
23
|
+
export const DEFAULT_PREFERENCE = {
|
|
24
|
+
frontend: 'next.js',
|
|
25
|
+
backend: 'nest.js',
|
|
26
|
+
database: 'postgresql',
|
|
27
|
+
orm: 'prisma',
|
|
28
|
+
};
|
|
29
|
+
export function defaultFor(field, options) {
|
|
30
|
+
const preferred = DEFAULT_PREFERENCE[field];
|
|
31
|
+
return preferred && options.includes(preferred) ? preferred : options[0];
|
|
32
|
+
}
|
|
33
|
+
// ── Removed / ignored flags ───────────────────────────────────────────────────
|
|
34
|
+
export function warnRemovedFlags(flags) {
|
|
35
|
+
if (flags.styling !== undefined) {
|
|
36
|
+
warn('--styling is not available in v3 (all templates use Tailwind CSS); ignoring it.');
|
|
37
|
+
}
|
|
38
|
+
if (flags.apiStyle !== undefined) {
|
|
39
|
+
warn('--api-style is not available in v3 (all templates are REST); ignoring it.');
|
|
40
|
+
}
|
|
41
|
+
if (flags.turbopack !== undefined) {
|
|
42
|
+
const flag = flags.turbopack ? '--turbopack' : '--no-turbopack';
|
|
43
|
+
warn(`${flag} is not available in v3 (Next.js 16 templates already use Turbopack); ignoring it.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// ── Value parsing ─────────────────────────────────────────────────────────────
|
|
47
|
+
export function parsePackageManager(value) {
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
const parsed = PackageManagerSchema.safeParse(value.toLowerCase());
|
|
51
|
+
if (!parsed.success) {
|
|
52
|
+
throw new UsageError(`--package-manager ${value} is not supported`, {
|
|
53
|
+
reason: `Supported: ${PACKAGE_MANAGERS.join(', ')}`,
|
|
54
|
+
fix: '--package-manager npm',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return parsed.data;
|
|
58
|
+
}
|
|
59
|
+
export function parseAuth(value) {
|
|
60
|
+
if (value === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
const v = value.toLowerCase();
|
|
63
|
+
if (v !== 'none' && v !== 'jwt') {
|
|
64
|
+
throw new UsageError(`--auth ${value} is not supported`, {
|
|
65
|
+
reason: `Supported: ${AUTH_STRATEGIES.join(', ')}`,
|
|
66
|
+
fix: '--auth jwt',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return v;
|
|
70
|
+
}
|
|
71
|
+
export function assertAuthSupported(auth, backend) {
|
|
72
|
+
if (auth === 'jwt' && !supportsAuth(backend)) {
|
|
73
|
+
throw new UsageError(`--auth jwt is not available for ${backend ?? 'this template'}`, {
|
|
74
|
+
reason: `JWT auth works with: ${AUTH_SUPPORT.join(', ')}`,
|
|
75
|
+
fix: '--auth none',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate the given stack values field by field. Fields with one remaining
|
|
81
|
+
* option are filled in; with `useDefaults`, so is every other missing field.
|
|
82
|
+
* Throws UsageError for a value in `given` (explicit flags) that is not
|
|
83
|
+
* available. `soft` values (from a preset) are used only when available and
|
|
84
|
+
* are otherwise dropped, as if they had not been given.
|
|
85
|
+
*/
|
|
86
|
+
export function resolveStack(given, templates, useDefaults, soft = {}) {
|
|
87
|
+
const answers = {};
|
|
88
|
+
const missing = [];
|
|
89
|
+
const fromSoft = new Set();
|
|
90
|
+
for (const field of STACK_FIELDS) {
|
|
91
|
+
const options = availableOptions(templates, field, answers);
|
|
92
|
+
const softRaw = soft[field];
|
|
93
|
+
const softValue = softRaw === undefined ? undefined : normalizeValue(field, softRaw);
|
|
94
|
+
if (given[field] === undefined && softValue !== undefined && options.includes(softValue)) {
|
|
95
|
+
answers[field] = softValue;
|
|
96
|
+
fromSoft.add(field);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const raw = given[field];
|
|
100
|
+
if (raw !== undefined) {
|
|
101
|
+
const value = normalizeValue(field, raw);
|
|
102
|
+
if (!options.includes(value))
|
|
103
|
+
throw unavailableError(field, value, options, answers, fromSoft);
|
|
104
|
+
answers[field] = value;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const value = autoPick(options) ?? (useDefaults ? defaultFor(field, options) : undefined);
|
|
108
|
+
if (value !== undefined) {
|
|
109
|
+
answers[field] = value;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Later fields are still filtered by the answers given so far
|
|
113
|
+
missing.push(field);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { stack: answers, missing };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* "No template for Vue + NestJS" / "Vue works with: express" / "Try: --backend express".
|
|
120
|
+
* Without earlier answers: "No template uses --frontend angular" / "Available: ...".
|
|
121
|
+
*/
|
|
122
|
+
function unavailableError(field, value, options, answers, fromSoft) {
|
|
123
|
+
const earlier = STACK_FIELDS.slice(0, STACK_FIELDS.indexOf(field))
|
|
124
|
+
.filter(f => f !== 'monorepo' && answers[f] !== undefined);
|
|
125
|
+
const fix = options[0] ? `--${field} ${options[0]}` : 'create-fs-app list';
|
|
126
|
+
if (earlier.length === 0) {
|
|
127
|
+
return new UsageError(`No template uses --${field} ${value}`, {
|
|
128
|
+
reason: `Available: ${options.join(', ') || '(none)'}`,
|
|
129
|
+
fix,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const labels = earlier.map(f => labelFor(answers[f]));
|
|
133
|
+
const allSoft = earlier.every(f => fromSoft.has(f));
|
|
134
|
+
const who = allSoft
|
|
135
|
+
? `${labels.join(' + ')} (from the preset)`
|
|
136
|
+
: earlier.map((f, i) => `${labels[i]}${fromSoft.has(f) ? ' (from the preset)' : ''}`).join(' + ');
|
|
137
|
+
return new UsageError(`No template for ${[...labels, labelFor(value)].join(' + ')}`, {
|
|
138
|
+
reason: `${who} works with: ${options.join(', ') || '(none)'}`,
|
|
139
|
+
fix,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/** "Missing required options: ..." with the values per flag and the --yes defaults as the fix. */
|
|
143
|
+
export function missingOptionsError(missing, templates, answers) {
|
|
144
|
+
const flags = missing.map(f => `--${f}`);
|
|
145
|
+
const width = Math.max(...flags.map(f => f.length));
|
|
146
|
+
const values = missing.map((field, i) => ` ${flags[i].padEnd(width)} ${availableOptions(templates, field, answers).join(', ')}`);
|
|
147
|
+
const defaults = resolveStack(answers, templates, true).stack;
|
|
148
|
+
return new UsageError(`Missing required options: ${flags.join(', ')}`, {
|
|
149
|
+
reason: ['No terminal to ask in.', ...values].join('\n'),
|
|
150
|
+
fix: missing.map(f => `--${f} ${defaults[f]}`).join(' '),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// ── Create ────────────────────────────────────────────────────────────────────
|
|
154
|
+
async function readPreset(name, readOnly) {
|
|
155
|
+
const preset = getBuiltinPreset(name)
|
|
156
|
+
// loadPreset records lastUsed (a write); --dry-run reads only
|
|
157
|
+
?? (readOnly ? (await listPresets()).find(p => p.name === name) ?? null : await loadPreset(name));
|
|
158
|
+
if (!preset) {
|
|
159
|
+
throw new UsageError(`Preset "${name}" not found`, {
|
|
160
|
+
reason: 'No built-in or saved preset has that name.',
|
|
161
|
+
fix: 'create-fs-app preset list',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return preset.config;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Turn the create command's flags into a config, or into a wizard seed when
|
|
168
|
+
* running interactively with values missing.
|
|
169
|
+
*/
|
|
170
|
+
export async function resolveCreate(name, flags, ctx) {
|
|
171
|
+
const base = flags.preset ? await readPreset(flags.preset, flags.dryRun === true) : {};
|
|
172
|
+
const explicitAuth = parseAuth(flags.auth);
|
|
173
|
+
const given = {
|
|
174
|
+
packageManager: parsePackageManager(flags.packageManager) ?? base.packageManager,
|
|
175
|
+
eslint: flags.eslint ?? base.eslint,
|
|
176
|
+
prettier: flags.prettier ?? base.prettier,
|
|
177
|
+
docker: flags.docker ?? base.docker,
|
|
178
|
+
ci: flags.ci ?? base.ci,
|
|
179
|
+
auth: explicitAuth ?? base.auth,
|
|
180
|
+
git: ctx.gitGiven ? flags.git : base.git,
|
|
181
|
+
install: ctx.installGiven ? flags.install : base.install,
|
|
182
|
+
};
|
|
183
|
+
const requireName = () => {
|
|
184
|
+
if (!name) {
|
|
185
|
+
throw new UsageError('Project name is required', {
|
|
186
|
+
reason: ctx.interactive
|
|
187
|
+
? 'With --yes the name must be the first argument.'
|
|
188
|
+
: 'Without a terminal the name must be the first argument.',
|
|
189
|
+
fix: 'create-fs-app my-app <flags>',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return name;
|
|
193
|
+
};
|
|
194
|
+
// Preset auth is soft like preset stack values (D27); an explicit --auth jwt is not
|
|
195
|
+
const checkAuth = (backend) => {
|
|
196
|
+
if (explicitAuth === undefined && given.auth === 'jwt' && !supportsAuth(backend)) {
|
|
197
|
+
given.auth = 'none';
|
|
198
|
+
warn(`The preset's JWT auth is not available for ${backend} (JWT works with ${AUTH_SUPPORT.join(', ')}); continuing without auth.`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
assertAuthSupported(given.auth, backend);
|
|
202
|
+
};
|
|
203
|
+
// --template-url: custom template, only generic customization (D19)
|
|
204
|
+
if (flags.templateUrl) {
|
|
205
|
+
const parsed = parseTemplateUrl(flags.templateUrl);
|
|
206
|
+
if (!parsed.valid || !parsed.parsed) {
|
|
207
|
+
const [what = 'Invalid --template-url', ...rest] = (parsed.error ?? '').split('\n');
|
|
208
|
+
throw new UsageError(what || 'Invalid --template-url', {
|
|
209
|
+
reason: rest.map(line => line.trim()).join('\n') || undefined,
|
|
210
|
+
fix: '--template-url https://github.com/<owner>/<repo>',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const ignored = [
|
|
214
|
+
given.auth === 'jwt' && '--auth jwt',
|
|
215
|
+
flags.docker === false && '--no-docker',
|
|
216
|
+
flags.eslint === false && '--no-eslint',
|
|
217
|
+
flags.prettier === false && '--no-prettier',
|
|
218
|
+
].filter((v) => Boolean(v));
|
|
219
|
+
if (ignored.length > 0) {
|
|
220
|
+
warn(`${ignored.join(', ')} ${ignored.length === 1 ? 'is' : 'are'} not applied to custom templates (--template-url); ignoring.`);
|
|
221
|
+
}
|
|
222
|
+
const template = createCustomTemplate(parsed.parsed.repoUrl, parsed.parsed.branch, parsed.parsed.subfolder);
|
|
223
|
+
const config = ProjectConfigSchema.parse({
|
|
224
|
+
...given, name: requireName(), stack: undefined, auth: 'none', eslint: true, prettier: true, docker: true,
|
|
225
|
+
});
|
|
226
|
+
return { kind: 'custom', template, config };
|
|
227
|
+
}
|
|
228
|
+
// --template <uuid>: contributed template
|
|
229
|
+
if (flags.template) {
|
|
230
|
+
if (!isValidUUID(flags.template)) {
|
|
231
|
+
throw new UsageError('--template needs a contributed template UUID', { fix: 'create-fs-app list --contributed' });
|
|
232
|
+
}
|
|
233
|
+
const match = getContributedByUUID(flags.template);
|
|
234
|
+
if (!match) {
|
|
235
|
+
throw new UsageError(`No contributed template has UUID "${flags.template}"`, { fix: 'create-fs-app list --contributed' });
|
|
236
|
+
}
|
|
237
|
+
checkAuth(match.metadata.stack.backend);
|
|
238
|
+
const config = ProjectConfigSchema.parse({ ...given, name: requireName(), stack: match.metadata.stack });
|
|
239
|
+
return { kind: 'contributed', template: match.metadata, config };
|
|
240
|
+
}
|
|
241
|
+
// Official template from stack flags / preset / defaults
|
|
242
|
+
const templates = getOfficialTemplates();
|
|
243
|
+
const useDefaults = flags.yes === true;
|
|
244
|
+
// Preset stack values are soft: one that no longer fits the flags is dropped
|
|
245
|
+
const { stack, missing } = resolveStack({
|
|
246
|
+
monorepo: flags.monorepo,
|
|
247
|
+
frontend: flags.frontend,
|
|
248
|
+
backend: flags.backend,
|
|
249
|
+
database: flags.database,
|
|
250
|
+
orm: flags.orm,
|
|
251
|
+
}, templates, useDefaults, base.stack ?? {});
|
|
252
|
+
if (stack.backend !== undefined)
|
|
253
|
+
checkAuth(stack.backend);
|
|
254
|
+
const canAsk = ctx.interactive && !useDefaults;
|
|
255
|
+
if ((missing.length > 0 || !name) && canAsk) {
|
|
256
|
+
return { kind: 'official', wizard: { name, stack, given } };
|
|
257
|
+
}
|
|
258
|
+
const projectName = requireName();
|
|
259
|
+
if (missing.length > 0) {
|
|
260
|
+
throw missingOptionsError(missing, templates, stack);
|
|
261
|
+
}
|
|
262
|
+
const config = ProjectConfigSchema.parse({ ...given, name: projectName, stack: stack });
|
|
263
|
+
return { kind: 'official', config };
|
|
264
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One error format for the whole CLI:
|
|
3
|
+
*
|
|
4
|
+
* ✗ No template for Vue + NestJS
|
|
5
|
+
* Vue works with: express
|
|
6
|
+
* Try: --backend express
|
|
7
|
+
*
|
|
8
|
+
* Line 1 is what failed, then why (any number of lines), then one command or
|
|
9
|
+
* flag set to try. Errors without details print line 1 only.
|
|
10
|
+
*/
|
|
11
|
+
import { CliError } from '../../utils/cli-error.js';
|
|
12
|
+
export function renderError(error, theme) {
|
|
13
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
14
|
+
const [what = '', ...more] = message.split('\n');
|
|
15
|
+
const lines = [theme.error(`${theme.glyphs.cross} ${what}`)];
|
|
16
|
+
for (const line of more)
|
|
17
|
+
lines.push(line.trim() === '' ? '' : ` ${line}`);
|
|
18
|
+
if (error instanceof CliError) {
|
|
19
|
+
if (error.reason) {
|
|
20
|
+
for (const line of error.reason.split('\n'))
|
|
21
|
+
lines.push(` ${line}`);
|
|
22
|
+
}
|
|
23
|
+
if (error.fix)
|
|
24
|
+
lines.push(` ${theme.dim('Try:')} ${theme.accent(error.fix)}`);
|
|
25
|
+
}
|
|
26
|
+
return lines.join('\n');
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root `--help`: usage, description, options grouped as Stack / Output /
|
|
3
|
+
* Templates, Commands (subcommands, --version, --help) and three examples.
|
|
4
|
+
* Groups come from commander's Option.helpGroup(); subcommand help keeps
|
|
5
|
+
* commander's default layout.
|
|
6
|
+
*/
|
|
7
|
+
export const OPTION_GROUPS = ['Stack', 'Output', 'Templates'];
|
|
8
|
+
export const COMMANDS_GROUP = 'Commands';
|
|
9
|
+
export const HELP_EXAMPLES = [
|
|
10
|
+
'npx create-fs-app my-app',
|
|
11
|
+
'npx create-fs-app my-app --frontend next.js --backend hono --yes',
|
|
12
|
+
'npx create-fs-app my-app --preset saas-starter --auth jwt --dry-run',
|
|
13
|
+
];
|
|
14
|
+
export function formatRootHelp(cmd, helper, theme, width) {
|
|
15
|
+
helper.helpWidth = width; // formatItem wraps descriptions to this width
|
|
16
|
+
const options = helper.visibleOptions(cmd);
|
|
17
|
+
const commands = helper.visibleCommands(cmd);
|
|
18
|
+
const inGroup = (group) => options.filter((o) => o.helpGroupHeading === group);
|
|
19
|
+
const optionWidth = Math.max(0, ...OPTION_GROUPS.flatMap(inGroup).map(o => helper.displayWidth(helper.optionTerm(o))));
|
|
20
|
+
const commandItems = [
|
|
21
|
+
...commands.map((c) => [helper.subcommandTerm(c), helper.subcommandDescription(c)]),
|
|
22
|
+
...inGroup(COMMANDS_GROUP).map((o) => [helper.optionTerm(o), helper.optionDescription(o)]),
|
|
23
|
+
];
|
|
24
|
+
const commandWidth = Math.max(0, ...commandItems.map(([term]) => helper.displayWidth(term)));
|
|
25
|
+
const out = [`${theme.bold('Usage:')} ${helper.commandUsage(cmd)}`, ''];
|
|
26
|
+
const description = helper.commandDescription(cmd);
|
|
27
|
+
if (description)
|
|
28
|
+
out.push(helper.boxWrap(description, width), '');
|
|
29
|
+
for (const group of OPTION_GROUPS) {
|
|
30
|
+
const items = inGroup(group);
|
|
31
|
+
if (items.length === 0)
|
|
32
|
+
continue;
|
|
33
|
+
out.push(theme.bold(group));
|
|
34
|
+
for (const o of items)
|
|
35
|
+
out.push(helper.formatItem(helper.optionTerm(o), optionWidth, helper.optionDescription(o), helper));
|
|
36
|
+
out.push('');
|
|
37
|
+
}
|
|
38
|
+
out.push(theme.bold(COMMANDS_GROUP));
|
|
39
|
+
for (const [term, desc] of commandItems)
|
|
40
|
+
out.push(helper.formatItem(term, commandWidth, desc, helper));
|
|
41
|
+
out.push('', theme.bold('Examples'), ...HELP_EXAMPLES.map(e => ` ${theme.accent(e)}`), '');
|
|
42
|
+
return out.join('\n');
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Wizard option hints, taken from the registry layer data. */
|
|
2
|
+
import { STACK_FIELDS } from '../../core/stack.js';
|
|
3
|
+
/**
|
|
4
|
+
* Hint for `value` of `field`, from the first template with that value that
|
|
5
|
+
* matches `answers` (the earlier fields): "v16 · App Router"; databases add
|
|
6
|
+
* "no Docker" when the template has no Docker files.
|
|
7
|
+
*/
|
|
8
|
+
export function optionHint(templates, field, value, answers = {}, dot = '·') {
|
|
9
|
+
const matches = (t) => t.stack[field] === value;
|
|
10
|
+
const before = STACK_FIELDS.slice(0, STACK_FIELDS.indexOf(field));
|
|
11
|
+
const earlier = (t) => before.every(f => answers[f] === undefined || t.stack[f] === answers[f]);
|
|
12
|
+
const template = templates.find(t => matches(t) && earlier(t)) ?? templates.find(matches);
|
|
13
|
+
if (!template || field === 'monorepo')
|
|
14
|
+
return undefined;
|
|
15
|
+
const layer = template.layers?.[field];
|
|
16
|
+
const parts = [
|
|
17
|
+
layer?.version && `v${layer.version}`,
|
|
18
|
+
layer?.notes?.[0],
|
|
19
|
+
field === 'database' && !template.supports.docker && 'no Docker',
|
|
20
|
+
].filter((v) => Boolean(v));
|
|
21
|
+
return parts.length > 0 ? parts.join(` ${dot} `) : undefined;
|
|
22
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The layer log: where each layer of a template lives and what it runs.
|
|
3
|
+
*
|
|
4
|
+
* <title> <monorepo> · <pm> · node ≥<node> (facts on a second line if too wide)
|
|
5
|
+
* ├─ <frontend path> <name> <version> :<port> <notes · …>
|
|
6
|
+
* ├─ packages/* <notes · …>
|
|
7
|
+
* ├─ <backend path> <name> <version> :<port> <notes · …>
|
|
8
|
+
* ├─ <orm path> <name> <version> <notes · …>
|
|
9
|
+
* └─ database <name> <version> :<port> <notes · …>
|
|
10
|
+
*
|
|
11
|
+
* Every fact comes from the registry (template.layers / template.node);
|
|
12
|
+
* templates without layer data fall back to their stack labels.
|
|
13
|
+
*/
|
|
14
|
+
import { labelFor } from '../../core/stack.js';
|
|
15
|
+
import { visibleWidth } from '../../utils/theme.js';
|
|
16
|
+
import { pad, truncate } from './text.js';
|
|
17
|
+
const LAYER_ORDER = ['frontend', 'packages', 'backend', 'orm', 'database'];
|
|
18
|
+
function fromLayer(layer, data) {
|
|
19
|
+
const name = [data.name, data.version].filter(Boolean).join(' ');
|
|
20
|
+
return {
|
|
21
|
+
layer,
|
|
22
|
+
path: layer === 'database' ? 'database' : data.path ?? layer,
|
|
23
|
+
name: layer === 'packages' ? '' : name,
|
|
24
|
+
port: data.port ? `:${data.port}` : '',
|
|
25
|
+
notes: [...(data.notes ?? [])],
|
|
26
|
+
span: layer === 'packages',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Rows for `template`, with the project-only notes (JWT /auth, docker compose). */
|
|
30
|
+
export function layerRows(template, project = {}) {
|
|
31
|
+
let rows;
|
|
32
|
+
if (template.layers) {
|
|
33
|
+
const layers = template.layers;
|
|
34
|
+
rows = LAYER_ORDER.flatMap(key => (layers[key] ? [fromLayer(key, layers[key])] : []));
|
|
35
|
+
}
|
|
36
|
+
else if (template.stack) {
|
|
37
|
+
const stack = template.stack;
|
|
38
|
+
rows = ['frontend', 'backend', 'orm', 'database'].map(key => ({
|
|
39
|
+
layer: key, path: key, name: labelFor(stack[key]), port: '', notes: [],
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return [{ layer: 'custom', path: 'custom template', name: '', port: '', notes: [template.url ?? 'unknown'], span: true }];
|
|
44
|
+
}
|
|
45
|
+
for (const row of rows) {
|
|
46
|
+
if (row.layer === 'backend' && project.auth === 'jwt')
|
|
47
|
+
row.notes.push('JWT /auth');
|
|
48
|
+
if (row.layer === 'database' && template.supports.docker && project.docker !== false)
|
|
49
|
+
row.notes.push('docker compose');
|
|
50
|
+
}
|
|
51
|
+
return rows;
|
|
52
|
+
}
|
|
53
|
+
/** ">=20.19.0" → "≥20.19" (ASCII: ">=20.19"); other ranges are shown as they are. */
|
|
54
|
+
export function nodeRange(range, ge) {
|
|
55
|
+
const match = range.trim().match(/^>=\s*(\d+(?:\.\d+)*)$/);
|
|
56
|
+
if (!match)
|
|
57
|
+
return range;
|
|
58
|
+
return ge + match[1].replace(/(\.0)+$/, '');
|
|
59
|
+
}
|
|
60
|
+
function styleFor(layer, theme) {
|
|
61
|
+
switch (layer) {
|
|
62
|
+
case 'frontend': return theme.frontend;
|
|
63
|
+
case 'backend': return theme.backend;
|
|
64
|
+
case 'orm':
|
|
65
|
+
case 'database': return theme.data;
|
|
66
|
+
default: return (text) => text;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function renderLayerLog(input, theme, width = 80) {
|
|
70
|
+
const { glyphs } = theme;
|
|
71
|
+
const { template } = input;
|
|
72
|
+
const sep = ` ${glyphs.dot} `;
|
|
73
|
+
const facts = [
|
|
74
|
+
template.stack ? labelFor(template.stack.monorepo) : undefined,
|
|
75
|
+
input.packageManager,
|
|
76
|
+
template.node ? `node ${nodeRange(template.node, glyphs.ge)}` : undefined,
|
|
77
|
+
].filter((v) => Boolean(v));
|
|
78
|
+
const headerPlain = ` ${input.title}${facts.length ? ` ${facts.join(sep)}` : ''}`;
|
|
79
|
+
// Too wide for one line (long title or Node range): the facts go on their own line
|
|
80
|
+
const header = visibleWidth(headerPlain) <= width
|
|
81
|
+
? ` ${theme.bold(input.title)}${facts.length ? ` ${theme.dim(facts.join(sep))}` : ''}`
|
|
82
|
+
: [
|
|
83
|
+
` ${theme.bold(truncate(input.title, Math.max(1, width - 2), glyphs.ellipsis))}`,
|
|
84
|
+
...(facts.length ? [` ${theme.dim(truncate(facts.join(sep), Math.max(1, width - 2), glyphs.ellipsis))}`] : []),
|
|
85
|
+
].join('\n');
|
|
86
|
+
const rows = layerRows(template, { docker: input.docker, auth: input.auth });
|
|
87
|
+
const columns = rows.filter(r => !r.span);
|
|
88
|
+
const pathWidth = Math.max(...rows.map(r => visibleWidth(r.path)));
|
|
89
|
+
const nameWidth = Math.max(0, ...columns.map(r => visibleWidth(r.name)));
|
|
90
|
+
const portWidth = Math.max(0, ...columns.map(r => visibleWidth(r.port)));
|
|
91
|
+
const lines = rows.map((row, i) => {
|
|
92
|
+
const glyph = i === rows.length - 1 ? glyphs.corner : glyphs.tee;
|
|
93
|
+
const lead = ` ${glyph} `;
|
|
94
|
+
const cells = [
|
|
95
|
+
{ plain: pad(row.path, pathWidth), styled: pad(styleFor(row.layer, theme)(row.path), pathWidth) },
|
|
96
|
+
];
|
|
97
|
+
if (!row.span) {
|
|
98
|
+
if (nameWidth > 0)
|
|
99
|
+
cells.push({ plain: pad(row.name, nameWidth), styled: pad(row.name, nameWidth) });
|
|
100
|
+
if (portWidth > 0)
|
|
101
|
+
cells.push({ plain: pad(row.port, portWidth), styled: pad(row.port, portWidth) });
|
|
102
|
+
}
|
|
103
|
+
const fixed = lead + cells.map(c => c.plain).join(' ');
|
|
104
|
+
const budget = width - visibleWidth(fixed) - 2;
|
|
105
|
+
const notes = row.notes.length > 0 && budget > 0
|
|
106
|
+
? truncate(row.notes.join(sep), budget, glyphs.ellipsis)
|
|
107
|
+
: '';
|
|
108
|
+
const styled = theme.dim(lead.trimEnd()) + ' ' + cells.map(c => c.styled).join(' ')
|
|
109
|
+
+ (notes ? ` ${theme.dim(notes)}` : '');
|
|
110
|
+
return notes ? styled : styled.trimEnd();
|
|
111
|
+
});
|
|
112
|
+
return [header, ...lines].join('\n');
|
|
113
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `list` and `info` screens. Search and name resolution stay in
|
|
3
|
+
* core/template-list.ts; these functions only render.
|
|
4
|
+
*/
|
|
5
|
+
import { describeStack, labelFor } from '../../core/stack.js';
|
|
6
|
+
import { supportsAuth } from '../../core/auth/jwt.js';
|
|
7
|
+
import { renderLayerLog } from './layer-log.js';
|
|
8
|
+
import { pad, truncate, wrapCommand, wrapText } from './text.js';
|
|
9
|
+
/** Key without the monorepo prefix: "turborepo-nextjs-…" → "nextjs-…" (still unique for `info`). */
|
|
10
|
+
export function shortKey({ key, metadata }) {
|
|
11
|
+
const prefix = `${metadata.stack.monorepo}-`;
|
|
12
|
+
return key.startsWith(prefix) ? key.slice(prefix.length) : key;
|
|
13
|
+
}
|
|
14
|
+
function backendLabel({ metadata }) {
|
|
15
|
+
return metadata.layers?.backend.name ?? labelFor(metadata.stack.backend);
|
|
16
|
+
}
|
|
17
|
+
function dataLabel({ metadata }, dot) {
|
|
18
|
+
const database = metadata.layers?.database.name ?? labelFor(metadata.stack.database);
|
|
19
|
+
const orm = metadata.layers?.orm.name ?? labelFor(metadata.stack.orm);
|
|
20
|
+
return `${database} ${dot} ${orm}`;
|
|
21
|
+
}
|
|
22
|
+
function notesFor({ metadata }) {
|
|
23
|
+
return [
|
|
24
|
+
!metadata.supports.docker && 'no Docker',
|
|
25
|
+
supportsAuth(metadata.stack.backend) && 'JWT available',
|
|
26
|
+
].filter((v) => Boolean(v));
|
|
27
|
+
}
|
|
28
|
+
const CREATE_EXAMPLES = [
|
|
29
|
+
'npx create-fs-app my-app',
|
|
30
|
+
'npx create-fs-app my-app --frontend next.js --backend nest.js --database postgresql',
|
|
31
|
+
];
|
|
32
|
+
export function renderTemplateList(input, theme, width = 80) {
|
|
33
|
+
const { glyphs } = theme;
|
|
34
|
+
const { official, contributed, search } = input;
|
|
35
|
+
const shown = official.length + contributed.length;
|
|
36
|
+
if (shown === 0) {
|
|
37
|
+
const hint = search
|
|
38
|
+
? `No templates match "${search}".`
|
|
39
|
+
: input.contributedOnly ? 'No contributed templates yet.' : 'No official templates found.';
|
|
40
|
+
return `${theme.warn(hint)} Run ${theme.accent('create-fs-app list --all')} to see everything.`;
|
|
41
|
+
}
|
|
42
|
+
const fit = (line) => truncate(line, width, glyphs.ellipsis);
|
|
43
|
+
const out = [
|
|
44
|
+
theme.bold(`Templates (${shown} of ${input.totalAll})`) + (search ? theme.dim(` search: "${search}"`) : ''),
|
|
45
|
+
];
|
|
46
|
+
if (official.length > 0) {
|
|
47
|
+
const backendWidth = Math.max('backend'.length, ...official.map(t => backendLabel(t).length));
|
|
48
|
+
const dataWidth = Math.max('data'.length, ...official.map(t => [...dataLabel(t, glyphs.dot)].length));
|
|
49
|
+
out.push('', theme.dim(` ${pad('backend', backendWidth)} ${pad('data', dataWidth)} notes`));
|
|
50
|
+
const groups = new Map();
|
|
51
|
+
for (const t of official) {
|
|
52
|
+
const label = t.metadata.layers?.frontend.name ?? labelFor(t.metadata.stack.frontend);
|
|
53
|
+
groups.set(label, [...(groups.get(label) ?? []), t]);
|
|
54
|
+
}
|
|
55
|
+
for (const [label, templates] of groups) {
|
|
56
|
+
out.push(theme.frontend(theme.bold(label)));
|
|
57
|
+
for (const t of templates) {
|
|
58
|
+
const notes = notesFor(t).join(` ${glyphs.dot} `);
|
|
59
|
+
const line = ` ${pad(backendLabel(t), backendWidth)} ${pad(dataLabel(t, glyphs.dot), dataWidth)} ${notes}`.trimEnd();
|
|
60
|
+
const plain = fit(line);
|
|
61
|
+
// style the cells only when nothing was cut
|
|
62
|
+
out.push(plain === line
|
|
63
|
+
? ` ${pad(theme.backend(backendLabel(t)), backendWidth)} ${notes
|
|
64
|
+
? `${pad(theme.data(dataLabel(t, glyphs.dot)), dataWidth)} ${theme.dim(notes)}`
|
|
65
|
+
: theme.data(dataLabel(t, glyphs.dot))}`
|
|
66
|
+
: plain);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (contributed.length > 0) {
|
|
71
|
+
out.push('', theme.warn(theme.bold('Contributed')));
|
|
72
|
+
for (const { key, metadata } of contributed) {
|
|
73
|
+
const by = metadata.contributor ? ` by @${metadata.contributor.github}` : '';
|
|
74
|
+
out.push(` ${theme.bold(fit(key))}${theme.dim(by)}`);
|
|
75
|
+
out.push(fit(` ${describeStack(metadata.stack)}`));
|
|
76
|
+
out.push(theme.dim(fit(` --template ${metadata.id ?? '(no id)'}`)));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const first = official[0] ?? contributed[0];
|
|
80
|
+
out.push('', `${theme.dim('Details:')} ${theme.accent(`create-fs-app info ${shortKey(first)}`)}`, theme.dim('Create a project:'), ...CREATE_EXAMPLES.map(cmd => ` ${theme.accent(fitCommand(cmd, width - 2))}`), ` ${theme.accent('npx create-fs-app my-app --template <uuid>')} ${theme.dim('(contributed)')}`);
|
|
81
|
+
return out.join('\n');
|
|
82
|
+
}
|
|
83
|
+
/** Drop trailing "--flag value" pairs until the command fits. */
|
|
84
|
+
function fitCommand(command, width) {
|
|
85
|
+
const parts = command.split(/ (?=--)/);
|
|
86
|
+
while (parts.length > 1 && [...parts.join(' ')].length > width)
|
|
87
|
+
parts.pop();
|
|
88
|
+
return parts.join(' ');
|
|
89
|
+
}
|
|
90
|
+
/** `info`: key, kind, description, layer log, features and the command that creates it. */
|
|
91
|
+
export function renderTemplateInfo({ key, metadata }, theme, width = 80) {
|
|
92
|
+
const { glyphs } = theme;
|
|
93
|
+
const s = metadata.stack;
|
|
94
|
+
const kind = metadata.kind === 'official' ? theme.success('official') : theme.warn('contributed');
|
|
95
|
+
const out = [
|
|
96
|
+
`${theme.bold(truncate(key, width - 13, glyphs.ellipsis))} ${kind}`,
|
|
97
|
+
...wrapText(metadata.description, width),
|
|
98
|
+
];
|
|
99
|
+
if (metadata.id)
|
|
100
|
+
out.push(theme.dim(`ID: ${metadata.id}`));
|
|
101
|
+
if (metadata.contributor) {
|
|
102
|
+
out.push(...wrapText(`By: @${metadata.contributor.github} (${metadata.contributor.url})`, width).map(l => theme.dim(l)));
|
|
103
|
+
}
|
|
104
|
+
out.push('', renderLayerLog({ title: key, template: metadata }, theme, width), '');
|
|
105
|
+
for (const feature of metadata.features) {
|
|
106
|
+
out.push(...wrapText(feature, width - 4).map((l, i) => (i ? ` ${l}` : ` ${theme.success(glyphs.check)} ${l}`)));
|
|
107
|
+
}
|
|
108
|
+
if (!metadata.supports.docker)
|
|
109
|
+
out.push(theme.dim(' (no Docker files)'));
|
|
110
|
+
const command = metadata.kind === 'official'
|
|
111
|
+
? `npx create-fs-app my-app --frontend ${s.frontend} --backend ${s.backend} --database ${s.database} --orm ${s.orm}`
|
|
112
|
+
: `npx create-fs-app my-app --template ${metadata.id ?? key}`;
|
|
113
|
+
out.push('', theme.dim('Create it:'), ...wrapCommand(command, width).map(l => theme.accent(l)));
|
|
114
|
+
return out.join('\n');
|
|
115
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Plain-text layout helpers for the renderers (inputs without ANSI codes unless noted). */
|
|
2
|
+
import { visibleWidth } from '../../utils/theme.js';
|
|
3
|
+
/** Pad a (possibly styled) string to `width` visible columns. */
|
|
4
|
+
export function pad(text, width) {
|
|
5
|
+
return text + ' '.repeat(Math.max(0, width - visibleWidth(text)));
|
|
6
|
+
}
|
|
7
|
+
/** Cut plain `text` to `width` columns, ending with `ellipsis` when cut. */
|
|
8
|
+
export function truncate(text, width, ellipsis) {
|
|
9
|
+
const chars = [...text];
|
|
10
|
+
if (chars.length <= width)
|
|
11
|
+
return text;
|
|
12
|
+
if (width <= ellipsis.length)
|
|
13
|
+
return ellipsis.slice(0, Math.max(0, width));
|
|
14
|
+
return chars.slice(0, width - ellipsis.length).join('').trimEnd() + ellipsis;
|
|
15
|
+
}
|
|
16
|
+
/** Word-wrap plain `text` to lines of at most `width` columns (long words are kept whole). */
|
|
17
|
+
export function wrapText(text, width) {
|
|
18
|
+
const lines = [];
|
|
19
|
+
for (const paragraph of text.split('\n')) {
|
|
20
|
+
let line = '';
|
|
21
|
+
for (const word of paragraph.split(/\s+/).filter(Boolean)) {
|
|
22
|
+
if (line && [...line].length + 1 + [...word].length > width) {
|
|
23
|
+
lines.push(line);
|
|
24
|
+
line = word;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
line = line ? `${line} ${word}` : word;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
lines.push(line);
|
|
31
|
+
}
|
|
32
|
+
return lines;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Break a shell command before ` --flag` so each line fits `width` after
|
|
36
|
+
* `indent`; continued lines end with ` \` and get two more spaces.
|
|
37
|
+
*/
|
|
38
|
+
export function wrapCommand(command, width, indent = ' ') {
|
|
39
|
+
const parts = command.split(/ (?=--?\w)/);
|
|
40
|
+
const lines = [];
|
|
41
|
+
let line = '';
|
|
42
|
+
for (const part of parts) {
|
|
43
|
+
const prefix = lines.length === 0 ? indent : `${indent} `;
|
|
44
|
+
const candidate = line ? `${line} ${part}` : part;
|
|
45
|
+
// room for " \" on a line that continues
|
|
46
|
+
if (line && visibleWidth(prefix + candidate) + 2 > width) {
|
|
47
|
+
lines.push(`${prefix}${line} \\`);
|
|
48
|
+
line = part;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
line = candidate;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
lines.push(`${lines.length === 0 ? indent : `${indent} `}${line}`);
|
|
55
|
+
return lines;
|
|
56
|
+
}
|