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
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Template listing, search, and selection utilities.
|
|
3
3
|
*
|
|
4
|
-
* Official templates → shown by default in `
|
|
5
|
-
* Contributed templates → shown with `
|
|
4
|
+
* Official templates → shown by default in `create-fs-app list`; selected by wizard/--yes/stack flags
|
|
5
|
+
* Contributed templates → shown with `list --contributed`; selected only via `--template <uuid>`
|
|
6
6
|
*/
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import Table from 'cli-table3';
|
|
9
|
-
import boxen from 'boxen';
|
|
10
7
|
import { listOfficialTemplates, listContributedTemplates, } from './template-registry.js';
|
|
11
|
-
// ──
|
|
12
|
-
function applySearch(templates, search) {
|
|
8
|
+
// ── Search ──────────────────────────────────────────────────────────────────
|
|
9
|
+
export function applySearch(templates, search) {
|
|
13
10
|
if (!search)
|
|
14
11
|
return templates;
|
|
15
12
|
const q = search.toLowerCase();
|
|
16
13
|
return templates.filter(({ key, metadata }) => key.toLowerCase().includes(q) ||
|
|
17
14
|
metadata.description.toLowerCase().includes(q) ||
|
|
18
15
|
metadata.features.some(f => f.toLowerCase().includes(q)) ||
|
|
16
|
+
Object.values(metadata.stack).some(v => v.includes(q)) ||
|
|
19
17
|
(metadata.contributor?.github.toLowerCase().includes(q) ?? false));
|
|
20
18
|
}
|
|
21
19
|
function resolveFrom(templates, name) {
|
|
@@ -33,140 +31,29 @@ function resolveFrom(templates, name) {
|
|
|
33
31
|
return { match: matches[0] };
|
|
34
32
|
return { ambiguous: matches };
|
|
35
33
|
}
|
|
36
|
-
// ──
|
|
37
|
-
|
|
34
|
+
// ── Listing ───────────────────────────────────────────────────────────────────
|
|
35
|
+
/** The templates `list` shows for `opts` (rendering lives in src/cli/ui/list.ts). */
|
|
36
|
+
export function listTemplates(opts = {}) {
|
|
38
37
|
const official = listOfficialTemplates();
|
|
39
38
|
const contributed = listContributedTemplates();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
let officialFiltered = showOfficial ? applySearch(official, opts.search) : [];
|
|
48
|
-
let contributedFiltered = showContributed ? applySearch(contributed, opts.search) : [];
|
|
49
|
-
const totalShown = officialFiltered.length + contributedFiltered.length;
|
|
50
|
-
const totalAll = official.length + contributed.length;
|
|
51
|
-
// ── Empty states ──────────────────────────────────────────────────────────
|
|
52
|
-
if (totalAll === 0) {
|
|
53
|
-
console.log(boxen(chalk.yellow.bold('⚠️ No templates available yet\n\n') +
|
|
54
|
-
chalk.white('Templates are currently being created.\n') +
|
|
55
|
-
chalk.cyan('Visit: ') + chalk.underline.cyan('https://github.com/Om-jannu/create-fs-app-templates'), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'yellow' }));
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (totalShown === 0) {
|
|
59
|
-
const hint = opts.search
|
|
60
|
-
? `No templates match "${opts.search}".`
|
|
61
|
-
: opts.contributed
|
|
62
|
-
? 'No contributed templates yet — be the first!'
|
|
63
|
-
: 'No official templates found.';
|
|
64
|
-
console.log(boxen(chalk.yellow(`⚠️ ${hint}\n\n`) +
|
|
65
|
-
chalk.gray('Run ') + chalk.cyan('create-fs-app list --all') + chalk.gray(' to see everything.'), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'yellow' }));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// ── Header ────────────────────────────────────────────────────────────────
|
|
69
|
-
console.log();
|
|
70
|
-
let heading = chalk.bold.cyan(' 📋 Available Templates');
|
|
71
|
-
if (opts.all)
|
|
72
|
-
heading += chalk.gray(' — all');
|
|
73
|
-
if (opts.contributed)
|
|
74
|
-
heading += chalk.gray(' — contributed');
|
|
75
|
-
if (opts.search)
|
|
76
|
-
heading += chalk.gray(` — search: "${opts.search}"`);
|
|
77
|
-
console.log(heading);
|
|
78
|
-
console.log(chalk.dim(` ${totalShown} of ${totalAll} template${totalAll === 1 ? '' : 's'}`));
|
|
79
|
-
console.log();
|
|
80
|
-
// ── Official section ──────────────────────────────────────────────────────
|
|
81
|
-
if (officialFiltered.length > 0) {
|
|
82
|
-
if (opts.all)
|
|
83
|
-
console.log(chalk.bold.green(' ✦ OFFICIAL'));
|
|
84
|
-
const grouped = officialFiltered.reduce((acc, item) => {
|
|
85
|
-
const mono = item.key.split('-')[0];
|
|
86
|
-
(acc[mono] = acc[mono] ?? []).push(item);
|
|
87
|
-
return acc;
|
|
88
|
-
}, {});
|
|
89
|
-
Object.entries(grouped).forEach(([mono, items]) => {
|
|
90
|
-
if (!opts.all)
|
|
91
|
-
console.log(chalk.bold.green(` ${mono.toUpperCase()}`));
|
|
92
|
-
const table = new Table({
|
|
93
|
-
head: [chalk.cyan.bold('Template Key'), chalk.cyan.bold('Description'), chalk.cyan.bold('Features')],
|
|
94
|
-
style: { head: [], border: ['gray'] },
|
|
95
|
-
colWidths: [50, 38, 30],
|
|
96
|
-
wordWrap: true,
|
|
97
|
-
});
|
|
98
|
-
items.forEach(({ key, metadata }) => {
|
|
99
|
-
table.push([
|
|
100
|
-
chalk.white(key) + '\n' + chalk.green('✦ official'),
|
|
101
|
-
chalk.gray(metadata.description),
|
|
102
|
-
chalk.yellow(metadata.features.slice(0, 3).join(', ')),
|
|
103
|
-
]);
|
|
104
|
-
});
|
|
105
|
-
console.log(table.toString());
|
|
106
|
-
console.log();
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// ── Contributed section ───────────────────────────────────────────────────
|
|
110
|
-
if (contributedFiltered.length > 0) {
|
|
111
|
-
if (opts.all)
|
|
112
|
-
console.log(chalk.bold.yellow(' ◆ CONTRIBUTED'));
|
|
113
|
-
const table = new Table({
|
|
114
|
-
head: [chalk.cyan.bold('Template Key'), chalk.cyan.bold('Description'), chalk.cyan.bold('Contributor')],
|
|
115
|
-
style: { head: [], border: ['gray'] },
|
|
116
|
-
colWidths: [50, 40, 26],
|
|
117
|
-
wordWrap: true,
|
|
118
|
-
});
|
|
119
|
-
contributedFiltered.forEach(({ key, metadata }) => {
|
|
120
|
-
const contrib = metadata.contributor;
|
|
121
|
-
const byLine = contrib
|
|
122
|
-
? chalk.cyan(`@${contrib.github}`) + '\n' + chalk.dim(contrib.repoUrl)
|
|
123
|
-
: chalk.dim('unknown');
|
|
124
|
-
table.push([
|
|
125
|
-
chalk.white(key) + '\n' + chalk.dim(metadata.id ?? 'no-uuid'),
|
|
126
|
-
chalk.gray(metadata.description),
|
|
127
|
-
byLine,
|
|
128
|
-
]);
|
|
129
|
-
});
|
|
130
|
-
console.log(table.toString());
|
|
131
|
-
console.log();
|
|
132
|
-
}
|
|
133
|
-
// ── Usage tip ─────────────────────────────────────────────────────────────
|
|
134
|
-
console.log(boxen(chalk.white.bold('Official templates') + chalk.gray(' (wizard / stack flags):\n') +
|
|
135
|
-
chalk.cyan(' npx create-fs-app my-app\n') +
|
|
136
|
-
chalk.cyan(' npx create-fs-app my-app --frontend next.js --backend nest.js --database postgresql\n\n') +
|
|
137
|
-
chalk.white.bold('Contributed templates') + chalk.gray(' (--template UUID):\n') +
|
|
138
|
-
chalk.cyan(' npx create-fs-app my-app --template <uuid>\n') +
|
|
139
|
-
chalk.cyan(' npx create-fs-app list --contributed # browse & copy UUID\n\n') +
|
|
140
|
-
chalk.white.bold('Filter & search:\n') +
|
|
141
|
-
chalk.cyan(' npx create-fs-app list --contributed\n') +
|
|
142
|
-
chalk.cyan(' npx create-fs-app list --all\n') +
|
|
143
|
-
chalk.cyan(' npx create-fs-app list graphql'), {
|
|
144
|
-
padding: 1,
|
|
145
|
-
margin: { top: 0, bottom: 1, left: 2, right: 2 },
|
|
146
|
-
borderStyle: 'round', borderColor: 'blue',
|
|
147
|
-
title: chalk.bold.blue('💡 Tip'), titleAlignment: 'left',
|
|
148
|
-
}));
|
|
39
|
+
const showOfficial = opts.all || !opts.contributed;
|
|
40
|
+
const showContributed = opts.all || opts.contributed;
|
|
41
|
+
return {
|
|
42
|
+
official: showOfficial ? applySearch(official, opts.search) : [],
|
|
43
|
+
contributed: showContributed ? applySearch(contributed, opts.search) : [],
|
|
44
|
+
totalAll: official.length + contributed.length,
|
|
45
|
+
};
|
|
149
46
|
}
|
|
150
47
|
// ── Resolution functions ──────────────────────────────────────────────────────
|
|
151
|
-
/**
|
|
152
|
-
* Resolve a user-supplied name within the CONTRIBUTED registry only.
|
|
153
|
-
* Used by the --template flag.
|
|
154
|
-
*/
|
|
48
|
+
/** Resolve a user-supplied name within the CONTRIBUTED registry only. */
|
|
155
49
|
export function getContributedByName(name) {
|
|
156
50
|
return resolveFrom(listContributedTemplates(), name);
|
|
157
51
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Resolve a contributed template by its exact UUID v4.
|
|
160
|
-
* Used by --template flag (UUID-only mode).
|
|
161
|
-
*/
|
|
52
|
+
/** Resolve a contributed template by its exact UUID v4 (--template). */
|
|
162
53
|
export function getContributedByUUID(uuid) {
|
|
163
|
-
|
|
164
|
-
return all.find(t => t.metadata.id === uuid) ?? null;
|
|
54
|
+
return listContributedTemplates().find(t => t.metadata.id === uuid) ?? null;
|
|
165
55
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Resolve a user-supplied name within the OFFICIAL registry only.
|
|
168
|
-
* Used by the `info` command when searching official templates.
|
|
169
|
-
*/
|
|
56
|
+
/** Resolve a user-supplied name within the OFFICIAL registry only (`info`). */
|
|
170
57
|
export function getOfficialByName(name) {
|
|
171
58
|
return resolveFrom(listOfficialTemplates(), name);
|
|
172
59
|
}
|
|
@@ -180,12 +67,3 @@ export function getTemplateStats() {
|
|
|
180
67
|
contributed: contributed.length,
|
|
181
68
|
};
|
|
182
69
|
}
|
|
183
|
-
export function displayTemplateStats() {
|
|
184
|
-
const s = getTemplateStats();
|
|
185
|
-
console.log(chalk.bold.cyan('\n📊 Template Statistics\n'));
|
|
186
|
-
console.log(chalk.green(`Total: ${s.total}`));
|
|
187
|
-
console.log(chalk.green(`Official: ${s.official}`));
|
|
188
|
-
console.log(chalk.green(`Contributed: ${s.contributed}`));
|
|
189
|
-
console.log();
|
|
190
|
-
}
|
|
191
|
-
//# sourceMappingURL=template-list.js.map
|
|
@@ -1,230 +1,134 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Template Registry
|
|
3
|
-
* Maps user configuration to template repository URLs
|
|
2
|
+
* Template Registry (format v3)
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The registry lives in templates/registry.json of the create-fs-app repo.
|
|
5
|
+
* Every entry carries a `stack` object; the CLI matches on it (see stack.ts),
|
|
6
|
+
* never by parsing template keys.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Official — maintained by the repo owner; used by the wizard, --yes and
|
|
9
|
+
* the stack flags.
|
|
10
|
+
* Contributed — community variants; only reachable via --template <uuid>.
|
|
11
|
+
*
|
|
12
|
+
* Entry `subfolder` is relative to the registry's `path` (the directory that
|
|
13
|
+
* holds registry.json inside the repo) and defaults to `templates/<key>`.
|
|
13
14
|
*/
|
|
15
|
+
import { readFileSync } from 'fs';
|
|
14
16
|
import path from 'path';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
],
|
|
104
|
-
supports: { eslint: true, prettier: true, docker: true, turbopack: true },
|
|
105
|
-
},
|
|
106
|
-
'turborepo-react-nestjs-postgresql-prisma': {
|
|
107
|
-
id: '8cba60d4-463a-45ef-9bb0-acb0676e04a2',
|
|
108
|
-
url: TEMPLATE_REPO_URL, branch: TEMPLATE_BRANCH,
|
|
109
|
-
subfolder: 'templates/turborepo-react-nestjs-postgresql-prisma',
|
|
110
|
-
description: 'React 19 (Vite) SPA + NestJS 11 REST API + PostgreSQL 16 + Prisma 5',
|
|
111
|
-
features: [
|
|
112
|
-
'Turborepo monorepo',
|
|
113
|
-
'React 19 + Vite — fast HMR, SPA',
|
|
114
|
-
'Tailwind CSS v4 via Vite plugin',
|
|
115
|
-
'NestJS 11 — modular, decorators, DI',
|
|
116
|
-
'Swagger / OpenAPI docs at /api',
|
|
117
|
-
'Prisma 5 ORM + migrations',
|
|
118
|
-
'PostgreSQL 16 via Docker Compose',
|
|
119
|
-
'TypeScript strict — ESLint + Prettier',
|
|
120
|
-
],
|
|
121
|
-
supports: { eslint: true, prettier: true, docker: true, turbopack: false },
|
|
122
|
-
},
|
|
123
|
-
'turborepo-react-express-postgresql-prisma': {
|
|
124
|
-
id: '8aab7d8e-b969-4c88-87ee-48fd343d0af3',
|
|
125
|
-
url: TEMPLATE_REPO_URL, branch: TEMPLATE_BRANCH,
|
|
126
|
-
subfolder: 'templates/turborepo-react-express-postgresql-prisma',
|
|
127
|
-
description: 'React 19 (Vite) SPA + Express 4 REST API + PostgreSQL 16 + Prisma 5',
|
|
128
|
-
features: [
|
|
129
|
-
'Turborepo monorepo',
|
|
130
|
-
'React 19 + Vite — fast HMR, SPA',
|
|
131
|
-
'Tailwind CSS v4 via Vite plugin',
|
|
132
|
-
'Express 4 — lightweight, flexible',
|
|
133
|
-
'Zod request validation',
|
|
134
|
-
'Prisma 5 ORM + migrations',
|
|
135
|
-
'PostgreSQL 16 via Docker Compose',
|
|
136
|
-
'TypeScript strict — ESLint + Prettier',
|
|
137
|
-
],
|
|
138
|
-
supports: { eslint: true, prettier: true, docker: true, turbopack: false },
|
|
139
|
-
},
|
|
140
|
-
'turborepo-react-nestjs-mongodb-mongoose': {
|
|
141
|
-
id: '70ea0b03-bfec-45cf-a99b-a284368d9660',
|
|
142
|
-
url: TEMPLATE_REPO_URL, branch: TEMPLATE_BRANCH,
|
|
143
|
-
subfolder: 'templates/turborepo-react-nestjs-mongodb-mongoose',
|
|
144
|
-
description: 'React 19 (Vite) SPA + NestJS 11 REST API + MongoDB 7 + Mongoose 8',
|
|
145
|
-
features: [
|
|
146
|
-
'Turborepo monorepo',
|
|
147
|
-
'React 19 + Vite — fast HMR, SPA',
|
|
148
|
-
'Tailwind CSS v4 via Vite plugin',
|
|
149
|
-
'NestJS 11 — modular, decorators, DI',
|
|
150
|
-
'Swagger / OpenAPI docs at /api',
|
|
151
|
-
'@nestjs/mongoose — schema decorators',
|
|
152
|
-
'MongoDB 7 via Docker Compose',
|
|
153
|
-
'TypeScript strict — ESLint + Prettier',
|
|
154
|
-
],
|
|
155
|
-
supports: { eslint: true, prettier: true, docker: true, turbopack: false },
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
// ── Active registries ─────────────────────────────────────────────────────────
|
|
159
|
-
let _officialRegistry = { ...TEMPLATE_REGISTRY };
|
|
160
|
-
let _contributedRegistry = {};
|
|
161
|
-
/**
|
|
162
|
-
* Replace both active registries with data fetched from GitHub.
|
|
163
|
-
* Remote official entries are merged over the hardcoded fallback so that
|
|
164
|
-
* hardcoded id values are preserved when the remote omits them.
|
|
165
|
-
*/
|
|
166
|
-
export function setActiveRegistry(remote) {
|
|
167
|
-
// Official: merge remote over hardcoded, preserve id when remote omits it
|
|
168
|
-
const mergedOfficial = { ...TEMPLATE_REGISTRY };
|
|
169
|
-
for (const [key, remoteEntry] of Object.entries(remote.official)) {
|
|
170
|
-
mergedOfficial[key] = {
|
|
171
|
-
...remoteEntry,
|
|
172
|
-
id: remoteEntry.id ?? TEMPLATE_REGISTRY[key]?.id,
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
import { StackSchema } from '../types/index.js';
|
|
19
|
+
// ── Schema ────────────────────────────────────────────────────────────────────
|
|
20
|
+
export const SupportsSchema = z.object({
|
|
21
|
+
eslint: z.boolean(),
|
|
22
|
+
prettier: z.boolean(),
|
|
23
|
+
docker: z.boolean(),
|
|
24
|
+
turbopack: z.boolean(),
|
|
25
|
+
});
|
|
26
|
+
export const ContributorSchema = z.object({
|
|
27
|
+
/** GitHub username, e.g. "johndoe" */
|
|
28
|
+
github: z.string().min(1),
|
|
29
|
+
/** GitHub profile URL */
|
|
30
|
+
url: z.string().min(1),
|
|
31
|
+
/** Repo the template was contributed from (informational) */
|
|
32
|
+
repoUrl: z.string().min(1),
|
|
33
|
+
});
|
|
34
|
+
/** One row of the layer log: where a layer lives and what it runs. */
|
|
35
|
+
export const LayerSchema = z.object({
|
|
36
|
+
path: z.string().min(1).optional(),
|
|
37
|
+
name: z.string().min(1).optional(),
|
|
38
|
+
package: z.string().min(1).optional(),
|
|
39
|
+
version: z.string().min(1).optional(),
|
|
40
|
+
port: z.number().int().positive().optional(),
|
|
41
|
+
notes: z.array(z.string().min(1)).optional(),
|
|
42
|
+
});
|
|
43
|
+
export const LayersSchema = z.object({
|
|
44
|
+
frontend: LayerSchema,
|
|
45
|
+
packages: LayerSchema.optional(),
|
|
46
|
+
backend: LayerSchema,
|
|
47
|
+
orm: LayerSchema,
|
|
48
|
+
database: LayerSchema,
|
|
49
|
+
});
|
|
50
|
+
export const RegistryEntrySchema = z.object({
|
|
51
|
+
id: z.string().optional(),
|
|
52
|
+
description: z.string().min(1),
|
|
53
|
+
features: z.array(z.string()),
|
|
54
|
+
stack: StackSchema,
|
|
55
|
+
supports: SupportsSchema,
|
|
56
|
+
subfolder: z.string().min(1).optional(),
|
|
57
|
+
/** The template's root package.json engines.node (required for official entries by validate-registry). */
|
|
58
|
+
node: z.string().min(1).optional(),
|
|
59
|
+
/** Layer data for the layer log (required for official entries by validate-registry). */
|
|
60
|
+
layers: LayersSchema.optional(),
|
|
61
|
+
});
|
|
62
|
+
export const ContributedEntrySchema = RegistryEntrySchema.extend({
|
|
63
|
+
contributor: ContributorSchema,
|
|
64
|
+
});
|
|
65
|
+
export const RegistrySchema = z.object({
|
|
66
|
+
version: z.literal(3),
|
|
67
|
+
repoUrl: z.string().url(),
|
|
68
|
+
branch: z.string().min(1),
|
|
69
|
+
path: z.string(),
|
|
70
|
+
official: z.record(z.string(), RegistryEntrySchema),
|
|
71
|
+
contributed: z.record(z.string(), ContributedEntrySchema).default({}),
|
|
72
|
+
});
|
|
73
|
+
/** Registry bundled with the CLI (synced from templates/registry.json at build time). */
|
|
74
|
+
// Read as a file: a JSON module import prints an ExperimentalWarning on Node < 20.19.
|
|
75
|
+
// tsconfig "include" lists src/**/*.json so tsc copies it to dist/core/.
|
|
76
|
+
export const FALLBACK_REGISTRY = RegistrySchema.parse(JSON.parse(readFileSync(new URL('./registry.fallback.json', import.meta.url), 'utf-8')));
|
|
77
|
+
/** CFA_TEMPLATES_REF overrides the branch for both the registry and the tarball. */
|
|
78
|
+
export function templatesRefOverride() {
|
|
79
|
+
return process.env.CFA_TEMPLATES_REF?.trim() || undefined;
|
|
80
|
+
}
|
|
81
|
+
export function toTemplates(registry, options = {}) {
|
|
82
|
+
const branch = templatesRefOverride() ?? registry.branch;
|
|
83
|
+
function convert(key, entry, kind) {
|
|
84
|
+
const relative = entry.subfolder ?? `templates/${key}`;
|
|
85
|
+
const base = {
|
|
86
|
+
key,
|
|
87
|
+
kind,
|
|
88
|
+
id: entry.id,
|
|
89
|
+
contributor: entry.contributor,
|
|
90
|
+
description: entry.description,
|
|
91
|
+
features: entry.features,
|
|
92
|
+
supports: entry.supports,
|
|
93
|
+
stack: entry.stack,
|
|
94
|
+
node: entry.node,
|
|
95
|
+
layers: entry.layers,
|
|
96
|
+
};
|
|
97
|
+
if (options.localDir) {
|
|
98
|
+
return { ...base, localPath: path.join(options.localDir, relative) };
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
...base,
|
|
102
|
+
url: registry.repoUrl,
|
|
103
|
+
branch,
|
|
104
|
+
subfolder: path.posix.join(registry.path, relative),
|
|
173
105
|
};
|
|
174
106
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
107
|
+
return {
|
|
108
|
+
official: Object.entries(registry.official).map(([k, e]) => convert(k, e, 'official')),
|
|
109
|
+
contributed: Object.entries(registry.contributed).map(([k, e]) => convert(k, e, 'contributed')),
|
|
110
|
+
};
|
|
178
111
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
export function
|
|
183
|
-
|
|
184
|
-
const frontend = apps.frontend.framework.replace('.', '');
|
|
185
|
-
const backend = apps.backend.framework.replace('.', '');
|
|
186
|
-
const database = apps.backend.database;
|
|
187
|
-
const orm = apps.backend.orm || 'none';
|
|
188
|
-
return `${monorepo}-${frontend}-${backend}-${database}-${orm}`.toLowerCase();
|
|
112
|
+
// ── Active registry ───────────────────────────────────────────────────────────
|
|
113
|
+
let active = toTemplates(FALLBACK_REGISTRY);
|
|
114
|
+
/** Replace the active registry (remote, cached, local or fallback data). */
|
|
115
|
+
export function setActiveRegistry(registry, options = {}) {
|
|
116
|
+
active = toTemplates(registry, options);
|
|
189
117
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
* Resolution order:
|
|
196
|
-
* 1. Exact key, 2. Without ORM suffix, 3. Partial prefix match
|
|
197
|
-
*/
|
|
198
|
-
export function getTemplate(config) {
|
|
199
|
-
const key = getTemplateKey(config);
|
|
200
|
-
if (_officialRegistry[key])
|
|
201
|
-
return _officialRegistry[key];
|
|
202
|
-
const keyWithoutOrm = key.replace(`-${config.apps.backend.orm}`, '');
|
|
203
|
-
if (_officialRegistry[keyWithoutOrm])
|
|
204
|
-
return _officialRegistry[keyWithoutOrm];
|
|
205
|
-
const partialKey = `${config.monorepo}-${config.apps.frontend.framework.replace('.', '')}-${config.apps.backend.framework.replace('.', '')}`.toLowerCase();
|
|
206
|
-
const closest = Object.keys(_officialRegistry).find(k => k.startsWith(partialKey));
|
|
207
|
-
return closest ? _officialRegistry[closest] : null;
|
|
118
|
+
export function getOfficialTemplates() {
|
|
119
|
+
return active.official;
|
|
120
|
+
}
|
|
121
|
+
export function getContributedTemplates() {
|
|
122
|
+
return active.contributed;
|
|
208
123
|
}
|
|
209
|
-
// ── Listing helpers ───────────────────────────────────────────────────────────
|
|
210
124
|
export function listOfficialTemplates() {
|
|
211
|
-
return
|
|
125
|
+
return active.official.map(metadata => ({ key: metadata.key, metadata }));
|
|
212
126
|
}
|
|
213
127
|
export function listContributedTemplates() {
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
export function hasTemplate(config) {
|
|
217
|
-
return getTemplate(config) !== null;
|
|
218
|
-
}
|
|
219
|
-
export function getSuggestedTemplates(config) {
|
|
220
|
-
const { monorepo } = config;
|
|
221
|
-
return Object.entries(_officialRegistry)
|
|
222
|
-
.filter(([key]) => key.startsWith(monorepo))
|
|
223
|
-
.map(([, metadata]) => metadata)
|
|
224
|
-
.slice(0, 3);
|
|
128
|
+
return active.contributed.map(metadata => ({ key: metadata.key, metadata }));
|
|
225
129
|
}
|
|
226
130
|
// ── Custom template (--template-url) ──────────────────────────────────────────
|
|
227
|
-
export function createCustomTemplate(url, branch = '
|
|
131
|
+
export function createCustomTemplate(url, branch = 'HEAD', subfolder) {
|
|
228
132
|
return {
|
|
229
133
|
url, branch, subfolder,
|
|
230
134
|
description: 'Custom template from URL',
|
|
@@ -232,7 +136,3 @@ export function createCustomTemplate(url, branch = 'main', subfolder) {
|
|
|
232
136
|
supports: { eslint: true, prettier: true, docker: true, turbopack: false },
|
|
233
137
|
};
|
|
234
138
|
}
|
|
235
|
-
export function getLocalTemplatesDir() {
|
|
236
|
-
return LOCAL_TEMPLATES_DIR;
|
|
237
|
-
}
|
|
238
|
-
//# sourceMappingURL=template-registry.js.map
|