@divithselvam/jokebook 1.0.0 → 1.2.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 +55 -0
- package/README.md +41 -28
- package/bin/run.js +4 -1
- package/{docs → dist/catalog}/STACK.md +33 -5
- package/dist/catalog/index.json +4 -0
- package/dist/commands/add.d.ts +12 -4
- package/dist/commands/add.js +29 -24
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +30 -25
- package/dist/commands/stack/list.d.ts +26 -15
- package/dist/commands/stack/list.js +190 -30
- package/dist/commands/stack/show.js +3 -2
- package/dist/commands/upgrade.d.ts +10 -0
- package/dist/commands/upgrade.js +55 -0
- package/dist/index.d.ts +18 -14
- package/dist/index.js +78 -21
- package/dist/starter.d.ts +14 -0
- package/dist/starter.js +38 -0
- package/dist/starters/1.0.0/desktop.tgz +0 -0
- package/dist/starters/1.0.0/mobile.tgz +0 -0
- package/dist/{starter-1.0.0-web.tgz → starters/1.0.0/web.tgz} +0 -0
- package/dist/starters/1.1.0/desktop.tgz +0 -0
- package/dist/starters/1.1.0/mobile.tgz +0 -0
- package/dist/starters/1.1.0/web.tgz +0 -0
- package/dist/starters/1.2.0/desktop.tgz +0 -0
- package/dist/starters/1.2.0/mobile.tgz +0 -0
- package/dist/starters/1.2.0/web.tgz +0 -0
- package/dist/starters/index.json +27 -0
- package/dist/upgrade.d.ts +30 -0
- package/dist/upgrade.js +574 -0
- package/package.json +20 -5
- package/dist/starter-1.0.0-desktop.tgz +0 -0
- package/dist/starter-1.0.0-mobile.tgz +0 -0
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
|
-
export
|
|
2
|
+
export type CatalogRecipe = {
|
|
3
|
+
aliases: string[];
|
|
3
4
|
capability: string;
|
|
4
5
|
id: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
status: string;
|
|
15
|
-
versions: string[];
|
|
6
|
+
implementation: string;
|
|
7
|
+
package: string;
|
|
8
|
+
summary: string;
|
|
9
|
+
workspace: string;
|
|
10
|
+
};
|
|
11
|
+
type CatalogSection = {
|
|
12
|
+
header: string;
|
|
13
|
+
heading: string;
|
|
16
14
|
workspace: string;
|
|
17
|
-
}
|
|
18
|
-
export
|
|
15
|
+
};
|
|
16
|
+
export type CatalogMetadata = {
|
|
17
|
+
recipes: CatalogRecipe[];
|
|
18
|
+
sections: CatalogSection[];
|
|
19
|
+
};
|
|
20
|
+
export type CatalogRow = {
|
|
19
21
|
capability: string;
|
|
20
22
|
id: string;
|
|
21
|
-
recipe: string |
|
|
23
|
+
recipe: string | undefined;
|
|
22
24
|
section: string;
|
|
23
25
|
selection: string;
|
|
24
26
|
setup: string;
|
|
@@ -31,6 +33,14 @@ export declare function lookup(catalog: ReturnType<typeof entries>, capability:
|
|
|
31
33
|
versions: string[];
|
|
32
34
|
workspace: string;
|
|
33
35
|
};
|
|
36
|
+
export declare function catalogMetadata(markdown: string): CatalogMetadata | undefined;
|
|
37
|
+
export declare function compileCatalog(markdown: string, document?: string): {
|
|
38
|
+
metadata: CatalogMetadata | undefined;
|
|
39
|
+
rows: CatalogRow[];
|
|
40
|
+
};
|
|
41
|
+
export declare function entries(markdown: string, document?: string): CatalogRow[];
|
|
42
|
+
export declare function recipeVersion(rows: CatalogRow[], recipe: CatalogRecipe): string;
|
|
43
|
+
export declare function lookup(catalog: ReturnType<typeof entries>, capability: string): CatalogRow;
|
|
34
44
|
export default class List extends Command {
|
|
35
45
|
static description: string;
|
|
36
46
|
static flags: {
|
|
@@ -38,3 +48,4 @@ export default class List extends Command {
|
|
|
38
48
|
};
|
|
39
49
|
run(): Promise<void>;
|
|
40
50
|
}
|
|
51
|
+
export {};
|
|
@@ -1,58 +1,218 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
}
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { catalogDocument, catalogPath, findProduct, Issue, slug, Workflow } from '../../index.js';
|
|
4
|
+
// Catalog 1.0.0 shipped before the machine-readable block. It is frozen, so its
|
|
5
|
+
// section ownership can only live here; every newer catalog must declare it.
|
|
6
|
+
const legacySections = [
|
|
7
|
+
{ header: 'Capability', heading: 'Data, synchronization, search, analytics and AI', workspace: 'services and infrastructure, with client integration as specified' },
|
|
8
|
+
{ header: 'Capability', heading: 'Desktop packages and operating-system integration', workspace: 'apps/desktop' },
|
|
9
|
+
{ header: 'Capability', heading: 'Mobile packages and operating-system integration', workspace: 'apps/mobile' },
|
|
10
|
+
{ header: 'Capability', heading: 'Monorepo, delivery and operations', workspace: 'Workspace root, tooling and infrastructure' },
|
|
11
|
+
{ header: 'Capability', heading: 'Rust API and worker packages', workspace: 'api and Cargo workspace' },
|
|
12
|
+
{ header: 'Capability', heading: 'Smaller packages that matter in specialized products', workspace: 'Depends on capability. See setup.' },
|
|
13
|
+
{ header: 'Surface', heading: 'The decision', workspace: 'Root architecture and platform foundations' },
|
|
14
|
+
{ header: 'Capability', heading: 'Web package catalog', workspace: 'apps/web' },
|
|
15
|
+
];
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
function requiredString(value, field) {
|
|
20
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
21
|
+
throw new Issue(`The catalog metadata field "${field}" must be a non-empty string.`);
|
|
22
|
+
}
|
|
23
|
+
return value.trim();
|
|
24
|
+
}
|
|
25
|
+
function workspacePath(value, field) {
|
|
26
|
+
const workspace = requiredString(value, field);
|
|
27
|
+
const normalized = path.posix.normalize(workspace);
|
|
28
|
+
if (normalized !== workspace || normalized === '.' || normalized === '..' ||
|
|
29
|
+
normalized.startsWith('../') || workspace.includes('\\') || path.posix.isAbsolute(workspace)) {
|
|
30
|
+
throw new Issue(`The catalog metadata field "${field}" must be a relative workspace path.`);
|
|
31
|
+
}
|
|
32
|
+
return workspace;
|
|
33
|
+
}
|
|
34
|
+
function metadataValue(markdown) {
|
|
35
|
+
const match = /<!--\s*jokebook-catalog\s*\r?\n([\s\S]*?)\r?\n-->/v.exec(markdown);
|
|
36
|
+
if (!match)
|
|
37
|
+
return undefined;
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(match[1]);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Issue(`The catalog metadata block is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function catalogMetadata(markdown) {
|
|
46
|
+
const value = metadataValue(markdown);
|
|
47
|
+
if (value === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
if (!isRecord(value) || !Array.isArray(value.sections) || !Array.isArray(value.recipes)) {
|
|
50
|
+
throw new Issue('The catalog metadata block must contain sections and recipes arrays.');
|
|
51
|
+
}
|
|
52
|
+
const headings = new Set();
|
|
53
|
+
const sections = value.sections.map((entry, index) => {
|
|
54
|
+
if (!isRecord(entry))
|
|
55
|
+
throw new Issue(`Catalog section ${index + 1} must be an object.`);
|
|
56
|
+
const section = {
|
|
57
|
+
header: requiredString(entry.header, `sections[${index}].header`),
|
|
58
|
+
heading: requiredString(entry.heading, `sections[${index}].heading`),
|
|
59
|
+
workspace: requiredString(entry.workspace, `sections[${index}].workspace`),
|
|
60
|
+
};
|
|
61
|
+
if (headings.has(section.heading))
|
|
62
|
+
throw new Issue(`Catalog section "${section.heading}" is declared twice.`);
|
|
63
|
+
headings.add(section.heading);
|
|
64
|
+
return section;
|
|
65
|
+
});
|
|
66
|
+
const names = new Set();
|
|
67
|
+
const recipes = value.recipes.map((entry, index) => {
|
|
68
|
+
if (!isRecord(entry))
|
|
69
|
+
throw new Issue(`Catalog recipe ${index + 1} must be an object.`);
|
|
70
|
+
const id = requiredString(entry.id, `recipes[${index}].id`);
|
|
71
|
+
if (slug(id) !== id)
|
|
72
|
+
throw new Issue(`Catalog recipe id "${id}" must be a slug.`);
|
|
73
|
+
const aliases = Array.isArray(entry.aliases) ? entry.aliases.map((alias, aliasIndex) => {
|
|
74
|
+
const aliasValue = requiredString(alias, `recipes[${index}].aliases[${aliasIndex}]`);
|
|
75
|
+
if (slug(aliasValue) !== aliasValue)
|
|
76
|
+
throw new Issue(`Catalog recipe alias "${aliasValue}" must be a slug.`);
|
|
77
|
+
return aliasValue;
|
|
78
|
+
}) : [];
|
|
79
|
+
for (const name of [id, ...aliases]) {
|
|
80
|
+
if (names.has(name))
|
|
81
|
+
throw new Issue(`Catalog recipe name "${name}" is declared twice.`);
|
|
82
|
+
names.add(name);
|
|
83
|
+
}
|
|
84
|
+
const capability = requiredString(entry.capability, `recipes[${index}].capability`);
|
|
85
|
+
if (slug(capability) !== capability)
|
|
86
|
+
throw new Issue(`Catalog recipe capability "${capability}" must be a slug.`);
|
|
87
|
+
return {
|
|
88
|
+
aliases,
|
|
89
|
+
capability,
|
|
90
|
+
id,
|
|
91
|
+
implementation: requiredString(entry.implementation, `recipes[${index}].implementation`),
|
|
92
|
+
package: requiredString(entry.package, `recipes[${index}].package`),
|
|
93
|
+
summary: requiredString(entry.summary, `recipes[${index}].summary`),
|
|
94
|
+
workspace: workspacePath(entry.workspace, `recipes[${index}].workspace`),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return { recipes, sections };
|
|
98
|
+
}
|
|
99
|
+
function cells(line) {
|
|
100
|
+
return line.trim().replace(/^\|/v, '').replace(/\|$/v, '').split(/(?<!\\)\|/v)
|
|
101
|
+
.map((cell) => cell.trim().replaceAll(String.raw `\|`, '|'));
|
|
102
|
+
}
|
|
13
103
|
function references(value) {
|
|
14
104
|
return value.matchAll(/\[\d+\]\(<(https?:\/\/[^>]+)>\)/gv).map((match) => match[1]).toArray();
|
|
15
105
|
}
|
|
16
106
|
function withoutReferences(value) {
|
|
17
107
|
return value.replaceAll(/\s*\[\d+\]\(<[^>]+>\)/gv, '').trim();
|
|
18
108
|
}
|
|
19
|
-
|
|
109
|
+
function versionList(selection) {
|
|
110
|
+
return new Set(selection.matchAll(/(?:@|\*\*)(\d+(?:\.\d+)*(?:[.\-][\w.]+)?)/gv)
|
|
111
|
+
.map((match) => match[1])).values().toArray();
|
|
112
|
+
}
|
|
113
|
+
function escapePattern(value) {
|
|
114
|
+
const special = new Set(String.raw `\^$.*+?()[]{}|`);
|
|
115
|
+
return [...value].map((character) => special.has(character) ? `\\${character}` : character).join('');
|
|
116
|
+
}
|
|
117
|
+
function packagePin(selection, packageName) {
|
|
118
|
+
const pattern = new RegExp('`' + escapePattern(packageName) +
|
|
119
|
+
'@(\\d+(?:\\.\\d+)+(?:[\\-+][\\w.]+)?)`', 'v');
|
|
120
|
+
const match = pattern.exec(selection);
|
|
121
|
+
if (!match)
|
|
122
|
+
throw new Issue(`The catalog does not pin ${packageName} for its automated recipe.`);
|
|
123
|
+
return match[1];
|
|
124
|
+
}
|
|
125
|
+
export function compileCatalog(markdown, document = catalogPath) {
|
|
126
|
+
const metadata = catalogMetadata(markdown);
|
|
127
|
+
const sections = metadata?.sections ?? legacySections;
|
|
128
|
+
const byHeading = new Map(sections.map((section) => [section.heading, section]));
|
|
129
|
+
const recipeByCapability = new Map();
|
|
130
|
+
for (const recipe of metadata?.recipes ?? []) {
|
|
131
|
+
if (recipeByCapability.has(recipe.capability)) {
|
|
132
|
+
throw new Issue(`Catalog capability "${recipe.capability}" has more than one automated recipe.`);
|
|
133
|
+
}
|
|
134
|
+
recipeByCapability.set(recipe.capability, recipe);
|
|
135
|
+
}
|
|
136
|
+
const headings = new Set();
|
|
137
|
+
for (const line of markdown.split(/\r?\n/v)) {
|
|
138
|
+
if (line.startsWith('## '))
|
|
139
|
+
headings.add(line.slice(3).trim());
|
|
140
|
+
}
|
|
141
|
+
for (const section of sections) {
|
|
142
|
+
if (!headings.has(section.heading))
|
|
143
|
+
throw new Issue(`The catalog is missing the declared section "${section.heading}".`);
|
|
144
|
+
}
|
|
145
|
+
const declaredHeaders = new Set(sections.map(({ header }) => header));
|
|
146
|
+
const seenSections = new Set();
|
|
147
|
+
const rows = [];
|
|
20
148
|
let section = '';
|
|
21
149
|
let isReadingTable = false;
|
|
22
|
-
|
|
23
|
-
for (const [index, line] of markdown.split(
|
|
24
|
-
if (line.startsWith('## '))
|
|
150
|
+
let isDeclaredTable = false;
|
|
151
|
+
for (const [index, line] of markdown.split(/\r?\n/v).entries()) {
|
|
152
|
+
if (line.startsWith('## ')) {
|
|
25
153
|
section = line.slice(3).trim();
|
|
154
|
+
isReadingTable = false;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
26
157
|
if (!line.startsWith('|')) {
|
|
27
158
|
isReadingTable = false;
|
|
28
159
|
continue;
|
|
29
160
|
}
|
|
30
|
-
if (
|
|
161
|
+
if (!isReadingTable) {
|
|
31
162
|
isReadingTable = true;
|
|
163
|
+
const header = cells(line)[0];
|
|
164
|
+
isDeclaredTable = byHeading.get(section)?.header === header;
|
|
165
|
+
if (!isDeclaredTable && declaredHeaders.has(header)) {
|
|
166
|
+
throw new Issue(`Catalog table "${header}" on line ${index + 1} is not declared by section "${section || '(none)'}".`);
|
|
167
|
+
}
|
|
32
168
|
continue;
|
|
33
169
|
}
|
|
34
|
-
if (!
|
|
170
|
+
if (!isDeclaredTable || line.startsWith('|---'))
|
|
35
171
|
continue;
|
|
36
|
-
const [
|
|
172
|
+
const [label, selected, notes] = cells(line);
|
|
37
173
|
const id = slug(label);
|
|
38
174
|
if (!id || !selected || !notes)
|
|
39
175
|
throw new Issue(`Invalid catalog row on line ${index + 1}.`);
|
|
40
|
-
|
|
176
|
+
if (rows.some((row) => row.id === id))
|
|
177
|
+
throw new Issue(`Catalog capability "${id}" is declared twice.`);
|
|
178
|
+
const recipe = recipeByCapability.get(id);
|
|
179
|
+
rows.push({
|
|
41
180
|
capability: label,
|
|
42
181
|
id,
|
|
43
|
-
recipe: id
|
|
182
|
+
recipe: recipe?.id,
|
|
44
183
|
section,
|
|
45
184
|
selection: withoutReferences(selected),
|
|
46
185
|
setup: withoutReferences(notes),
|
|
47
|
-
source: { document
|
|
48
|
-
status:
|
|
49
|
-
versions:
|
|
50
|
-
workspace:
|
|
186
|
+
source: { document, line: index + 1, links: references(line) },
|
|
187
|
+
status: recipe ? `Automated recipe: ${recipe.id}` : 'Catalog recommendation; verify before adopting',
|
|
188
|
+
versions: versionList(selected),
|
|
189
|
+
workspace: byHeading.get(section)?.workspace ?? 'See catalog setup',
|
|
51
190
|
});
|
|
191
|
+
seenSections.add(section);
|
|
192
|
+
}
|
|
193
|
+
for (const declaredSection of sections) {
|
|
194
|
+
if (!seenSections.has(declaredSection.heading)) {
|
|
195
|
+
throw new Issue(`The catalog section "${declaredSection.heading}" has no "${declaredSection.header}" table.`);
|
|
196
|
+
}
|
|
52
197
|
}
|
|
53
|
-
if (
|
|
54
|
-
throw new Issue('No capability rows were found in
|
|
55
|
-
|
|
198
|
+
if (rows.length === 0)
|
|
199
|
+
throw new Issue('No capability rows were found in the catalog.');
|
|
200
|
+
for (const recipe of metadata?.recipes ?? []) {
|
|
201
|
+
const row = rows.find(({ id }) => id === recipe.capability);
|
|
202
|
+
if (!row)
|
|
203
|
+
throw new Issue(`Catalog recipe ${recipe.id} points at unknown capability "${recipe.capability}".`);
|
|
204
|
+
packagePin(row.selection, recipe.package);
|
|
205
|
+
}
|
|
206
|
+
return { metadata, rows };
|
|
207
|
+
}
|
|
208
|
+
export function entries(markdown, document) {
|
|
209
|
+
return compileCatalog(markdown, document).rows;
|
|
210
|
+
}
|
|
211
|
+
export function recipeVersion(rows, recipe) {
|
|
212
|
+
const row = rows.find(({ id }) => id === recipe.capability);
|
|
213
|
+
if (!row)
|
|
214
|
+
throw new Issue(`Catalog recipe ${recipe.id} points at unknown capability "${recipe.capability}".`);
|
|
215
|
+
return packagePin(row.selection, recipe.package);
|
|
56
216
|
}
|
|
57
217
|
export function lookup(catalog, capability) {
|
|
58
218
|
const id = slug(capability);
|
|
@@ -66,7 +226,7 @@ export function lookup(catalog, capability) {
|
|
|
66
226
|
return packages[0];
|
|
67
227
|
}
|
|
68
228
|
export default class List extends Command {
|
|
69
|
-
static description = 'List package and platform capabilities from
|
|
229
|
+
static description = 'List package and platform capabilities from the catalog';
|
|
70
230
|
static flags = { json: Flags.boolean({ description: 'Emit JSON' }) };
|
|
71
231
|
async run() {
|
|
72
232
|
const workflow = new Workflow('stack list');
|
|
@@ -76,8 +236,8 @@ export default class List extends Command {
|
|
|
76
236
|
const product = await findProduct();
|
|
77
237
|
if (product)
|
|
78
238
|
workflow.starterRevision = product.marker.starter;
|
|
79
|
-
const { digest, text } = await catalogDocument(product);
|
|
80
|
-
return { capabilities: entries(text), stackSha256: digest };
|
|
239
|
+
const { digest, file, text } = await catalogDocument(product);
|
|
240
|
+
return { capabilities: entries(text, file), stackSha256: digest };
|
|
81
241
|
}, (result) => result.capabilities.map(({ capability, id }) => `${id} ${capability}`).join('\n'));
|
|
82
242
|
}
|
|
83
243
|
}
|
|
@@ -13,8 +13,8 @@ export default class Show extends Command {
|
|
|
13
13
|
const product = await findProduct();
|
|
14
14
|
if (product)
|
|
15
15
|
workflow.starterRevision = product.marker.starter;
|
|
16
|
-
const { digest, text } = await catalogDocument(product);
|
|
17
|
-
const capability = lookup(entries(text), args.capability);
|
|
16
|
+
const { digest, file, text } = await catalogDocument(product);
|
|
17
|
+
const capability = lookup(entries(text, file), args.capability);
|
|
18
18
|
if (!capability)
|
|
19
19
|
throw new Issue(`Unknown capability "${args.capability}". Run jokebook stack list.`);
|
|
20
20
|
return { capability, stackSha256: digest };
|
|
@@ -23,6 +23,7 @@ export default class Show extends Command {
|
|
|
23
23
|
return [
|
|
24
24
|
row.capability,
|
|
25
25
|
row.selection,
|
|
26
|
+
`Versions: ${row.versions.join(', ') || 'Not pinned'}`,
|
|
26
27
|
`Workspace: ${row.workspace}`,
|
|
27
28
|
`Status: ${row.status}`,
|
|
28
29
|
`Setup: ${row.setup}`,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Upgrade extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
apply: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
|
+
check: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { catalogDocument, findProduct, Issue, release, Workflow } from '../index.js';
|
|
3
|
+
import { applyUpgrade, planUpgrade, publicPlan } from '../upgrade.js';
|
|
4
|
+
const usage = 'Try: jokebook upgrade [--check | --apply] [--json] (from a Jokebook product)';
|
|
5
|
+
export default class Upgrade extends Command {
|
|
6
|
+
static description = 'Merge a newer bundled starter into an existing product without discarding local edits';
|
|
7
|
+
static flags = {
|
|
8
|
+
apply: Flags.boolean({ default: false, description: 'Write the reviewed upgrade plan' }),
|
|
9
|
+
check: Flags.boolean({ default: false, description: 'Inspect the upgrade plan without writing anything' }),
|
|
10
|
+
json: Flags.boolean({ description: 'Emit a single JSON result' }),
|
|
11
|
+
};
|
|
12
|
+
async run() {
|
|
13
|
+
const workflow = new Workflow('upgrade');
|
|
14
|
+
await workflow.report(this.argv.includes('--json'), usage, async () => {
|
|
15
|
+
const { flags } = await this.parse(Upgrade);
|
|
16
|
+
if (flags.apply && flags.check)
|
|
17
|
+
throw new Issue('Use either --check or --apply, not both.');
|
|
18
|
+
if (process.versions.node !== release.node) {
|
|
19
|
+
throw new Issue(`Use Node.js ${release.node}. Found ${process.versions.node}.`);
|
|
20
|
+
}
|
|
21
|
+
const product = await findProduct();
|
|
22
|
+
if (!product)
|
|
23
|
+
throw new Issue('Run this command inside a product created by Jokebook.');
|
|
24
|
+
workflow.destination = product.cwd;
|
|
25
|
+
workflow.starterRevision = product.marker.starter;
|
|
26
|
+
workflow.stage = 'catalog';
|
|
27
|
+
const { digest, file } = await catalogDocument(product);
|
|
28
|
+
workflow.stage = 'upgrade';
|
|
29
|
+
const plan = await planUpgrade(product, digest, file);
|
|
30
|
+
if (flags.apply && plan.status !== 'up-to-date') {
|
|
31
|
+
const report = await applyUpgrade(product, plan);
|
|
32
|
+
workflow.stage = 'complete';
|
|
33
|
+
const outcome = { ...publicPlan(plan), applied: true, report };
|
|
34
|
+
return outcome;
|
|
35
|
+
}
|
|
36
|
+
workflow.stage = flags.apply ? 'complete' : 'plan';
|
|
37
|
+
const outcome = { ...publicPlan(plan), applied: false };
|
|
38
|
+
return outcome;
|
|
39
|
+
}, (result) => {
|
|
40
|
+
if (result.status === 'up-to-date') {
|
|
41
|
+
return `Starter ${result.to} and catalog ${result.catalog} are up to date.`;
|
|
42
|
+
}
|
|
43
|
+
const changes = result.actions.length;
|
|
44
|
+
const conflicts = result.conflicts.length;
|
|
45
|
+
if (result.status === 'blocked') {
|
|
46
|
+
return `Plan ${result.from} -> ${result.to}: ${changes} files change, ${conflicts} conflicts. ` +
|
|
47
|
+
'Resolve the conflicts before running jokebook upgrade --apply. No files were changed.';
|
|
48
|
+
}
|
|
49
|
+
if (result.applied) {
|
|
50
|
+
return `Upgraded ${result.from} -> ${result.to}. ${changes} files changed, ${conflicts} need review. Report: ${result.report}`;
|
|
51
|
+
}
|
|
52
|
+
return `Plan ${result.from} -> ${result.to}: ${changes} files change, ${conflicts} need review. Run jokebook upgrade --apply to write it.`;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly revision: "1.0.0";
|
|
5
|
-
readonly skillsCli: "1.9.1";
|
|
6
|
-
readonly stackSha256: "850953320cc8e9093b9c3286e4279596dbdd274319e2b60ab648977ae4e90307";
|
|
1
|
+
type Skill = {
|
|
2
|
+
name: string;
|
|
3
|
+
repo: string;
|
|
7
4
|
};
|
|
8
|
-
export declare const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
export declare const release: Readonly<{
|
|
6
|
+
catalog: string;
|
|
7
|
+
node: string;
|
|
8
|
+
npm: string;
|
|
9
|
+
pnpm: string;
|
|
10
|
+
revision: string;
|
|
11
|
+
skillsCli: string;
|
|
12
|
+
version: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const skills: Skill[];
|
|
15
|
+
export declare const catalogPath = "docs/STACK.md";
|
|
16
|
+
export declare const legacyCatalogPath = "STACK.md";
|
|
15
17
|
export declare const presets: {
|
|
16
18
|
desktop: string;
|
|
17
19
|
full: string;
|
|
@@ -26,11 +28,12 @@ export type Settings = {
|
|
|
26
28
|
recipes: string[];
|
|
27
29
|
};
|
|
28
30
|
export type ProductMarker = {
|
|
31
|
+
catalog?: string;
|
|
29
32
|
preset: string;
|
|
30
33
|
stackSha256: string;
|
|
31
34
|
starter: string;
|
|
32
35
|
};
|
|
33
|
-
type Product = {
|
|
36
|
+
export type Product = {
|
|
34
37
|
cwd: string;
|
|
35
38
|
marker: ProductMarker;
|
|
36
39
|
};
|
|
@@ -72,6 +75,7 @@ export declare function readJson<T>(file: string): Promise<T>;
|
|
|
72
75
|
export declare function findProduct(start?: string): Promise<Product | undefined>;
|
|
73
76
|
export declare function catalogDocument(product?: Product): Promise<{
|
|
74
77
|
digest: string;
|
|
78
|
+
file: string;
|
|
75
79
|
text: string;
|
|
76
80
|
}>;
|
|
77
81
|
export declare function slug(value: string): string;
|
package/dist/index.js
CHANGED
|
@@ -2,20 +2,28 @@ import { isCI } from 'ci-info';
|
|
|
2
2
|
import { execa } from 'execa';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import { lstat, readdir, readFile, realpath } from 'node:fs/promises';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { stripVTControlCharacters } from 'node:util';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const manifest = createRequire(import.meta.url)('../package.json');
|
|
10
|
+
const config = manifest.jokebook;
|
|
11
|
+
if (!config?.catalog || !config.starter || !config.pnpm || !config.skillsCli || !manifest.engines?.node ||
|
|
12
|
+
!manifest.engines.npm || !manifest.version) {
|
|
13
|
+
throw new Error('package.json is missing the release metadata Jokebook needs.');
|
|
14
|
+
}
|
|
15
|
+
export const release = Object.freeze({
|
|
16
|
+
catalog: config.catalog,
|
|
17
|
+
node: manifest.engines.node,
|
|
18
|
+
npm: manifest.engines.npm,
|
|
19
|
+
pnpm: config.pnpm,
|
|
20
|
+
revision: config.starter,
|
|
21
|
+
skillsCli: config.skillsCli,
|
|
22
|
+
version: manifest.version,
|
|
23
|
+
});
|
|
24
|
+
export const { skills } = config;
|
|
25
|
+
export const catalogPath = 'docs/STACK.md';
|
|
26
|
+
export const legacyCatalogPath = 'STACK.md';
|
|
19
27
|
export const presets = {
|
|
20
28
|
desktop: 'Web foundation and Tauri desktop',
|
|
21
29
|
full: 'Web, Tauri desktop and shared-Swift mobile',
|
|
@@ -67,7 +75,16 @@ export class Workflow {
|
|
|
67
75
|
const result = await execa(binary, args, {
|
|
68
76
|
cancelSignal: options.signal ?? this.controller.signal,
|
|
69
77
|
cwd,
|
|
70
|
-
env: {
|
|
78
|
+
env: {
|
|
79
|
+
CI: 'true',
|
|
80
|
+
FORCE_COLOR: undefined,
|
|
81
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
82
|
+
NO_COLOR: '1',
|
|
83
|
+
// `npm exec --package=@divithselvam/jokebook` exports this to the CLI.
|
|
84
|
+
// If it reaches the nested `npx skills@...` call, npx tries to run the
|
|
85
|
+
// outer package instead of the requested skills CLI.
|
|
86
|
+
npm_config_package: undefined,
|
|
87
|
+
},
|
|
71
88
|
reject: false,
|
|
72
89
|
stdin: 'ignore',
|
|
73
90
|
timeout: 300_000,
|
|
@@ -177,9 +194,9 @@ export async function readJson(file) {
|
|
|
177
194
|
}
|
|
178
195
|
export async function findProduct(start = process.cwd()) {
|
|
179
196
|
try {
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
return { cwd: start, marker:
|
|
197
|
+
const productManifest = await readJson(path.resolve(start, 'package.json'));
|
|
198
|
+
if (productManifest.jokebook?.starter && productManifest.jokebook.stackSha256) {
|
|
199
|
+
return { cwd: start, marker: productManifest.jokebook };
|
|
183
200
|
}
|
|
184
201
|
}
|
|
185
202
|
catch (error) {
|
|
@@ -189,14 +206,54 @@ export async function findProduct(start = process.cwd()) {
|
|
|
189
206
|
const parent = path.dirname(start);
|
|
190
207
|
return parent === start ? undefined : findProduct(parent);
|
|
191
208
|
}
|
|
209
|
+
async function readCatalog(file) {
|
|
210
|
+
try {
|
|
211
|
+
return await readFile(file, 'utf8');
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (error.code === 'ENOENT') {
|
|
215
|
+
throw new Issue('The bundled catalog is missing from this package. Reinstall Jokebook or run npm run build.');
|
|
216
|
+
}
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
192
220
|
export async function catalogDocument(product) {
|
|
193
|
-
|
|
194
|
-
|
|
221
|
+
if (product) {
|
|
222
|
+
const candidates = await Promise.all([catalogPath, legacyCatalogPath].map(async (candidate) => {
|
|
223
|
+
try {
|
|
224
|
+
return { file: candidate, text: await readFile(path.resolve(product.cwd, candidate), 'utf8') };
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (error.code === 'ENOENT')
|
|
228
|
+
return undefined;
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
232
|
+
const found = candidates.find((candidate) => candidate !== undefined);
|
|
233
|
+
if (!found) {
|
|
234
|
+
throw new Issue(`${catalogPath} is missing from this product. Restore the catalog recorded in package.json before continuing.`);
|
|
235
|
+
}
|
|
236
|
+
const digest = createHash('sha256').update(found.text).digest('hex');
|
|
237
|
+
if (digest !== product.marker.stackSha256) {
|
|
238
|
+
throw new Issue(`${found.file} differs from the recorded revision. Restore the original catalog before continuing.`);
|
|
239
|
+
}
|
|
240
|
+
return { ...found, digest };
|
|
241
|
+
}
|
|
242
|
+
const index = await readJson(packageFile('../dist/catalog/index.json')).catch((error) => {
|
|
243
|
+
if (error.code === 'ENOENT') {
|
|
244
|
+
throw new Issue('The bundled catalog index is missing from this package. Reinstall Jokebook or run npm run build.');
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
});
|
|
248
|
+
if (index.catalog !== release.catalog) {
|
|
249
|
+
throw new Issue(`The bundled catalog is ${index.catalog}, but this CLI requires ${release.catalog}. Reinstall Jokebook.`);
|
|
250
|
+
}
|
|
251
|
+
const text = await readCatalog(packageFile('../dist/catalog/STACK.md'));
|
|
195
252
|
const digest = createHash('sha256').update(text).digest('hex');
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return { digest, text };
|
|
253
|
+
if (digest !== index.sha256) {
|
|
254
|
+
throw new Issue('The bundled catalog does not match its recorded SHA-256. Reinstall Jokebook.');
|
|
255
|
+
}
|
|
256
|
+
return { digest, file: catalogPath, text };
|
|
200
257
|
}
|
|
201
258
|
export function slug(value) {
|
|
202
259
|
return value.toLowerCase().replaceAll(/[^a-z0-9]+/gv, '-').replaceAll(/^-|-$/gv, '');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Preset } from './index.js';
|
|
2
|
+
export type StarterIndex = {
|
|
3
|
+
catalog: string;
|
|
4
|
+
catalogSha256: string;
|
|
5
|
+
current: string;
|
|
6
|
+
revisions: string[];
|
|
7
|
+
surfaces: Record<string, string[]>;
|
|
8
|
+
};
|
|
9
|
+
export declare function starterIndex(): Promise<StarterIndex>;
|
|
10
|
+
export declare function starterArchive(revision: string, surface: string): string;
|
|
11
|
+
export declare function extractStarter(revision: string, preset: Preset, destination: string): Promise<{
|
|
12
|
+
base: string;
|
|
13
|
+
surfaces: string[];
|
|
14
|
+
}>;
|
package/dist/starter.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { extract } from 'tar';
|
|
4
|
+
import { Issue, packageFile, readJson } from './index.js';
|
|
5
|
+
export async function starterIndex() {
|
|
6
|
+
try {
|
|
7
|
+
return await readJson(packageFile('../dist/starters/index.json'));
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error.code === 'ENOENT') {
|
|
11
|
+
throw new Issue('The bundled starter index is missing. Reinstall Jokebook or run npm run build.');
|
|
12
|
+
}
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function starterArchive(revision, surface) {
|
|
17
|
+
return packageFile(`../dist/starters/${revision}/${surface}.tgz`);
|
|
18
|
+
}
|
|
19
|
+
export async function extractStarter(revision, preset, destination) {
|
|
20
|
+
const index = await starterIndex();
|
|
21
|
+
if (!index.revisions.includes(revision)) {
|
|
22
|
+
throw new Issue(`Starter ${revision} is not bundled with this CLI. Available revisions: ${index.revisions.join(', ')}.`);
|
|
23
|
+
}
|
|
24
|
+
const base = preset === 'desktop' || preset === 'full' ? 'desktop' : 'web';
|
|
25
|
+
await mkdir(destination, { recursive: true });
|
|
26
|
+
const surfaces = index.surfaces[revision] ?? [];
|
|
27
|
+
if (!surfaces.includes(base))
|
|
28
|
+
throw new Issue(`Starter ${revision} does not contain the ${base} archive.`);
|
|
29
|
+
await extract({ cwd: destination, file: starterArchive(revision, base), strict: true });
|
|
30
|
+
if (preset === 'mobile' || preset === 'full') {
|
|
31
|
+
if (!surfaces.includes('mobile'))
|
|
32
|
+
throw new Issue(`Starter ${revision} does not contain the mobile overlay.`);
|
|
33
|
+
const apps = path.join(destination, 'apps');
|
|
34
|
+
await mkdir(apps, { recursive: true });
|
|
35
|
+
await extract({ cwd: apps, file: starterArchive(revision, 'mobile'), strict: true });
|
|
36
|
+
}
|
|
37
|
+
return { base, surfaces };
|
|
38
|
+
}
|
|
Binary file
|