@divithselvam/jokebook 1.0.0 → 1.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.
@@ -1,58 +1,218 @@
1
1
  import { Command, Flags } from '@oclif/core';
2
+ import path from 'node:path';
2
3
  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
- };
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: 'services/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
- export function entries(markdown) {
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(`STACK.md does not pin ${packageName} for its automated recipe.`);
123
+ return match[1];
124
+ }
125
+ export function compileCatalog(markdown) {
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(`STACK.md 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
- const result = [];
23
- for (const [index, line] of markdown.split('\n').entries()) {
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 (line.startsWith('| Capability |') || (section === 'The decision' && line.startsWith('| Surface |'))) {
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 (!isReadingTable || line.startsWith('|---'))
170
+ if (!isDeclaredTable || line.startsWith('|---'))
35
171
  continue;
36
- const [, label, selected, notes] = line.split('|').map((cell) => cell.trim());
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
- result.push({
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 === 'runtime-validation' ? id : null,
182
+ recipe: recipe?.id,
44
183
  section,
45
184
  selection: withoutReferences(selected),
46
185
  setup: withoutReferences(notes),
47
186
  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',
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(`STACK.md section "${declaredSection.heading}" has no "${declaredSection.header}" table.`);
196
+ }
52
197
  }
53
- if (result.length === 0)
198
+ if (rows.length === 0)
54
199
  throw new Issue('No capability rows were found in STACK.md.');
55
- return result;
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) {
209
+ return compileCatalog(markdown).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);
@@ -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 } = await catalogDocument(product);
28
+ workflow.stage = 'upgrade';
29
+ const plan = await planUpgrade(product, digest);
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,17 @@
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";
1
+ type Skill = {
2
+ name: string;
3
+ repo: string;
7
4
  };
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
- }];
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
15
  export declare const presets: {
16
16
  desktop: string;
17
17
  full: string;
@@ -26,11 +26,12 @@ export type Settings = {
26
26
  recipes: string[];
27
27
  };
28
28
  export type ProductMarker = {
29
+ catalog?: string;
29
30
  preset: string;
30
31
  stackSha256: string;
31
32
  starter: string;
32
33
  };
33
- type Product = {
34
+ export type Product = {
34
35
  cwd: string;
35
36
  marker: ProductMarker;
36
37
  };
package/dist/index.js CHANGED
@@ -2,20 +2,26 @@ 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
- 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
- ];
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;
19
25
  export const presets = {
20
26
  desktop: 'Web foundation and Tauri desktop',
21
27
  full: 'Web, Tauri desktop and shared-Swift mobile',
@@ -67,7 +73,16 @@ export class Workflow {
67
73
  const result = await execa(binary, args, {
68
74
  cancelSignal: options.signal ?? this.controller.signal,
69
75
  cwd,
70
- env: { CI: 'true', FORCE_COLOR: undefined, GIT_TERMINAL_PROMPT: '0', NO_COLOR: '1' },
76
+ env: {
77
+ CI: 'true',
78
+ FORCE_COLOR: undefined,
79
+ GIT_TERMINAL_PROMPT: '0',
80
+ NO_COLOR: '1',
81
+ // `npm exec --package=@divithselvam/jokebook` exports this to the CLI.
82
+ // If it reaches the nested `npx skills@...` call, npx tries to run the
83
+ // outer package instead of the requested skills CLI.
84
+ npm_config_package: undefined,
85
+ },
71
86
  reject: false,
72
87
  stdin: 'ignore',
73
88
  timeout: 300_000,
@@ -177,9 +192,9 @@ export async function readJson(file) {
177
192
  }
178
193
  export async function findProduct(start = process.cwd()) {
179
194
  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 };
195
+ const productManifest = await readJson(path.resolve(start, 'package.json'));
196
+ if (productManifest.jokebook?.starter && productManifest.jokebook.stackSha256) {
197
+ return { cwd: start, marker: productManifest.jokebook };
183
198
  }
184
199
  }
185
200
  catch (error) {
@@ -189,13 +204,49 @@ export async function findProduct(start = process.cwd()) {
189
204
  const parent = path.dirname(start);
190
205
  return parent === start ? undefined : findProduct(parent);
191
206
  }
207
+ async function readCatalog(file) {
208
+ try {
209
+ return await readFile(file, 'utf8');
210
+ }
211
+ catch (error) {
212
+ if (error.code === 'ENOENT') {
213
+ throw new Issue('The bundled catalog is missing from this package. Reinstall Jokebook or run npm run build.');
214
+ }
215
+ throw error;
216
+ }
217
+ }
192
218
  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');
219
+ if (product) {
220
+ let text;
221
+ try {
222
+ text = await readFile(path.resolve(product.cwd, 'STACK.md'), 'utf8');
223
+ }
224
+ catch (error) {
225
+ if (error.code === 'ENOENT') {
226
+ throw new Issue('STACK.md is missing from this product. Restore the catalog recorded in package.json before continuing.');
227
+ }
228
+ throw error;
229
+ }
230
+ const digest = createHash('sha256').update(text).digest('hex');
231
+ if (digest !== product.marker.stackSha256) {
232
+ throw new Issue('STACK.md differs from the recorded revision. Restore the original catalog before continuing.');
233
+ }
234
+ return { digest, text };
235
+ }
236
+ const index = await readJson(packageFile('../dist/catalog/index.json')).catch((error) => {
237
+ if (error.code === 'ENOENT') {
238
+ throw new Issue('The bundled catalog index is missing from this package. Reinstall Jokebook or run npm run build.');
239
+ }
240
+ throw error;
241
+ });
242
+ if (index.catalog !== release.catalog) {
243
+ throw new Issue(`The bundled catalog is ${index.catalog}, but this CLI requires ${release.catalog}. Reinstall Jokebook.`);
244
+ }
245
+ const text = await readCatalog(packageFile('../dist/catalog/STACK.md'));
195
246
  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.');
247
+ if (digest !== index.sha256) {
248
+ throw new Issue('The bundled catalog does not match its recorded SHA-256. Reinstall Jokebook.');
249
+ }
199
250
  return { digest, text };
200
251
  }
201
252
  export function slug(value) {
@@ -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
+ }>;
@@ -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
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,21 @@
1
+ {
2
+ "catalog": "1.1.0",
3
+ "catalogSha256": "14f8bf06942076bf593e89e20f6413677fbf8f0cf4aee9151fbe87e604150e17",
4
+ "current": "1.1.0",
5
+ "revisions": [
6
+ "1.0.0",
7
+ "1.1.0"
8
+ ],
9
+ "surfaces": {
10
+ "1.0.0": [
11
+ "desktop",
12
+ "mobile",
13
+ "web"
14
+ ],
15
+ "1.1.0": [
16
+ "desktop",
17
+ "mobile",
18
+ "web"
19
+ ]
20
+ }
21
+ }
@@ -0,0 +1,30 @@
1
+ import { type Product, type ProductMarker } from './index.js';
2
+ type Action = 'add' | 'conflict' | 'merge' | 'remove' | 'update';
3
+ type Content = Uint8Array;
4
+ type Write = {
5
+ content: Content;
6
+ mode: number;
7
+ };
8
+ export type UpgradeAction = {
9
+ action: Action;
10
+ path: string;
11
+ reason?: string;
12
+ };
13
+ export type UpgradePlan = {
14
+ actions: UpgradeAction[];
15
+ catalog: string;
16
+ conflicts: UpgradeAction[];
17
+ from: string;
18
+ marker: ProductMarker;
19
+ preset: string;
20
+ stackSha256: string;
21
+ status: 'blocked' | 'ready' | 'up-to-date';
22
+ to: string;
23
+ warnings: string[];
24
+ writes: Map<string, Write>;
25
+ };
26
+ export type UpgradeResult = Omit<UpgradePlan, 'marker' | 'writes'>;
27
+ export declare function publicPlan(plan: UpgradePlan): UpgradeResult;
28
+ export declare function planUpgrade(product: Product, currentDigest: string): Promise<UpgradePlan>;
29
+ export declare function applyUpgrade(product: Product, plan: UpgradePlan): Promise<string>;
30
+ export {};