@usequeek/create-theme 0.4.2 → 0.5.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,24 +1,429 @@
1
1
  {
2
- "$comment": "The only keys a template's `for` may use (theme.config.ts default_demo.for / demos[].for). `services` are the slugs a vendor registers as; `catalogue` is the marketplace product taxonomy, root -> branches, and `subcategories` a branch -> its own children; each key is the Str::slug of the category name. The backend reads a vendor's business from what they actually sell and ranks a specific (branch) match above a broad one. Agreed with queek_backend 24/9/26 (storefront-theme-templates-contract.md, R2.1; jewelry and beverages R2.5); change it only together with the backend.",
2
+ "$comment": "The only keys a template's `for` may use (theme.config.ts default_demo.for / demos[].for). `services` are the slugs a vendor registers as; `catalogue` is the marketplace product taxonomy, root -> branches, and `subcategories` a branch -> its own children; each key is the Str::slug of the category name. The backend reads a vendor's business from what they actually sell and ranks a specific (branch) match above a broad one. Agreed with queek_backend (storefront-theme-templates-contract.md, R2.1; jewelry R2.5; production snapshot R2.9); change it only together with the backend.",
3
+ "version": "d1f9c8eefc91ed3b2c834345458c62343f465ce6",
3
4
  "services": [
4
- "foods", "local-meals", "shawarma-pizza-snacks", "suya", "boli", "fruits-fresh-natural",
5
- "meat-fish", "supermarket", "groceries", "shop-groceries", "local-market", "pharmacy",
6
- "health-wellness-store", "fashion", "beauty-cosmetics", "electronics", "phones-accessories",
7
- "home-living", "baby-kids", "office-school", "shop", "laundry", "gas-refill", "home-cleaning",
8
- "car-wash"
5
+ "baby-kids",
6
+ "beauty-cosmetics",
7
+ "electronics",
8
+ "fashion",
9
+ "foods",
10
+ "gas-refill",
11
+ "groceries",
12
+ "health-wellness-store",
13
+ "home-living",
14
+ "laundry",
15
+ "office-school",
16
+ "pharmacy",
17
+ "phones-accessories",
18
+ "shop",
19
+ "shop-groceries",
20
+ "supermarket"
9
21
  ],
10
22
  "catalogue": {
11
- "fashion": ["womens-fashion", "mens-fashion", "kids-fashion", "shoes", "bags-accessories", "modest-occasion-wear"],
12
- "beauty-personal-care": ["makeup", "skincare", "hair-care-styling", "fragrance", "wigs-extensions-hair-accessories", "personal-care", "beauty-tools-devices"],
13
- "electronics": ["computers-laptops", "tv-home-entertainment", "gaming-consoles", "cameras-drones", "smart-home-security", "power-solar"],
14
- "phones-tablets": ["smartphones", "tablets-e-readers", "smartwatches-wearables", "chargers-power-banks", "earbuds-headsets", "cases-screen-protection", "phone-repair-replacement"],
15
- "home-living": ["furniture", "home-decor", "kitchen-dining", "bedding-bath", "lighting-electrical", "storage-organization"],
16
- "baby-kids": ["baby-gear", "feeding-nursing", "diapering-potty", "baby-clothing", "kids-clothing", "toys-games", "school-essentials", "nursery-safety"],
17
- "health-wellness": ["vitamins-supplements", "personal-care-hygiene", "fitness-recovery", "sexual-wellness", "medical-supplies", "health-devices", "healthy-living"],
18
- "office-school": ["stationery-writing", "office-supplies", "school-supplies", "bags-lunch-gear", "office-furniture", "printers-accessories", "tech-for-school-office"],
19
- "supermarket": ["beverages"]
23
+ "baby-kids": [
24
+ "baby-clothing",
25
+ "baby-gear",
26
+ "diapering-potty",
27
+ "feeding-nursing",
28
+ "kids-clothing",
29
+ "nursery-safety",
30
+ "school-essentials",
31
+ "toys-games"
32
+ ],
33
+ "beauty-personal-care": [
34
+ "beauty-tools-devices",
35
+ "fragrance",
36
+ "hair-care-styling",
37
+ "makeup",
38
+ "personal-care",
39
+ "skincare",
40
+ "wigs-extensions-hair-accessories"
41
+ ],
42
+ "electronics": [
43
+ "cameras-drones",
44
+ "computers-laptops",
45
+ "gaming-consoles",
46
+ "power-solar",
47
+ "smart-home-security",
48
+ "tv-home-entertainment"
49
+ ],
50
+ "fashion": [
51
+ "bags-accessories",
52
+ "kids-fashion",
53
+ "mens-fashion",
54
+ "modest-occasion-wear",
55
+ "shoes",
56
+ "womens-fashion"
57
+ ],
58
+ "health-wellness": [
59
+ "fitness-recovery",
60
+ "health-devices",
61
+ "healthy-living",
62
+ "medical-supplies",
63
+ "personal-care-hygiene",
64
+ "sexual-wellness",
65
+ "vitamins-supplements"
66
+ ],
67
+ "home-living": [
68
+ "bedding-bath",
69
+ "furniture",
70
+ "home-decor",
71
+ "kitchen-dining",
72
+ "lighting-electrical",
73
+ "storage-organization"
74
+ ],
75
+ "office-school": [
76
+ "bags-lunch-gear",
77
+ "office-furniture",
78
+ "office-supplies",
79
+ "printers-accessories",
80
+ "school-supplies",
81
+ "stationery-writing",
82
+ "tech-for-school-office"
83
+ ],
84
+ "phones-tablets": [
85
+ "cases-screen-protection",
86
+ "chargers-power-banks",
87
+ "earbuds-headsets",
88
+ "phone-repair-replacement",
89
+ "smartphones",
90
+ "smartwatches-wearables",
91
+ "tablets-e-readers"
92
+ ]
20
93
  },
21
94
  "subcategories": {
22
- "bags-accessories": ["jewelry"]
95
+ "baby-clothing": [
96
+ "newborn-clothing",
97
+ "sets",
98
+ "sleepsuits",
99
+ "socks-caps"
100
+ ],
101
+ "baby-gear": [
102
+ "car-seats",
103
+ "carriers",
104
+ "strollers",
105
+ "walkers"
106
+ ],
107
+ "bags-accessories": [
108
+ "backpacks",
109
+ "handbags",
110
+ "jewelry",
111
+ "wallets",
112
+ "watches"
113
+ ],
114
+ "bags-lunch-gear": [
115
+ "backpacks",
116
+ "lunch-bags",
117
+ "pencil-cases",
118
+ "water-bottles"
119
+ ],
120
+ "beauty-tools-devices": [
121
+ "beauty-blenders",
122
+ "makeup-brushes",
123
+ "nail-tools",
124
+ "skincare-devices"
125
+ ],
126
+ "bedding-bath": [
127
+ "bathroom-accessories",
128
+ "bedsheets",
129
+ "pillows-duvets",
130
+ "towels"
131
+ ],
132
+ "cameras-drones": [
133
+ "cameras",
134
+ "drones",
135
+ "lenses",
136
+ "photography-accessories"
137
+ ],
138
+ "cases-screen-protection": [
139
+ "phone-cases",
140
+ "screen-protectors",
141
+ "tablet-covers"
142
+ ],
143
+ "chargers-power-banks": [
144
+ "cables",
145
+ "car-chargers",
146
+ "power-banks",
147
+ "wall-chargers",
148
+ "wireless-chargers"
149
+ ],
150
+ "computers-laptops": [
151
+ "desktop-pcs",
152
+ "keyboards-mice",
153
+ "laptops",
154
+ "monitors",
155
+ "storage-devices"
156
+ ],
157
+ "diapering-potty": [
158
+ "changing-accessories",
159
+ "diapers",
160
+ "potty-training",
161
+ "wipes"
162
+ ],
163
+ "earbuds-headsets": [
164
+ "bluetooth-earbuds",
165
+ "headphones",
166
+ "phone-headsets",
167
+ "speakers"
168
+ ],
169
+ "feeding-nursing": [
170
+ "bibs",
171
+ "bottles",
172
+ "breast-pumps",
173
+ "feeding-accessories"
174
+ ],
175
+ "fitness-recovery": [
176
+ "exercise-equipment",
177
+ "massage-recovery",
178
+ "support-braces",
179
+ "yoga-pilates"
180
+ ],
181
+ "fragrance": [
182
+ "body-mists",
183
+ "gift-sets",
184
+ "perfumes"
185
+ ],
186
+ "furniture": [
187
+ "beds-mattresses",
188
+ "chairs-stools",
189
+ "sofas",
190
+ "tables-desks",
191
+ "wardrobes-storage"
192
+ ],
193
+ "gaming-consoles": [
194
+ "consoles",
195
+ "gaming-accessories",
196
+ "gaming-chairs"
197
+ ],
198
+ "hair-care-styling": [
199
+ "hair-tools",
200
+ "hair-treatments",
201
+ "shampoo-conditioner",
202
+ "styling-products"
203
+ ],
204
+ "health-devices": [
205
+ "nebulizers",
206
+ "oximeters",
207
+ "posture-wellness-devices",
208
+ "weighing-scales"
209
+ ],
210
+ "healthy-living": [
211
+ "digestive-health",
212
+ "healthy-snacks",
213
+ "herbal-products",
214
+ "sleep-support"
215
+ ],
216
+ "home-decor": [
217
+ "decorative-accessories",
218
+ "mirrors",
219
+ "rugs-curtains",
220
+ "wall-art"
221
+ ],
222
+ "kids-clothing": [
223
+ "boys-clothing",
224
+ "girls-clothing",
225
+ "school-wear"
226
+ ],
227
+ "kids-fashion": [
228
+ "baby-clothing",
229
+ "boys-clothing",
230
+ "girls-clothing",
231
+ "school-wear"
232
+ ],
233
+ "kitchen-dining": [
234
+ "cookware",
235
+ "dinnerware",
236
+ "kitchen-storage",
237
+ "small-kitchen-appliances"
238
+ ],
239
+ "lighting-electrical": [
240
+ "ceiling-lights",
241
+ "electrical-fittings",
242
+ "lamps",
243
+ "outdoor-lighting"
244
+ ],
245
+ "makeup": [
246
+ "eye-makeup",
247
+ "face-makeup",
248
+ "lip-makeup",
249
+ "makeup-sets"
250
+ ],
251
+ "medical-supplies": [
252
+ "blood-pressure-monitors",
253
+ "first-aid",
254
+ "glucose-monitors",
255
+ "thermometers"
256
+ ],
257
+ "mens-fashion": [
258
+ "native-wear",
259
+ "shirts",
260
+ "t-shirts-polos",
261
+ "trousers-jeans",
262
+ "underwear-sleepwear"
263
+ ],
264
+ "modest-occasion-wear": [
265
+ "aso-ebi",
266
+ "bridal-occasion",
267
+ "kaftans-abayas",
268
+ "suits-blazers"
269
+ ],
270
+ "nursery-safety": [
271
+ "baby-monitors",
272
+ "cots-cribs",
273
+ "nursery-bedding",
274
+ "safety-gates"
275
+ ],
276
+ "office-furniture": [
277
+ "desks",
278
+ "office-chairs",
279
+ "shelves",
280
+ "whiteboards"
281
+ ],
282
+ "office-supplies": [
283
+ "desk-accessories",
284
+ "filing-organization",
285
+ "laminating-binding",
286
+ "paper-products"
287
+ ],
288
+ "personal-care": [
289
+ "bath-body",
290
+ "feminine-care",
291
+ "grooming",
292
+ "oral-care"
293
+ ],
294
+ "personal-care-hygiene": [
295
+ "bath-body",
296
+ "deodorants",
297
+ "feminine-care",
298
+ "oral-care"
299
+ ],
300
+ "phone-repair-replacement": [
301
+ "phone-batteries",
302
+ "repair-tools",
303
+ "replacement-screens"
304
+ ],
305
+ "power-solar": [
306
+ "batteries-ups",
307
+ "extension-surge-protectors",
308
+ "inverters",
309
+ "solar-panels"
310
+ ],
311
+ "printers-accessories": [
312
+ "ink-toner",
313
+ "printer-accessories",
314
+ "printers",
315
+ "printing-paper"
316
+ ],
317
+ "school-essentials": [
318
+ "lunch-boxes",
319
+ "school-bags",
320
+ "stationery",
321
+ "water-bottles"
322
+ ],
323
+ "school-supplies": [
324
+ "classroom-supplies",
325
+ "exam-essentials",
326
+ "exercise-books",
327
+ "geometry-sets"
328
+ ],
329
+ "sexual-wellness": [
330
+ "condoms",
331
+ "intimate-care",
332
+ "lubricants",
333
+ "performance-support"
334
+ ],
335
+ "shoes": [
336
+ "kids-shoes",
337
+ "men-shoes",
338
+ "slides-sandals",
339
+ "women-shoes"
340
+ ],
341
+ "skincare": [
342
+ "cleansers",
343
+ "face-masks",
344
+ "moisturizers",
345
+ "serums",
346
+ "sunscreens"
347
+ ],
348
+ "smart-home-security": [
349
+ "cctv-security",
350
+ "networking",
351
+ "smart-home-devices"
352
+ ],
353
+ "smartphones": [
354
+ "android-phones",
355
+ "iphones",
356
+ "refurbished-phones"
357
+ ],
358
+ "smartwatches-wearables": [
359
+ "fitness-bands",
360
+ "gps-wearables",
361
+ "smartwatches"
362
+ ],
363
+ "stationery-writing": [
364
+ "art-supplies",
365
+ "markers-highlighters",
366
+ "notebooks",
367
+ "pens-pencils"
368
+ ],
369
+ "storage-organization": [
370
+ "closet-organizers",
371
+ "laundry-storage",
372
+ "shelving",
373
+ "utility-storage"
374
+ ],
375
+ "tablets-e-readers": [
376
+ "e-readers",
377
+ "kids-tablets",
378
+ "tablets"
379
+ ],
380
+ "tech-for-school-office": [
381
+ "calculators",
382
+ "computer-accessories",
383
+ "laptops",
384
+ "projectors"
385
+ ],
386
+ "toys-games": [
387
+ "board-games",
388
+ "dolls-action-figures",
389
+ "learning-toys",
390
+ "outdoor-toys"
391
+ ],
392
+ "tv-home-entertainment": [
393
+ "home-audio",
394
+ "projectors",
395
+ "streaming-devices",
396
+ "televisions",
397
+ "tv-accessories"
398
+ ],
399
+ "vitamins-supplements": [
400
+ "immunity-support",
401
+ "multivitamins",
402
+ "sports-nutrition",
403
+ "weight-management"
404
+ ],
405
+ "wigs-extensions-hair-accessories": [
406
+ "extensions",
407
+ "hair-accessories",
408
+ "human-hair-wigs",
409
+ "synthetic-wigs",
410
+ "wigs"
411
+ ],
412
+ "womens-fashion": [
413
+ "dresses",
414
+ "lingerie-sleepwear",
415
+ "skirts-shorts",
416
+ "tops-tees"
417
+ ]
418
+ },
419
+ "root_service": {
420
+ "baby-kids": "baby-kids",
421
+ "beauty-personal-care": "beauty-cosmetics",
422
+ "electronics": "electronics",
423
+ "fashion": "fashion",
424
+ "health-wellness": "health-wellness-store",
425
+ "home-living": "home-living",
426
+ "office-school": "office-school",
427
+ "phones-tablets": "phones-accessories"
23
428
  }
24
429
  }
package/dist/index.d.ts CHANGED
@@ -3,12 +3,13 @@ import { type Answers } from './setup.js';
3
3
  export { UsageError, CancelledError, type Flags, type Prompter, type PackageManager } from './options.js';
4
4
  export { setupTheme, type Answers } from './setup.js';
5
5
  export { clackPrompter } from './prompts.js';
6
+ export { bundledLists, cachedLists, createLists, getActiveLists, setActiveLists, SHOP_HINT, SHOP_KEY, SHOP_LABEL, type BusinessLists, type BusinessOption, type ListsData } from './lists.js';
6
7
  /** The rename `npm create` applies to the starter, for tools that copy a theme under a new name (Queek's `yarn theme:new`). */
7
8
  export { renameTheme, SKELETON, type Identity } from './rename.js';
8
9
  /** The starter this release was tested with: its tag matches this package's version (`yarn starter:publish --tag`). */
9
10
  export declare const STARTER: string;
10
11
  export declare function detectPackageManager(userAgent?: string): PackageManager;
11
- export declare const HELP = "Create a Queek storefront theme.\n\n npm create @usequeek/theme@latest my-theme -- --templates laundry --tags minimal\n pnpm create @usequeek/theme my-theme --templates laundry --tags minimal\n\nnpm needs -- before these flags. In a terminal, anything you leave out is asked,\nand with no folder the folder is named after the theme (my-theme with --yes or no terminal).\n\n --name <text> theme name (default: the folder name)\n --templates <keys> businesses to make templates for, comma-separated (required with --yes)\n --primary <key> the main template (default: the first)\n --categories <keys> business categories (default: the templates')\n --tags <tags> 1\u20136 tags for the look (required with --yes)\n --pages <list|none> extra pages: contact, faq (default: both)\n --ai <list>, --no-ai AI assistants: claude, gemini (default: both; AGENTS.md unless --no-ai)\n --pm <npm|pnpm|yarn|bun>, --no-install, --no-git\n --yes, -y never prompt; take the default for everything else\n --dry-run print what would be written; write nothing\n --force allow a folder that is not empty\n --template <source> another starter: a giget source or a local folder";
12
+ export declare const HELP = "Create a Queek storefront theme.\n\n npm create @usequeek/theme@latest my-theme -- --templates laundry --tags minimal\n pnpm create @usequeek/theme my-theme --templates laundry --tags minimal\n\nnpm needs -- before these flags. In a terminal, anything you leave out is asked,\nand with no folder the folder is named after the theme (my-theme with --yes or no terminal).\n\n --name <text> theme name (default: the folder name)\n --templates <keys> businesses to make templates for, comma-separated (required with --yes)\n --primary <key> the main template (default: the first)\n --categories <keys> business categories (default: the templates')\n --tags <tags> 1\u20136 tags for the look (required with --yes)\n --pages <list|none> extra pages: contact, faq (default: both)\n --ai <list>, --no-ai AI assistants: claude, gemini (default: both; AGENTS.md unless --no-ai)\n --pm <npm|pnpm|yarn|bun>, --no-install, --no-git\n --yes, -y never prompt; take the default for everything else\n --dry-run print what would be written; write nothing\n --force allow a folder that is not empty\n --template <source> another starter: a giget source or a local folder\n --vocabulary <file> a pinned vocabulary file (default: the live copy)\n --offline use the bundled vocabulary snapshot; no network";
12
13
  export declare function createTheme(dir: string, answers: Answers, options: {
13
14
  install: boolean;
14
15
  git: boolean;
@@ -16,11 +17,17 @@ export declare function createTheme(dir: string, answers: Answers, options: {
16
17
  dryRun: boolean;
17
18
  force: boolean;
18
19
  template?: string;
20
+ offline?: boolean;
21
+ vocabularyFile?: string;
19
22
  log?: (line: string) => void;
20
23
  }): Promise<void>;
21
24
  /**
22
25
  * Flags → answers (prompting when a prompter is given) → the theme. Shared by the CLI and `queek-theme init`.
23
26
  * With no folder argument, a person at the prompts gets a folder named after the theme's slug (checked
24
27
  * with the name, before the next question); a script gets `my-theme`.
28
+ *
29
+ * The prompts ask from the cached-or-bundled copy at once while a live
30
+ * refresh runs in the background; the final `for` is validated against the
31
+ * fresh copy when it has arrived, else the copy the prompts used.
25
32
  */
26
33
  export declare function runCreate(flags: Flags, prompter: Prompter | null, log?: (line: string) => void): Promise<void>;
package/dist/index.js CHANGED
@@ -3,11 +3,14 @@ import { cpSync, existsSync, lstatSync, mkdtempSync, readFileSync, readdirSync,
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join, relative, resolve } from 'node:path';
5
5
  import { downloadTemplate } from 'giget';
6
+ import { parseVocabularyData, resolveVocabulary } from '@usequeek/theme-check';
7
+ import { bundledLists, cachedLists, createLists, getActiveLists, setActiveLists } from './lists.js';
6
8
  import { UsageError, equivalentCommand, resolveAnswers, shellWord } from './options.js';
7
9
  import { setupTheme } from './setup.js';
8
10
  export { UsageError, CancelledError } from './options.js';
9
11
  export { setupTheme } from './setup.js';
10
12
  export { clackPrompter } from './prompts.js';
13
+ export { bundledLists, cachedLists, createLists, getActiveLists, setActiveLists, SHOP_HINT, SHOP_KEY, SHOP_LABEL } from './lists.js';
11
14
  /** The rename `npm create` applies to the starter, for tools that copy a theme under a new name (Queek's `yarn theme:new`). */
12
15
  export { renameTheme, SKELETON } from './rename.js';
13
16
  const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
@@ -36,7 +39,9 @@ and with no folder the folder is named after the theme (my-theme with --yes or n
36
39
  --yes, -y never prompt; take the default for everything else
37
40
  --dry-run print what would be written; write nothing
38
41
  --force allow a folder that is not empty
39
- --template <source> another starter: a giget source or a local folder`;
42
+ --template <source> another starter: a giget source or a local folder
43
+ --vocabulary <file> a pinned vocabulary file (default: the live copy)
44
+ --offline use the bundled vocabulary snapshot; no network`;
40
45
  function targetState(dir) {
41
46
  if (!existsSync(dir))
42
47
  return 'missing';
@@ -208,7 +213,7 @@ export async function createTheme(dir, answers, options) {
208
213
  log(` ${run} dev # preview every template`);
209
214
  log(` ${run} check # your to-do list: each template's description, its own home and screenshot, your products and photos`);
210
215
  log('');
211
- log(`To repeat this setup: ${equivalentCommand(options.pm, dir, answers, { template: options.template, install: options.install, git: options.git })}`);
216
+ log(`To repeat this setup: ${equivalentCommand(options.pm, dir, answers, { template: options.template, install: options.install, git: options.git, offline: options.offline, vocabularyFile: options.vocabularyFile })}`);
212
217
  }
213
218
  /** Why `dir` cannot take the theme (`checkTarget`'s message), or null. */
214
219
  function targetProblem(dir, force) {
@@ -222,10 +227,59 @@ function targetProblem(dir, force) {
222
227
  throw error;
223
228
  }
224
229
  }
230
+ /**
231
+ * The lists the prompts ask from: a pinned file when `--vocabulary` is given
232
+ * (validated — an unreadable or invalid file is a usage error), else the
233
+ * cached copy when one is stored, else the bundled snapshot. Synchronous, so
234
+ * the first question never waits on the network.
235
+ */
236
+ function startingLists(flags) {
237
+ const bundled = bundledLists();
238
+ const withBundledLabels = (data) => createLists({
239
+ services: data.services,
240
+ catalogue: data.catalogue,
241
+ subcategories: data.subcategories,
242
+ root_service: data.root_service,
243
+ // A copy from before labels were stored still gets the bundled names.
244
+ labels: data.labels ?? Object.fromEntries(bundled.businessKeys.map((key) => [key, bundled.labelOf(key)])),
245
+ });
246
+ if (flags.vocabularyFile !== undefined) {
247
+ let raw;
248
+ try {
249
+ raw = readFileSync(resolve(flags.vocabularyFile), 'utf8');
250
+ }
251
+ catch (error) {
252
+ throw new UsageError(`Cannot read --vocabulary ${flags.vocabularyFile} (${error.message}).`);
253
+ }
254
+ let parsed;
255
+ try {
256
+ parsed = JSON.parse(raw);
257
+ }
258
+ catch {
259
+ throw new UsageError(`--vocabulary ${flags.vocabularyFile} is not valid JSON.`);
260
+ }
261
+ try {
262
+ const data = typeof parsed.data === 'object' && parsed.data !== null
263
+ ? parseVocabularyData(parsed.data, { requireVersion: false })
264
+ : parseVocabularyData(parsed, { requireVersion: false });
265
+ return withBundledLabels(data);
266
+ }
267
+ catch (error) {
268
+ throw new UsageError(`--vocabulary ${flags.vocabularyFile} is not a vocabulary (${error.message}).`);
269
+ }
270
+ }
271
+ if (flags.offline)
272
+ return bundled;
273
+ return cachedLists() ?? bundled;
274
+ }
225
275
  /**
226
276
  * Flags → answers (prompting when a prompter is given) → the theme. Shared by the CLI and `queek-theme init`.
227
277
  * With no folder argument, a person at the prompts gets a folder named after the theme's slug (checked
228
278
  * with the name, before the next question); a script gets `my-theme`.
279
+ *
280
+ * The prompts ask from the cached-or-bundled copy at once while a live
281
+ * refresh runs in the background; the final `for` is validated against the
282
+ * fresh copy when it has arrived, else the copy the prompts used.
229
283
  */
230
284
  export async function runCreate(flags, prompter, log) {
231
285
  const named = flags.dir === undefined && prompter !== null;
@@ -234,7 +288,40 @@ export async function runCreate(flags, prompter, log) {
234
288
  const pm = flags.pm ?? detectPackageManager();
235
289
  if (!['npm', 'pnpm', 'yarn', 'bun'].includes(pm))
236
290
  throw new UsageError(`--pm must be npm, pnpm, yarn or bun, not "${pm}".`);
237
- const answers = await resolveAnswers(flags, prompter, named ? (slug) => targetProblem(slug, flags.force) : undefined);
238
- const dir = flags.dir ?? (named ? answers.slug : 'my-theme');
239
- await createTheme(dir, answers, { install: flags.install, git: flags.git, pm, dryRun: flags.dryRun, force: flags.force, template: flags.template, log });
291
+ const previous = getActiveLists();
292
+ const starting = startingLists(flags);
293
+ setActiveLists(starting);
294
+ // Started at launch, awaited after the answers: the prompts never wait on it.
295
+ const refresh = !flags.offline && flags.vocabularyFile === undefined
296
+ ? resolveVocabulary({ mode: 'live' }).then((resolved) => resolved, () => null)
297
+ : null;
298
+ try {
299
+ const answers = await resolveAnswers(flags, prompter, named ? (slug) => targetProblem(slug, flags.force) : undefined, starting);
300
+ const fresh = refresh ? await refresh : null;
301
+ if (fresh) {
302
+ if (fresh.notice && log)
303
+ log(fresh.notice);
304
+ const lists = createLists({
305
+ services: fresh.vocabulary.services,
306
+ catalogue: fresh.vocabulary.catalogue,
307
+ subcategories: fresh.vocabulary.subcategories,
308
+ root_service: fresh.vocabulary.root_service,
309
+ labels: fresh.vocabulary.labels ?? Object.fromEntries(starting.businessKeys.map((key) => [key, starting.labelOf(key)])),
310
+ });
311
+ const unknown = answers.templates.map((t) => t.key).filter((key) => !lists.businessKeys.includes(key));
312
+ if (unknown.length > 0) {
313
+ throw new UsageError(`The live vocabulary no longer has ${unknown.map((key) => `"${key}"`).join(', ')} — pick from: ${lists.businessKeys.join(', ')}.`);
314
+ }
315
+ const unknownCategories = answers.categories.filter((key) => !lists.services.includes(key));
316
+ if (unknownCategories.length > 0) {
317
+ throw new UsageError(`The live vocabulary no longer has the categor${unknownCategories.length === 1 ? 'y' : 'ies'} ${unknownCategories.map((key) => `"${key}"`).join(', ')}.`);
318
+ }
319
+ setActiveLists(lists);
320
+ }
321
+ const dir = flags.dir ?? (named ? answers.slug : 'my-theme');
322
+ await createTheme(dir, answers, { install: flags.install, git: flags.git, pm, dryRun: flags.dryRun, force: flags.force, template: flags.template, offline: flags.offline, vocabularyFile: flags.vocabularyFile, log });
323
+ }
324
+ finally {
325
+ setActiveLists(previous);
326
+ }
240
327
  }
package/dist/lists.d.ts CHANGED
@@ -1,3 +1,47 @@
1
+ /** One vocabulary copy as the pickers read it. */
2
+ export interface ListsData {
3
+ services: string[];
4
+ catalogue: Record<string, string[]>;
5
+ subcategories: Record<string, string[]>;
6
+ root_service?: Record<string, string>;
7
+ labels?: Record<string, string>;
8
+ }
9
+ export interface BusinessOption {
10
+ value: string;
11
+ label: string;
12
+ hint?: string;
13
+ }
14
+ /** `shop` in the pickers: last, under this name, with this hint. It is for a general store only. */
15
+ export declare const SHOP_KEY = "shop";
16
+ export declare const SHOP_LABEL = "General store";
17
+ export declare const SHOP_HINT = "pick a specific business; this is for a general store only";
18
+ /** One vocabulary copy's pickers: services, niches, labels, categories. */
19
+ export interface BusinessLists {
20
+ /** Business categories, `shop` last. */
21
+ services: readonly string[];
22
+ /** Catalogue keys that are not also a business category. */
23
+ niches: readonly string[];
24
+ /** Every key: services plus niches. */
25
+ businessKeys: readonly string[];
26
+ /** The business category any key belongs to (`jewelry` → `fashion`). */
27
+ categoryOf: (key: string) => string;
28
+ /** The display name of any key, from the vocabulary's labels. */
29
+ labelOf: (key: string) => string;
30
+ /** The templates picker: services (`shop` last) then niches, `shop` as "General store". */
31
+ templateOptions: () => BusinessOption[];
32
+ /** The categories picker: services, `shop` last and as "General store". */
33
+ categoryOptions: () => BusinessOption[];
34
+ }
35
+ /** The pickers for one vocabulary copy. */
36
+ export declare function createLists(data: ListsData): BusinessLists;
37
+ /** The bundled copy: the synced vocabulary plus the synced labels. */
38
+ export declare function bundledLists(): BusinessLists;
39
+ /** The lists the current run prompts from (runCreate sets these at launch). */
40
+ export declare function getActiveLists(): BusinessLists;
41
+ /** Set the lists the current run prompts from. runCreate restores the bundled copy when it finishes. */
42
+ export declare function setActiveLists(lists: BusinessLists): void;
43
+ /** The cached copy, synchronously, for prompts that must ask before any fetch returns. Null when absent or invalid. */
44
+ export declare function cachedLists(): BusinessLists | null;
1
45
  /** Business categories: what a vendor picks at setup (R2.7). */
2
46
  export declare const SERVICES: readonly string[];
3
47
  /** Catalogue keys that are not also a business category: a template for one kind of product. */