@usequeek/create-theme 0.4.2 → 0.5.2

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/dist/lists.js CHANGED
@@ -3,46 +3,120 @@
3
3
  * (their source of truth, synced by `yarn tools:sync-lists` there): no network
4
4
  * before a question is asked, and the same vocabulary the checker of this
5
5
  * release enforces.
6
+ *
7
+ * A run's lists are a BusinessLists built from one vocabulary copy: the
8
+ * cached-or-bundled copy while prompting, the live copy for the final check
9
+ * (see runCreate). Labels and root→service come from that copy's
10
+ * `labels`/`root_service` — no hand-kept maps. The module-level constants are
11
+ * the bundled copy, for compatibility.
6
12
  */
13
+ import { readCachedVocabulary } from '@usequeek/theme-check';
7
14
  import vocabulary from './data/business-vocabulary.json' with { type: 'json' };
8
15
  import labels from './data/business-labels.json' with { type: 'json' };
9
16
  import tags from './data/theme-tags.json' with { type: 'json' };
10
17
  import reserved from './data/reserved.json' with { type: 'json' };
11
- const CATALOGUE = vocabulary.catalogue;
12
- const SUBCATEGORIES = vocabulary.subcategories;
13
- /** Business categories: what a vendor picks at setup (R2.7). */
14
- export const SERVICES = vocabulary.services;
15
- const ROOT_OF = new Map();
16
- for (const [root, branches] of Object.entries(CATALOGUE)) {
17
- ROOT_OF.set(root, root);
18
- for (const branch of branches)
19
- ROOT_OF.set(branch, root);
18
+ /** `shop` in the pickers: last, under this name, with this hint. It is for a general store only. */
19
+ export const SHOP_KEY = 'shop';
20
+ export const SHOP_LABEL = 'General store';
21
+ export const SHOP_HINT = 'pick a specific business; this is for a general store only';
22
+ function rootsOf(data) {
23
+ const roots = new Map();
24
+ for (const [root, branches] of Object.entries(data.catalogue)) {
25
+ roots.set(root, root);
26
+ for (const branch of branches)
27
+ roots.set(branch, root);
28
+ }
29
+ for (const [branch, children] of Object.entries(data.subcategories)) {
30
+ for (const child of children)
31
+ roots.set(child, roots.get(branch) ?? branch);
32
+ }
33
+ return roots;
34
+ }
35
+ /** The pickers for one vocabulary copy. */
36
+ export function createLists(data) {
37
+ const roots = rootsOf(data);
38
+ const labelsOf = data.labels ?? {};
39
+ const rootService = data.root_service ?? {};
40
+ const services = [...data.services.filter((key) => key !== SHOP_KEY), ...data.services.filter((key) => key === SHOP_KEY)];
41
+ const niches = [...roots.keys()].filter((key) => !data.services.includes(key));
42
+ // `shop` is offered dead last whatever kind of key it is: it is for a general store only.
43
+ const hasShop = data.services.includes(SHOP_KEY) || niches.includes(SHOP_KEY);
44
+ const servicesNoShop = services.filter((key) => key !== SHOP_KEY);
45
+ const nichesNoShop = niches.filter((key) => key !== SHOP_KEY);
46
+ const businessKeys = [...servicesNoShop, ...nichesNoShop, ...(hasShop ? [SHOP_KEY] : [])];
47
+ const categoryOf = (key) => {
48
+ if (data.services.includes(key))
49
+ return key;
50
+ const root = roots.get(key) ?? key;
51
+ return data.services.includes(root) ? root : (rootService[root] ?? root);
52
+ };
53
+ const labelOf = (key) => labelsOf[key] ?? key;
54
+ const option = (key, hint) => key === SHOP_KEY
55
+ ? { value: key, label: SHOP_LABEL, hint: SHOP_HINT }
56
+ : { value: key, label: labelOf(key), hint };
57
+ return {
58
+ services,
59
+ niches,
60
+ businessKeys,
61
+ categoryOf,
62
+ labelOf,
63
+ templateOptions: () => [
64
+ ...servicesNoShop.map((key) => option(key, 'business category')),
65
+ ...nichesNoShop.map((key) => option(key, `niche · ${labelOf(categoryOf(key))}`)),
66
+ ...(hasShop ? [option(SHOP_KEY, 'business category')] : []),
67
+ ],
68
+ categoryOptions: () => services.map((key) => option(key, 'business category')),
69
+ };
20
70
  }
21
- for (const [branch, children] of Object.entries(SUBCATEGORIES)) {
22
- for (const child of children)
23
- ROOT_OF.set(child, ROOT_OF.get(branch) ?? branch);
71
+ /** The bundled copy: the synced vocabulary plus the synced labels. */
72
+ export function bundledLists() {
73
+ return createLists({
74
+ services: vocabulary.services,
75
+ catalogue: vocabulary.catalogue,
76
+ subcategories: vocabulary.subcategories,
77
+ root_service: vocabulary.root_service,
78
+ labels: (labels.labels ?? {}),
79
+ });
24
80
  }
81
+ const BUNDLED = bundledLists();
82
+ let active = BUNDLED;
83
+ /** The lists the current run prompts from (runCreate sets these at launch). */
84
+ export function getActiveLists() {
85
+ return active;
86
+ }
87
+ /** Set the lists the current run prompts from. runCreate restores the bundled copy when it finishes. */
88
+ export function setActiveLists(lists) {
89
+ active = lists;
90
+ }
91
+ /** The cached copy, synchronously, for prompts that must ask before any fetch returns. Null when absent or invalid. */
92
+ export function cachedLists() {
93
+ const cached = readCachedVocabulary();
94
+ if (!cached)
95
+ return null;
96
+ const bundled = BUNDLED;
97
+ return createLists({
98
+ services: cached.services,
99
+ catalogue: cached.catalogue,
100
+ subcategories: cached.subcategories,
101
+ root_service: cached.root_service,
102
+ // A cache from before labels were stored still gets the bundled names.
103
+ labels: cached.labels ?? Object.fromEntries(bundled.businessKeys.map((key) => [key, bundled.labelOf(key)])),
104
+ });
105
+ }
106
+ /** Business categories: what a vendor picks at setup (R2.7). */
107
+ export const SERVICES = BUNDLED.services;
25
108
  /** Catalogue keys that are not also a business category: a template for one kind of product. */
26
- export const NICHES = [...ROOT_OF.keys()].filter((key) => !SERVICES.includes(key));
27
- export const BUSINESS_KEYS = [...SERVICES, ...NICHES];
109
+ export const NICHES = BUNDLED.niches;
110
+ export const BUSINESS_KEYS = BUNDLED.businessKeys;
28
111
  export const TAGS = tags.tags;
29
112
  export const RESERVED_SLUGS = reserved.slugs;
30
113
  export const RESERVED_PREFIXES = reserved.prefixes;
31
- /** Catalogue roots that are not a business category, and the category their vendors pick. */
32
- const ROOT_SERVICE = {
33
- 'beauty-personal-care': 'beauty-cosmetics',
34
- 'phones-tablets': 'phones-accessories',
35
- 'health-wellness': 'health-wellness-store',
36
- };
37
114
  /** The business category any key belongs to (`jewelry` → `fashion`). */
38
115
  export function categoryOf(key) {
39
- if (SERVICES.includes(key))
40
- return key;
41
- const root = ROOT_OF.get(key) ?? key;
42
- return SERVICES.includes(root) ? root : (ROOT_SERVICE[root] ?? root);
116
+ return BUNDLED.categoryOf(key);
43
117
  }
44
118
  export function labelOf(key) {
45
- return labels.labels[key] ?? key;
119
+ return BUNDLED.labelOf(key);
46
120
  }
47
121
  function distance(a, b) {
48
122
  const row = Array.from({ length: b.length + 1 }, (_, i) => i);
package/dist/naming.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type BusinessLists } from './lists.js';
1
2
  /** `Mọ́ Laundry & Co.` → `mo-laundry-co`: what `yarn theme:pull` accepts, `^[a-z][a-z0-9-]{1,30}$`. */
2
3
  export declare function slugify(name: string): string;
3
4
  /** Why a slug cannot be used, or null. */
@@ -25,6 +26,6 @@ export interface TemplatePlan {
25
26
  * niche a niche one — either way `for` is just that key, so a niche never
26
27
  * names a category (R2.7).
27
28
  */
28
- export declare function planTemplates(keys: string[], primary?: string): TemplatePlan[];
29
+ export declare function planTemplates(keys: string[], primary?: string, lists?: BusinessLists): TemplatePlan[];
29
30
  /** The business categories the templates belong to, once each, in order. */
30
- export declare function defaultCategories(keys: string[]): string[];
31
+ export declare function defaultCategories(keys: string[], lists?: BusinessLists): string[];
package/dist/naming.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RESERVED_PREFIXES, RESERVED_SLUGS, categoryOf, labelOf } from './lists.js';
1
+ import { RESERVED_PREFIXES, RESERVED_SLUGS, getActiveLists } from './lists.js';
2
2
  /** `Mọ́ Laundry & Co.` → `mo-laundry-co`: what `yarn theme:pull` accepts, `^[a-z][a-z0-9-]{1,30}$`. */
3
3
  export function slugify(name) {
4
4
  let slug = name.normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase()
@@ -35,15 +35,15 @@ export function prefixFor(slug) {
35
35
  * niche a niche one — either way `for` is just that key, so a niche never
36
36
  * names a category (R2.7).
37
37
  */
38
- export function planTemplates(keys, primary) {
38
+ export function planTemplates(keys, primary, lists = getActiveLists()) {
39
39
  const unique = [...new Set(keys)];
40
40
  if (unique.length === 0)
41
41
  return [];
42
42
  const first = primary && unique.includes(primary) ? primary : unique[0];
43
43
  const ordered = [first, ...unique.filter((key) => key !== first)];
44
- return ordered.map((key, index) => ({ id: index === 0 ? 'default' : key, key, template: key, label: labelOf(key), for: [key], primary: index === 0 }));
44
+ return ordered.map((key, index) => ({ id: index === 0 ? 'default' : key, key, template: key, label: lists.labelOf(key), for: [key], primary: index === 0 }));
45
45
  }
46
46
  /** The business categories the templates belong to, once each, in order. */
47
- export function defaultCategories(keys) {
48
- return [...new Set(keys.map(categoryOf))];
47
+ export function defaultCategories(keys, lists = getActiveLists()) {
48
+ return [...new Set(keys.map((key) => lists.categoryOf(key)))];
49
49
  }
package/dist/options.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type BusinessLists } from './lists.js';
1
2
  import type { Answers, Assistant, OptionalPage } from './setup.js';
2
3
  export declare class UsageError extends Error {
3
4
  readonly exitCode = 2;
@@ -24,6 +25,10 @@ export interface Flags {
24
25
  force: boolean;
25
26
  /** Where the starter comes from: a giget source or a local folder. Default: the pinned starter. */
26
27
  template?: string;
28
+ /** Use the bundled vocabulary snapshot; no network. */
29
+ offline?: boolean;
30
+ /** A pinned vocabulary file the prompts and the final check read instead. */
31
+ vocabularyFile?: string;
27
32
  }
28
33
  export interface Prompter {
29
34
  /** Ask until `problem` has nothing to say about the name: a bad name must never end the run. */
@@ -44,7 +49,7 @@ export declare function nameProblem(name: string): string | null;
44
49
  * so no answer is lost after it is given. `folderProblem` (a folder named after the slug) is checked
45
50
  * with the name.
46
51
  */
47
- export declare function resolveAnswers(flags: Flags, prompter: Prompter | null, folderProblem?: (slug: string) => string | null): Promise<Answers>;
52
+ export declare function resolveAnswers(flags: Flags, prompter: Prompter | null, folderProblem?: (slug: string) => string | null, lists?: BusinessLists): Promise<Answers>;
48
53
  /** `text` as one POSIX shell word: quoted only when it has a space or a shell-special character. */
49
54
  export declare const shellWord: (text: string) => string;
50
55
  /**
@@ -55,4 +60,6 @@ export declare function equivalentCommand(pm: PackageManager, dir: string, answe
55
60
  template?: string;
56
61
  install?: boolean;
57
62
  git?: boolean;
63
+ offline?: boolean;
64
+ vocabularyFile?: string;
58
65
  }): string;
package/dist/options.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { basename, resolve } from 'node:path';
2
- import { BUSINESS_KEYS, SERVICES, TAGS, nearest } from './lists.js';
2
+ import { TAGS, getActiveLists, nearest } from './lists.js';
3
3
  import { defaultCategories, planTemplates, prefixFor, slugProblem, slugify } from './naming.js';
4
4
  export class UsageError extends Error {
5
5
  exitCode = 2;
@@ -36,21 +36,21 @@ const tagsProblem = (tags) => (tags.length < 1 || tags.length > 6 ? 'Pick 1 to 6
36
36
  * so no answer is lost after it is given. `folderProblem` (a folder named after the slug) is checked
37
37
  * with the name.
38
38
  */
39
- export async function resolveAnswers(flags, prompter, folderProblem) {
39
+ export async function resolveAnswers(flags, prompter, folderProblem, lists = getActiveLists()) {
40
40
  // Flags first: a typo in one must not cost the answers to the questions before it.
41
41
  const keyFlag = csv(flags.templates);
42
42
  if (keyFlag) {
43
43
  if (keyFlag.length === 0)
44
44
  throw new UsageError('Pick at least one business for --templates.');
45
- checkAll('business', '--templates', keyFlag, BUSINESS_KEYS);
45
+ checkAll('business', '--templates', keyFlag, lists.businessKeys);
46
46
  }
47
47
  if (flags.primary !== undefined)
48
- checkAll('business', '--primary', [flags.primary], BUSINESS_KEYS);
48
+ checkAll('business', '--primary', [flags.primary], lists.businessKeys);
49
49
  const categoryFlag = csv(flags.categories);
50
50
  if (categoryFlag) {
51
51
  if (categoryFlag.length === 0)
52
52
  throw new UsageError('Pick at least one business category for --categories.');
53
- checkAll('category', '--categories', categoryFlag, SERVICES);
53
+ checkAll('category', '--categories', categoryFlag, lists.services);
54
54
  }
55
55
  const tagFlag = csv(flags.tags);
56
56
  if (tagFlag) {
@@ -74,20 +74,20 @@ export async function resolveAnswers(flags, prompter, folderProblem) {
74
74
  const problem = slugProblem(slug) ?? folderProblem?.(slug);
75
75
  if (problem)
76
76
  throw new UsageError(problem);
77
- const keys = keyFlag ?? (prompter ? await prompter.templates() : required('--templates', BUSINESS_KEYS));
77
+ const keys = keyFlag ?? (prompter ? await prompter.templates() : required('--templates', lists.businessKeys));
78
78
  if (keys.length === 0)
79
79
  throw new UsageError('Pick at least one business for --templates.');
80
- checkAll('business', '--templates', keys, BUSINESS_KEYS);
80
+ checkAll('business', '--templates', keys, lists.businessKeys);
81
81
  const unique = [...new Set(keys)];
82
82
  const primary = flags.primary ?? (prompter && unique.length > 1 && flags.templates === undefined ? await prompter.primary(unique) : unique[0]);
83
83
  if (!unique.includes(primary))
84
84
  throw new UsageError(`--primary "${primary}" is not one of --templates (${unique.join(', ')}).`);
85
- const templates = planTemplates(unique, primary);
85
+ const templates = planTemplates(unique, primary, lists);
86
86
  const categories = categoryFlag
87
- ?? (prompter ? await prompter.categories(defaultCategories(templates.map((t) => t.key))) : defaultCategories(templates.map((t) => t.key)));
87
+ ?? (prompter ? await prompter.categories(defaultCategories(templates.map((t) => t.key), lists)) : defaultCategories(templates.map((t) => t.key), lists));
88
88
  if (categories.length === 0)
89
89
  throw new UsageError('Pick at least one business category for --categories.');
90
- checkAll('category', '--categories', categories, SERVICES);
90
+ checkAll('category', '--categories', categories, lists.services);
91
91
  const tags = tagFlag ?? (prompter ? await prompter.tags(tagsProblem) : required('--tags', TAGS));
92
92
  if (tags.length === 0 || tags.length > 6)
93
93
  throw new UsageError('Pick 1 to 6 --tags.');
@@ -116,6 +116,8 @@ export function equivalentCommand(pm, dir, answers, given = {}) {
116
116
  ...(given.template !== undefined ? [`--template ${shellWord(given.template)}`] : []),
117
117
  ...(given.install === false ? ['--no-install'] : []),
118
118
  ...(given.git === false ? ['--no-git'] : []),
119
+ ...(given.offline ? ['--offline'] : []),
120
+ ...(given.vocabularyFile !== undefined ? [`--vocabulary ${shellWord(given.vocabularyFile)}`] : []),
119
121
  ].join(' ');
120
122
  return pm === 'npm' ? `npm create @usequeek/theme@latest ${shellWord(dir)} -- ${flags}` : `${pm} create @usequeek/theme ${shellWord(dir)} ${flags}`;
121
123
  }
package/dist/prompts.d.ts CHANGED
@@ -1,13 +1,14 @@
1
+ import { type BusinessLists, type BusinessOption } from './lists.js';
1
2
  import { type Prompter } from './options.js';
2
3
  /**
3
4
  * Ask until the answer has no problem, warning each time and starting the next ask from the
4
5
  * last answer: clack 1.8's multiselect has no `validate`, and a bad pick must not end the run.
5
6
  */
6
7
  export declare function askUntil<T>(ask: (previous: T | undefined) => Promise<T>, problem: (value: T) => string | undefined, warn: (message: string) => void): Promise<T>;
7
- /** Business categories first, then niches: clack 1.8 has no grouped autocomplete, so each hint names its group. */
8
- export declare const templateOptions: () => {
9
- value: string;
10
- label: string;
11
- hint: string;
12
- }[];
13
- export declare function clackPrompter(): Prompter;
8
+ /**
9
+ * The business picker: services, then niches, `shop` dead last as "General
10
+ * store" with its hint. clack 1.8 has no grouped autocomplete, so each hint
11
+ * names its group.
12
+ */
13
+ export declare const templateOptions: (lists?: BusinessLists) => BusinessOption[];
14
+ export declare function clackPrompter(lists?: BusinessLists): Prompter;
package/dist/prompts.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as p from '@clack/prompts';
2
- import { NICHES, SERVICES, TAGS, categoryOf, labelOf } from './lists.js';
2
+ import { TAGS, getActiveLists } from './lists.js';
3
3
  import { slugify } from './naming.js';
4
4
  import { CancelledError } from './options.js';
5
5
  function answer(value) {
@@ -22,14 +22,22 @@ export async function askUntil(ask, problem, warn) {
22
22
  previous = value;
23
23
  }
24
24
  }
25
- const businessOption = (key) => ({
26
- value: key,
27
- label: labelOf(key),
28
- hint: SERVICES.includes(key) ? 'business category' : `niche · ${labelOf(categoryOf(key))}`,
29
- });
30
- /** Business categories first, then niches: clack 1.8 has no grouped autocomplete, so each hint names its group. */
31
- export const templateOptions = () => [...SERVICES, ...NICHES].map(businessOption);
32
- export function clackPrompter() {
25
+ /**
26
+ * The business picker: services, then niches, `shop` dead last as "General
27
+ * store" with its hint. clack 1.8 has no grouped autocomplete, so each hint
28
+ * names its group.
29
+ */
30
+ export const templateOptions = (lists = getActiveLists()) => lists.templateOptions();
31
+ const serviceOption = (lists, key) => {
32
+ const found = lists.categoryOptions().find((option) => option.value === key);
33
+ if (!found)
34
+ throw new Error(`unknown business category "${key}"`);
35
+ return found;
36
+ };
37
+ export function clackPrompter(lists) {
38
+ // Read at each question, not at construction: runCreate sets the run's
39
+ // lists (cached-or-bundled, then live) after the caller builds the prompter.
40
+ const current = () => lists ?? getActiveLists();
33
41
  return {
34
42
  async name(initial, problem) {
35
43
  const typed = answer(await p.text({ message: 'Theme name', placeholder: initial, defaultValue: initial, validate: (v) => problem(v?.trim() || initial) }));
@@ -38,13 +46,15 @@ export function clackPrompter() {
38
46
  return name;
39
47
  },
40
48
  async templates() {
41
- return answer(await p.autocompleteMultiselect({ message: 'Businesses to make templates for (type to search)', options: templateOptions(), required: true }));
49
+ return answer(await p.autocompleteMultiselect({ message: 'Businesses to make templates for (type to search)', options: templateOptions(current()), required: true }));
42
50
  },
43
51
  async primary(keys) {
44
- return answer(await p.select({ message: 'Which template is the main one (the theme\'s first impression)?', options: keys.map(businessOption) }));
52
+ const options = templateOptions(current()).filter((option) => keys.includes(option.value));
53
+ return answer(await p.select({ message: 'Which template is the main one (the theme\'s first impression)?', options: keys.map((key) => options.find((option) => option.value === key) ?? { value: key, label: key }) }));
45
54
  },
46
55
  async categories(initial) {
47
- return answer(await p.multiselect({ message: 'Business categories the theme serves', options: SERVICES.map((key) => ({ value: key, label: labelOf(key) })), initialValues: initial, required: true }));
56
+ const resolved = current();
57
+ return answer(await p.multiselect({ message: 'Business categories the theme serves', options: resolved.services.map((key) => serviceOption(resolved, key)), initialValues: initial, required: true }));
48
58
  },
49
59
  async tags(problem) {
50
60
  return askUntil(async (previous) => answer(await p.multiselect({ message: 'Tags: the look (1–6)', options: TAGS.map((tag) => ({ value: tag, label: tag })), initialValues: previous, required: true })), problem, (message) => p.log.warn(message));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/create-theme",
3
- "version": "0.4.2",
3
+ "version": "0.5.2",
4
4
  "description": "npm create @usequeek/theme — start a Queek storefront theme from the official starter.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@clack/prompts": "^1.8.1",
25
+ "@usequeek/theme-check": "^0.5.1",
25
26
  "giget": "^3.3.1"
26
27
  },
27
28
  "keywords": [