@divithselvam/jokebook 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +186 -2
- package/bin/run.js +24 -0
- package/dist/commands/add.d.ts +25 -0
- package/dist/commands/add.js +144 -0
- package/dist/commands/init.d.ts +18 -0
- package/dist/commands/init.js +218 -0
- package/dist/commands/stack/list.d.ts +40 -0
- package/dist/commands/stack/list.js +83 -0
- package/dist/commands/stack/show.d.ts +11 -0
- package/dist/commands/stack/show.js +35 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +203 -0
- package/dist/starter-1.0.0-desktop.tgz +0 -0
- package/dist/starter-1.0.0-mobile.tgz +0 -0
- package/dist/starter-1.0.0-web.tgz +0 -0
- package/docs/STACK.md +565 -0
- package/package.json +85 -4
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import * as prompts from '@clack/prompts';
|
|
2
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
3
|
+
import { copyFile, lstat, mkdir, mkdtemp, readFile, rename, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { x as extract } from 'tar';
|
|
6
|
+
import { assertDestination, catalogDocument, Issue, isUnattended, packageFile, presets, readJson, release, resolveDestination, skills, Workflow, } from '../index.js';
|
|
7
|
+
import { applyRecipe, recipeName, recipePackage, resolveRecipe } from './add.js';
|
|
8
|
+
const usage = 'Try: jokebook init my-product --preset web --dir ./my-product --no-interactive';
|
|
9
|
+
const presetNames = Object.keys(presets);
|
|
10
|
+
function productError(value = '') {
|
|
11
|
+
if (value.length > 63 || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/v.test(value)) {
|
|
12
|
+
return 'Use 1–63 lowercase letters, digits and single hyphens, starting with a letter.';
|
|
13
|
+
}
|
|
14
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9]|node-modules)$/v.test(value)) {
|
|
15
|
+
return 'Choose a name that is portable across filesystems.';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function answered(value) {
|
|
19
|
+
if (prompts.isCancel(value))
|
|
20
|
+
throw new Issue('Cancelled.', {}, 130);
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
async function promptProduct() {
|
|
24
|
+
return answered(await prompts.text({
|
|
25
|
+
message: 'Product name',
|
|
26
|
+
placeholder: 'my-product',
|
|
27
|
+
validate: productError,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
async function promptDestination(product) {
|
|
31
|
+
return answered(await prompts.text({
|
|
32
|
+
defaultValue: product,
|
|
33
|
+
message: 'Destination',
|
|
34
|
+
placeholder: './' + product,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
async function promptPreset() {
|
|
38
|
+
return answered(await prompts.select({
|
|
39
|
+
initialValue: 'web',
|
|
40
|
+
message: 'Preset',
|
|
41
|
+
options: presetNames.map((value) => ({
|
|
42
|
+
hint: presets[value], label: value === 'web' ? 'web (recommended)' : value, value,
|
|
43
|
+
})),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
async function promptRecipes() {
|
|
47
|
+
return answered(await prompts.multiselect({
|
|
48
|
+
message: 'Optional recipes',
|
|
49
|
+
options: [{ hint: 'Browser-side input validation', label: recipePackage, value: recipeName }],
|
|
50
|
+
required: false,
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function plan(settings) {
|
|
54
|
+
return [
|
|
55
|
+
settings.product + ' · ' + settings.preset,
|
|
56
|
+
settings.destination,
|
|
57
|
+
'Starter ' + release.revision,
|
|
58
|
+
'Recipes: ' + (settings.recipes.join(', ') || 'none'),
|
|
59
|
+
'Skills: ' + skills.map(({ name }) => name).join(', '),
|
|
60
|
+
].join('\n');
|
|
61
|
+
}
|
|
62
|
+
async function installSkill(workflow, stage, index) {
|
|
63
|
+
const skill = skills[index];
|
|
64
|
+
if (!skill)
|
|
65
|
+
return;
|
|
66
|
+
const { name, repo } = skill;
|
|
67
|
+
const repository = 'https://github.com/' + repo;
|
|
68
|
+
const args = ['--yes', 'skills@' + release.skillsCli, 'add', repository,
|
|
69
|
+
'--skill', name, '--agent', 'universal', '--copy', '--yes'];
|
|
70
|
+
const output = await workflow.command('npx', args, { cwd: stage, deliverable: `project skill ${name}` });
|
|
71
|
+
const relativePath = `.agents/skills/${name}/SKILL.md`;
|
|
72
|
+
const registration = await readJson(path.join(stage, 'skills-lock.json'));
|
|
73
|
+
const provenance = registration.skills[name];
|
|
74
|
+
const file = path.join(stage, relativePath);
|
|
75
|
+
const identity = /^---\r?\n([\s\S]*?)\r?\n---/v.exec(await readFile(file, 'utf8'))?.[1];
|
|
76
|
+
if (!(await lstat(file)).isFile() || !identity?.split(/\r?\n/v).includes('name: ' + name) ||
|
|
77
|
+
provenance?.source.toLowerCase() !== repo.toLowerCase() ||
|
|
78
|
+
provenance.installMode !== 'copy' || provenance.sourceType !== 'github' ||
|
|
79
|
+
!/^[a-f0-9]{40}$/v.test(provenance.commit)) {
|
|
80
|
+
throw new Issue(`Skills CLI did not verify ${name} from ${repository}.`, {
|
|
81
|
+
command: ['npx', ...args].join(' '),
|
|
82
|
+
cwd: stage,
|
|
83
|
+
deliverable: relativePath,
|
|
84
|
+
exitCode: 0,
|
|
85
|
+
stdout: output,
|
|
86
|
+
versions: workflow.versions,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
workflow.installedSkills.push({ commit: provenance.commit, name, path: relativePath, repository });
|
|
90
|
+
await installSkill(workflow, stage, index + 1);
|
|
91
|
+
}
|
|
92
|
+
async function installSkills(workflow, stage) {
|
|
93
|
+
workflow.stage = 'skills';
|
|
94
|
+
await installSkill(workflow, stage, 0);
|
|
95
|
+
}
|
|
96
|
+
async function applyRecipes(workflow, stage, recipes, index = 0) {
|
|
97
|
+
const recipe = recipes[index];
|
|
98
|
+
if (!recipe)
|
|
99
|
+
return;
|
|
100
|
+
await applyRecipe(workflow, stage, recipe, false);
|
|
101
|
+
await applyRecipes(workflow, stage, recipes, index + 1);
|
|
102
|
+
}
|
|
103
|
+
async function materialize(workflow, settings) {
|
|
104
|
+
const { destination, preset, product, recipes } = settings;
|
|
105
|
+
const isDesktop = ['desktop', 'full'].includes(preset);
|
|
106
|
+
const isMobile = ['full', 'mobile'].includes(preset);
|
|
107
|
+
workflow.stage = 'generation';
|
|
108
|
+
const stage = await mkdtemp(path.join(path.dirname(destination), '.jokebook-'));
|
|
109
|
+
try {
|
|
110
|
+
const archive = isDesktop ? 'desktop' : 'web';
|
|
111
|
+
await extract({ cwd: stage, file: packageFile(`./starter-${release.revision}-${archive}.tgz`), strict: true });
|
|
112
|
+
if (isMobile) {
|
|
113
|
+
const apps = path.join(stage, 'apps');
|
|
114
|
+
await mkdir(apps, { recursive: true });
|
|
115
|
+
await extract({
|
|
116
|
+
cwd: apps,
|
|
117
|
+
file: packageFile(`./starter-${release.revision}-mobile.tgz`),
|
|
118
|
+
strict: true,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
await catalogDocument();
|
|
122
|
+
await copyFile(packageFile('../docs/STACK.md'), path.join(stage, 'STACK.md'));
|
|
123
|
+
const manifest = path.join(stage, 'package.json');
|
|
124
|
+
const starterManifest = await readJson(manifest);
|
|
125
|
+
const marker = { preset, stackSha256: release.stackSha256, starter: release.revision };
|
|
126
|
+
await writeFile(manifest, JSON.stringify({ ...starterManifest, jokebook: marker, name: product }, null, 2) + '\n');
|
|
127
|
+
if (isDesktop) {
|
|
128
|
+
const configFile = path.join(stage, 'apps/desktop/src-tauri/tauri.conf.json');
|
|
129
|
+
const config = await readJson(configFile);
|
|
130
|
+
config.productName = product;
|
|
131
|
+
config.identifier = `com.example.${product}`;
|
|
132
|
+
config.app.windows[0].title = product;
|
|
133
|
+
await writeFile(configFile, JSON.stringify(config, null, 2) + '\n');
|
|
134
|
+
}
|
|
135
|
+
workflow.stage = 'dependencies';
|
|
136
|
+
await workflow.command('pnpm', ['install', '--frozen-lockfile'], { cwd: stage, deliverable: 'product dependencies' });
|
|
137
|
+
await applyRecipes(workflow, stage, recipes);
|
|
138
|
+
await installSkills(workflow, stage);
|
|
139
|
+
workflow.stage = 'finalize';
|
|
140
|
+
workflow.checkCancelled();
|
|
141
|
+
await assertDestination(destination);
|
|
142
|
+
// Windows rename cannot replace an existing directory, even when empty.
|
|
143
|
+
if (process.platform === 'win32') {
|
|
144
|
+
try {
|
|
145
|
+
await rmdir(destination);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error.code !== 'ENOENT')
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
await rename(stage, destination);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
await rm(stage, { force: true, recursive: true });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export default class Init extends Command {
|
|
159
|
+
static args = { product: Args.string({ description: 'Product name in kebab case' }) };
|
|
160
|
+
static description = 'Create a product from the bundled starter release';
|
|
161
|
+
static examples = ['<%= config.bin %> init my-product --preset web --no-interactive --json'];
|
|
162
|
+
static flags = {
|
|
163
|
+
dir: Flags.string({ description: 'Exact destination (default: ./<product>)' }),
|
|
164
|
+
'dry-run': Flags.boolean({ description: 'Resolve the plan without writing anything' }),
|
|
165
|
+
interactive: Flags.boolean({ description: 'Prompt in a usable terminal outside CI' }),
|
|
166
|
+
json: Flags.boolean({ description: 'Emit a single JSON result without prompts' }),
|
|
167
|
+
'no-interactive': Flags.boolean({ description: 'Resolve input without prompts' }),
|
|
168
|
+
preset: Flags.string({ description: 'Surface preset (default: web)', options: presetNames }),
|
|
169
|
+
with: Flags.string({ description: `Apply ${recipeName} (repeat for each recipe)`, multiple: true }),
|
|
170
|
+
};
|
|
171
|
+
async run() {
|
|
172
|
+
const workflow = new Workflow('init');
|
|
173
|
+
await workflow.report(this.argv.includes('--json'), usage, async () => {
|
|
174
|
+
const { args, flags } = await this.parse(Init);
|
|
175
|
+
const canPrompt = !isUnattended() && !flags.json && !flags['no-interactive'];
|
|
176
|
+
if (!canPrompt && flags.interactive) {
|
|
177
|
+
throw new Issue('--interactive requires a usable terminal outside CI and conflicts with --no-interactive and --json.');
|
|
178
|
+
}
|
|
179
|
+
await Promise.all((flags.with ?? []).map(async (recipe) => resolveRecipe(recipe)));
|
|
180
|
+
const product = args.product ?? (canPrompt ? await promptProduct() : undefined);
|
|
181
|
+
if (!product)
|
|
182
|
+
throw new Issue('Supply a product name in non-interactive mode.');
|
|
183
|
+
const invalid = productError(product);
|
|
184
|
+
if (invalid)
|
|
185
|
+
throw new Issue(invalid);
|
|
186
|
+
const dir = flags.dir ?? (canPrompt ? await promptDestination(product) : product);
|
|
187
|
+
const preset = flags.preset ?? (canPrompt ? await promptPreset() : 'web');
|
|
188
|
+
const recipes = flags.with ?? (canPrompt ? await promptRecipes() : []);
|
|
189
|
+
workflow.stage = 'destination';
|
|
190
|
+
const settings = {
|
|
191
|
+
destination: await resolveDestination(dir),
|
|
192
|
+
preset,
|
|
193
|
+
product,
|
|
194
|
+
recipes: [...new Set(recipes)],
|
|
195
|
+
};
|
|
196
|
+
workflow.destination = settings.destination;
|
|
197
|
+
workflow.settings = settings;
|
|
198
|
+
if (flags['dry-run']) {
|
|
199
|
+
workflow.stage = 'plan';
|
|
200
|
+
return { dryRun: true, plan: plan(settings), skills: skills.map(({ name }) => name) };
|
|
201
|
+
}
|
|
202
|
+
if (canPrompt) {
|
|
203
|
+
prompts.note(plan(settings), 'Create product');
|
|
204
|
+
if (!answered(await prompts.confirm({ initialValue: true, message: 'Create this project?' }))) {
|
|
205
|
+
throw new Issue('Cancelled.', {}, 130);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
await workflow.prerequisites(path.dirname(settings.destination), true);
|
|
209
|
+
if (canPrompt)
|
|
210
|
+
prompts.log.info('Installing the workspace and both project skills…');
|
|
211
|
+
await materialize(workflow, settings);
|
|
212
|
+
workflow.stage = 'complete';
|
|
213
|
+
return { created: settings.destination, dryRun: false, skills: skills.map(({ name }) => name) };
|
|
214
|
+
}, (result) => result.dryRun
|
|
215
|
+
? result.plan
|
|
216
|
+
: `Created ${result.created}\nRun pnpm dev from the project root. See README.md for the API and native targets.`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export declare function entries(markdown: string): {
|
|
3
|
+
capability: string;
|
|
4
|
+
id: string;
|
|
5
|
+
recipe: string | null;
|
|
6
|
+
section: string;
|
|
7
|
+
selection: string;
|
|
8
|
+
setup: string;
|
|
9
|
+
source: {
|
|
10
|
+
document: string;
|
|
11
|
+
line: number;
|
|
12
|
+
links: string[];
|
|
13
|
+
};
|
|
14
|
+
status: string;
|
|
15
|
+
versions: string[];
|
|
16
|
+
workspace: string;
|
|
17
|
+
}[];
|
|
18
|
+
export declare function lookup(catalog: ReturnType<typeof entries>, capability: string): {
|
|
19
|
+
capability: string;
|
|
20
|
+
id: string;
|
|
21
|
+
recipe: string | null;
|
|
22
|
+
section: string;
|
|
23
|
+
selection: string;
|
|
24
|
+
setup: string;
|
|
25
|
+
source: {
|
|
26
|
+
document: string;
|
|
27
|
+
line: number;
|
|
28
|
+
links: string[];
|
|
29
|
+
};
|
|
30
|
+
status: string;
|
|
31
|
+
versions: string[];
|
|
32
|
+
workspace: string;
|
|
33
|
+
};
|
|
34
|
+
export default class List extends Command {
|
|
35
|
+
static description: string;
|
|
36
|
+
static flags: {
|
|
37
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
38
|
+
};
|
|
39
|
+
run(): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { catalogDocument, findProduct, Issue, slug, Workflow } from '../../index.js';
|
|
3
|
+
const workspaces = {
|
|
4
|
+
'Data, synchronization, search, analytics and AI': 'services and infrastructure, with client integration as specified',
|
|
5
|
+
'Desktop packages and operating-system integration': 'apps/desktop',
|
|
6
|
+
'Mobile packages and operating-system integration': 'apps/mobile',
|
|
7
|
+
'Monorepo, delivery and operations': 'Workspace root, tooling and infrastructure',
|
|
8
|
+
'Rust API and worker packages': 'services/api and Cargo workspace',
|
|
9
|
+
'Smaller packages that matter in specialized products': 'Depends on capability. See setup.',
|
|
10
|
+
'The decision': 'Root architecture and platform foundations',
|
|
11
|
+
'Web package catalog': 'apps/web',
|
|
12
|
+
};
|
|
13
|
+
function references(value) {
|
|
14
|
+
return value.matchAll(/\[\d+\]\(<(https?:\/\/[^>]+)>\)/gv).map((match) => match[1]).toArray();
|
|
15
|
+
}
|
|
16
|
+
function withoutReferences(value) {
|
|
17
|
+
return value.replaceAll(/\s*\[\d+\]\(<[^>]+>\)/gv, '').trim();
|
|
18
|
+
}
|
|
19
|
+
export function entries(markdown) {
|
|
20
|
+
let section = '';
|
|
21
|
+
let isReadingTable = false;
|
|
22
|
+
const result = [];
|
|
23
|
+
for (const [index, line] of markdown.split('\n').entries()) {
|
|
24
|
+
if (line.startsWith('## '))
|
|
25
|
+
section = line.slice(3).trim();
|
|
26
|
+
if (!line.startsWith('|')) {
|
|
27
|
+
isReadingTable = false;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (line.startsWith('| Capability |') || (section === 'The decision' && line.startsWith('| Surface |'))) {
|
|
31
|
+
isReadingTable = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (!isReadingTable || line.startsWith('|---'))
|
|
35
|
+
continue;
|
|
36
|
+
const [, label, selected, notes] = line.split('|').map((cell) => cell.trim());
|
|
37
|
+
const id = slug(label);
|
|
38
|
+
if (!id || !selected || !notes)
|
|
39
|
+
throw new Issue(`Invalid catalog row on line ${index + 1}.`);
|
|
40
|
+
result.push({
|
|
41
|
+
capability: label,
|
|
42
|
+
id,
|
|
43
|
+
recipe: id === 'runtime-validation' ? id : null,
|
|
44
|
+
section,
|
|
45
|
+
selection: withoutReferences(selected),
|
|
46
|
+
setup: withoutReferences(notes),
|
|
47
|
+
source: { document: 'STACK.md', line: index + 1, links: references(line) },
|
|
48
|
+
status: id === 'runtime-validation' ? 'Automated recipe verified for starter 1.0.0' : 'Catalog recommendation; verify before adopting',
|
|
49
|
+
versions: new Set(selected.matchAll(/(?:@|\*\*)(\d+(?:\.\d+)*(?:[.\-][\w.]+)?)/gv).map((match) => match[1])).values().toArray(),
|
|
50
|
+
workspace: workspaces[section] ?? 'See catalog setup',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (result.length === 0)
|
|
54
|
+
throw new Issue('No capability rows were found in STACK.md.');
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
export function lookup(catalog, capability) {
|
|
58
|
+
const id = slug(capability);
|
|
59
|
+
const exact = catalog.find((row) => row.id === id);
|
|
60
|
+
if (exact)
|
|
61
|
+
return exact;
|
|
62
|
+
const packages = catalog.filter(({ selection }) => selection.matchAll(/`([^`]+)`/gv).some((match) => match[1].toLowerCase().replace(/@\d.*$/v, '') === capability.toLowerCase()));
|
|
63
|
+
if (packages.length > 1) {
|
|
64
|
+
throw new Issue('Package matches multiple capabilities. Use a capability slug.', { matches: packages.map((row) => row.id) });
|
|
65
|
+
}
|
|
66
|
+
return packages[0];
|
|
67
|
+
}
|
|
68
|
+
export default class List extends Command {
|
|
69
|
+
static description = 'List package and platform capabilities from STACK.md';
|
|
70
|
+
static flags = { json: Flags.boolean({ description: 'Emit JSON' }) };
|
|
71
|
+
async run() {
|
|
72
|
+
const workflow = new Workflow('stack list');
|
|
73
|
+
await workflow.report(this.argv.includes('--json'), 'Try: jokebook stack list [--json]', async () => {
|
|
74
|
+
await this.parse(List);
|
|
75
|
+
workflow.stage = 'catalog';
|
|
76
|
+
const product = await findProduct();
|
|
77
|
+
if (product)
|
|
78
|
+
workflow.starterRevision = product.marker.starter;
|
|
79
|
+
const { digest, text } = await catalogDocument(product);
|
|
80
|
+
return { capabilities: entries(text), stackSha256: digest };
|
|
81
|
+
}, (result) => result.capabilities.map(({ capability, id }) => `${id} ${capability}`).join('\n'));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Show extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
capability: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static flags: {
|
|
8
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
+
import { catalogDocument, findProduct, Issue, Workflow } from '../../index.js';
|
|
3
|
+
import { entries, lookup } from './list.js';
|
|
4
|
+
export default class Show extends Command {
|
|
5
|
+
static args = { capability: Args.string({ description: 'Capability slug or package name', required: true }) };
|
|
6
|
+
static description = 'Show a capability, its workspace, sources and setup';
|
|
7
|
+
static flags = { json: Flags.boolean({ description: 'Emit JSON' }) };
|
|
8
|
+
async run() {
|
|
9
|
+
const workflow = new Workflow('stack show');
|
|
10
|
+
await workflow.report(this.argv.includes('--json'), 'Try: jokebook stack show runtime-validation [--json]', async () => {
|
|
11
|
+
const { args } = await this.parse(Show);
|
|
12
|
+
workflow.stage = 'catalog';
|
|
13
|
+
const product = await findProduct();
|
|
14
|
+
if (product)
|
|
15
|
+
workflow.starterRevision = product.marker.starter;
|
|
16
|
+
const { digest, text } = await catalogDocument(product);
|
|
17
|
+
const capability = lookup(entries(text), args.capability);
|
|
18
|
+
if (!capability)
|
|
19
|
+
throw new Issue(`Unknown capability "${args.capability}". Run jokebook stack list.`);
|
|
20
|
+
return { capability, stackSha256: digest };
|
|
21
|
+
}, (result) => {
|
|
22
|
+
const row = result.capability;
|
|
23
|
+
return [
|
|
24
|
+
row.capability,
|
|
25
|
+
row.selection,
|
|
26
|
+
`Workspace: ${row.workspace}`,
|
|
27
|
+
`Status: ${row.status}`,
|
|
28
|
+
`Setup: ${row.setup}`,
|
|
29
|
+
`Source: ${row.source.document}:${row.source.line}`,
|
|
30
|
+
...row.source.links,
|
|
31
|
+
...(row.recipe ? [`Recipe: jokebook add ${row.recipe}`] : []),
|
|
32
|
+
].join('\n');
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const release: {
|
|
2
|
+
readonly node: "26.13.1";
|
|
3
|
+
readonly pnpm: "12.25.1";
|
|
4
|
+
readonly revision: "1.0.0";
|
|
5
|
+
readonly skillsCli: "1.9.1";
|
|
6
|
+
readonly stackSha256: "850953320cc8e9093b9c3286e4279596dbdd274319e2b60ab648977ae4e90307";
|
|
7
|
+
};
|
|
8
|
+
export declare const skills: readonly [{
|
|
9
|
+
readonly name: "blame-the-intern";
|
|
10
|
+
readonly repo: "Divith123/skills";
|
|
11
|
+
}, {
|
|
12
|
+
readonly name: "modern-web-guidance";
|
|
13
|
+
readonly repo: "googlechrome/modern-web-guidance";
|
|
14
|
+
}];
|
|
15
|
+
export declare const presets: {
|
|
16
|
+
desktop: string;
|
|
17
|
+
full: string;
|
|
18
|
+
mobile: string;
|
|
19
|
+
web: string;
|
|
20
|
+
};
|
|
21
|
+
export type Preset = keyof typeof presets;
|
|
22
|
+
export type Settings = {
|
|
23
|
+
destination: string;
|
|
24
|
+
preset: Preset;
|
|
25
|
+
product: string;
|
|
26
|
+
recipes: string[];
|
|
27
|
+
};
|
|
28
|
+
export type ProductMarker = {
|
|
29
|
+
preset: string;
|
|
30
|
+
stackSha256: string;
|
|
31
|
+
starter: string;
|
|
32
|
+
};
|
|
33
|
+
type Product = {
|
|
34
|
+
cwd: string;
|
|
35
|
+
marker: ProductMarker;
|
|
36
|
+
};
|
|
37
|
+
export declare class Issue extends Error {
|
|
38
|
+
readonly details: Record<string, unknown>;
|
|
39
|
+
readonly code: number;
|
|
40
|
+
constructor(message: string, details?: Record<string, unknown>, code?: number);
|
|
41
|
+
}
|
|
42
|
+
export declare function isUnattended(): boolean;
|
|
43
|
+
type CommandOptions = {
|
|
44
|
+
cwd: string;
|
|
45
|
+
deliverable: string;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
};
|
|
48
|
+
export declare class Workflow {
|
|
49
|
+
readonly controller: AbortController;
|
|
50
|
+
destination: string | undefined;
|
|
51
|
+
installedSkills: Array<{
|
|
52
|
+
commit: string;
|
|
53
|
+
name: string;
|
|
54
|
+
path: string;
|
|
55
|
+
repository: string;
|
|
56
|
+
}>;
|
|
57
|
+
readonly operation: string;
|
|
58
|
+
settings: Settings | undefined;
|
|
59
|
+
stage: string;
|
|
60
|
+
starterRevision: string;
|
|
61
|
+
readonly versions: Record<string, string>;
|
|
62
|
+
constructor(operation: string);
|
|
63
|
+
checkCancelled(): void;
|
|
64
|
+
command(binary: string, args: string[], options: CommandOptions): Promise<string>;
|
|
65
|
+
prerequisites(cwd: string, hasSkills?: boolean): Promise<void>;
|
|
66
|
+
report<T extends Record<string, unknown>>(isJson: boolean, usage: string, task: () => Promise<T>, format: (result: T) => string): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
export declare function assertDestination(destination: string): Promise<void>;
|
|
69
|
+
export declare function resolveDestination(directory: string): Promise<string>;
|
|
70
|
+
export declare function packageFile(relative: string): string;
|
|
71
|
+
export declare function readJson<T>(file: string): Promise<T>;
|
|
72
|
+
export declare function findProduct(start?: string): Promise<Product | undefined>;
|
|
73
|
+
export declare function catalogDocument(product?: Product): Promise<{
|
|
74
|
+
digest: string;
|
|
75
|
+
text: string;
|
|
76
|
+
}>;
|
|
77
|
+
export declare function slug(value: string): string;
|
|
78
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { isCI } from 'ci-info';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { lstat, readdir, readFile, realpath } from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
8
|
+
export const release = {
|
|
9
|
+
node: '26.13.1',
|
|
10
|
+
pnpm: '12.25.1',
|
|
11
|
+
revision: '1.0.0',
|
|
12
|
+
skillsCli: '1.9.1',
|
|
13
|
+
stackSha256: '850953320cc8e9093b9c3286e4279596dbdd274319e2b60ab648977ae4e90307',
|
|
14
|
+
};
|
|
15
|
+
export const skills = [
|
|
16
|
+
{ name: 'blame-the-intern', repo: 'Divith123/skills' },
|
|
17
|
+
{ name: 'modern-web-guidance', repo: 'googlechrome/modern-web-guidance' },
|
|
18
|
+
];
|
|
19
|
+
export const presets = {
|
|
20
|
+
desktop: 'Web foundation and Tauri desktop',
|
|
21
|
+
full: 'Web, Tauri desktop and shared-Swift mobile',
|
|
22
|
+
mobile: 'Web foundation with SwiftUI and Jetpack Compose apps',
|
|
23
|
+
web: 'SvelteKit, Rust API and PostgreSQL',
|
|
24
|
+
};
|
|
25
|
+
export class Issue extends Error {
|
|
26
|
+
details;
|
|
27
|
+
code;
|
|
28
|
+
constructor(message, details = {}, code = 1) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.details = details;
|
|
31
|
+
this.code = code;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function isUnattended() {
|
|
35
|
+
return isCI || !process.stdin.isTTY || !process.stdout.isTTY || process.env.TERM === 'dumb';
|
|
36
|
+
}
|
|
37
|
+
function redact(value) {
|
|
38
|
+
let clean = stripVTControlCharacters(value);
|
|
39
|
+
for (const [name, secret] of Object.entries(process.env)) {
|
|
40
|
+
if (secret !== undefined && secret.length >= 8 && /(?:api.?key|password|secret|token)/iv.test(name)) {
|
|
41
|
+
clean = clean.replaceAll(secret, '[redacted]');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return clean
|
|
45
|
+
.replaceAll(/(\w+:\/\/)[^\/\s@]+@/gv, '$1[redacted]@')
|
|
46
|
+
.replaceAll(/\b(?:npm_|gh[pousr]_)[\w]{20,}/gv, '[redacted]')
|
|
47
|
+
.replaceAll(/([Aa]uthorization:\s*(?:[Bb]earer|[Bb]asic)\s+)\S+/gv, '$1[redacted]');
|
|
48
|
+
}
|
|
49
|
+
export class Workflow {
|
|
50
|
+
controller = new AbortController();
|
|
51
|
+
destination;
|
|
52
|
+
installedSkills = [];
|
|
53
|
+
operation;
|
|
54
|
+
settings;
|
|
55
|
+
stage = 'arguments';
|
|
56
|
+
starterRevision = release.revision;
|
|
57
|
+
versions = { node: process.versions.node };
|
|
58
|
+
constructor(operation) {
|
|
59
|
+
this.operation = operation;
|
|
60
|
+
}
|
|
61
|
+
checkCancelled() {
|
|
62
|
+
if (this.controller.signal.aborted)
|
|
63
|
+
throw new Issue('Cancelled.', {}, 130);
|
|
64
|
+
}
|
|
65
|
+
async command(binary, args, options) {
|
|
66
|
+
const { cwd, deliverable } = options;
|
|
67
|
+
const result = await execa(binary, args, {
|
|
68
|
+
cancelSignal: options.signal ?? this.controller.signal,
|
|
69
|
+
cwd,
|
|
70
|
+
env: { CI: 'true', FORCE_COLOR: undefined, GIT_TERMINAL_PROMPT: '0', NO_COLOR: '1' },
|
|
71
|
+
reject: false,
|
|
72
|
+
stdin: 'ignore',
|
|
73
|
+
timeout: 300_000,
|
|
74
|
+
});
|
|
75
|
+
if (result.failed) {
|
|
76
|
+
const errorOutput = (result.stderr === '' ? result.stdout === '' ? result.shortMessage : result.stdout : result.stderr) ?? '';
|
|
77
|
+
const code = result.isCanceled ? 130 : 1;
|
|
78
|
+
throw new Issue(result.isCanceled ? 'Cancelled.' : `Could not complete ${deliverable}.`, {
|
|
79
|
+
command: redact(result.escapedCommand),
|
|
80
|
+
cwd,
|
|
81
|
+
deliverable,
|
|
82
|
+
exitCode: result.exitCode ?? null,
|
|
83
|
+
signal: result.signal ?? null,
|
|
84
|
+
stderr: redact(errorOutput),
|
|
85
|
+
stdout: redact(result.stdout ?? ''),
|
|
86
|
+
versions: this.versions,
|
|
87
|
+
}, code);
|
|
88
|
+
}
|
|
89
|
+
return result.stdout;
|
|
90
|
+
}
|
|
91
|
+
async prerequisites(cwd, hasSkills = false) {
|
|
92
|
+
this.stage = 'prerequisites';
|
|
93
|
+
if (process.versions.node !== release.node) {
|
|
94
|
+
throw new Issue(`Use Node.js ${release.node}. Found ${process.versions.node}.`);
|
|
95
|
+
}
|
|
96
|
+
const pnpm = await this.command('pnpm', ['--version'], {
|
|
97
|
+
cwd, deliverable: `pnpm ${release.pnpm} availability`,
|
|
98
|
+
});
|
|
99
|
+
this.versions.pnpm = pnpm;
|
|
100
|
+
if (pnpm !== release.pnpm)
|
|
101
|
+
throw new Issue(`Use pnpm ${release.pnpm}. Found ${pnpm}.`);
|
|
102
|
+
if (hasSkills) {
|
|
103
|
+
this.versions.npm = await this.command('npx', ['--version'], { cwd, deliverable: 'npm/npx availability' });
|
|
104
|
+
this.versions.git = await this.command('git', ['--version'], { cwd, deliverable: 'Git availability' });
|
|
105
|
+
this.versions.skills = release.skillsCli;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async report(isJson, usage, task, format) {
|
|
109
|
+
const cancel = () => { this.controller.abort(); };
|
|
110
|
+
process.on('SIGINT', cancel);
|
|
111
|
+
process.on('SIGTERM', cancel);
|
|
112
|
+
try {
|
|
113
|
+
const result = await task();
|
|
114
|
+
const data = { ...summarize(this), ...result, ok: true };
|
|
115
|
+
console.log(isJson ? JSON.stringify(data) : format(result));
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const issue = error instanceof Issue ? error : new Issue(error instanceof Error ? error.message : String(error));
|
|
119
|
+
const details = { message: redact(issue.message), ...issue.details };
|
|
120
|
+
if (isJson) {
|
|
121
|
+
console.log(JSON.stringify({ ...summarize(this), error: details, ok: false, usage }));
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
console.error(`[${this.stage}] ${details.message}`);
|
|
125
|
+
for (const [key, value] of Object.entries(issue.details)) {
|
|
126
|
+
if (value !== '' && value !== null)
|
|
127
|
+
console.error(`${key}: ${typeof value === 'string' ? value : JSON.stringify(value)}`);
|
|
128
|
+
}
|
|
129
|
+
if (issue.code !== 130)
|
|
130
|
+
console.error(usage);
|
|
131
|
+
}
|
|
132
|
+
process.exitCode = issue.code;
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
process.off('SIGINT', cancel);
|
|
136
|
+
process.off('SIGTERM', cancel);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function summarize(workflow) {
|
|
141
|
+
return {
|
|
142
|
+
destination: workflow.destination,
|
|
143
|
+
installedSkills: workflow.installedSkills,
|
|
144
|
+
operation: workflow.operation,
|
|
145
|
+
settings: workflow.settings,
|
|
146
|
+
stage: workflow.stage,
|
|
147
|
+
starterRevision: workflow.starterRevision,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export async function assertDestination(destination) {
|
|
151
|
+
try {
|
|
152
|
+
const entry = await lstat(destination);
|
|
153
|
+
if (!entry.isDirectory() || (await readdir(destination)).length > 0) {
|
|
154
|
+
throw new Issue('Choose a destination that is absent or an empty directory.');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error.code !== 'ENOENT')
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export async function resolveDestination(directory) {
|
|
163
|
+
const absolute = path.resolve(directory);
|
|
164
|
+
const { base, dir, root } = path.parse(absolute);
|
|
165
|
+
if (absolute === root || base === '')
|
|
166
|
+
throw new Issue('Choose a destination inside an existing parent directory.');
|
|
167
|
+
const parent = await realpath(dir);
|
|
168
|
+
const destination = path.resolve(parent, base);
|
|
169
|
+
await assertDestination(destination);
|
|
170
|
+
return destination;
|
|
171
|
+
}
|
|
172
|
+
export function packageFile(relative) {
|
|
173
|
+
return fileURLToPath(new URL(relative, import.meta.url));
|
|
174
|
+
}
|
|
175
|
+
export async function readJson(file) {
|
|
176
|
+
return JSON.parse(await readFile(file, 'utf8'));
|
|
177
|
+
}
|
|
178
|
+
export async function findProduct(start = process.cwd()) {
|
|
179
|
+
try {
|
|
180
|
+
const manifest = await readJson(path.resolve(start, 'package.json'));
|
|
181
|
+
if (manifest.jokebook?.starter && manifest.jokebook.stackSha256) {
|
|
182
|
+
return { cwd: start, marker: manifest.jokebook };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (error.code !== 'ENOENT')
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
const parent = path.dirname(start);
|
|
190
|
+
return parent === start ? undefined : findProduct(parent);
|
|
191
|
+
}
|
|
192
|
+
export async function catalogDocument(product) {
|
|
193
|
+
const source = product ? path.resolve(product.cwd, 'STACK.md') : packageFile('../docs/STACK.md');
|
|
194
|
+
const text = await readFile(source, 'utf8');
|
|
195
|
+
const digest = createHash('sha256').update(text).digest('hex');
|
|
196
|
+
const expected = product?.marker.stackSha256 ?? release.stackSha256;
|
|
197
|
+
if (digest !== expected)
|
|
198
|
+
throw new Issue('STACK.md differs from the recorded revision. Restore the original catalog before continuing.');
|
|
199
|
+
return { digest, text };
|
|
200
|
+
}
|
|
201
|
+
export function slug(value) {
|
|
202
|
+
return value.toLowerCase().replaceAll(/[^a-z0-9]+/gv, '-').replaceAll(/^-|-$/gv, '');
|
|
203
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|