@usequeek/create-theme 0.4.0 → 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.
- package/dist/cli.js +2 -0
- package/dist/data/business-labels.json +277 -31
- package/dist/data/business-vocabulary.json +421 -16
- package/dist/index.d.ts +8 -1
- package/dist/index.js +92 -5
- package/dist/lists.d.ts +44 -0
- package/dist/lists.js +99 -25
- package/dist/naming.d.ts +3 -2
- package/dist/naming.js +5 -5
- package/dist/options.d.ts +8 -1
- package/dist/options.js +12 -10
- package/dist/prompts.d.ts +8 -7
- package/dist/prompts.js +22 -12
- package/dist/rename.d.ts +10 -4
- package/dist/rename.js +53 -8
- package/package.json +2 -1
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
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 =
|
|
27
|
-
export const BUSINESS_KEYS =
|
|
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
|
-
|
|
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
|
|
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,
|
|
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 {
|
|
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,
|
|
45
|
+
checkAll('business', '--templates', keyFlag, lists.businessKeys);
|
|
46
46
|
}
|
|
47
47
|
if (flags.primary !== undefined)
|
|
48
|
-
checkAll('business', '--primary', [flags.primary],
|
|
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,
|
|
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',
|
|
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,
|
|
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,
|
|
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
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 {
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/dist/rename.d.ts
CHANGED
|
@@ -8,15 +8,21 @@ export declare const SKELETON: Identity;
|
|
|
8
8
|
/**
|
|
9
9
|
* Rename one file's identity as TOKENS: the root class (`theme-bare`), the demo
|
|
10
10
|
* ids (`demo-bare`, `demo-bare-home`), every class token (`bare-main
|
|
11
|
-
* bare-product` — both), the display name (`Bare`) and the slug (`bare`).
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* bare-product` — both), the display name (`Bare`) and the slug (`bare`). A
|
|
12
|
+
* real theme adds more shapes of the same identity: CSS custom properties
|
|
13
|
+
* (`--md-accent`), data attributes (`data-md-open`), component heads
|
|
14
|
+
* (`MedleyModalLayer`), store ids (`medley-food`) and preview paths
|
|
15
|
+
* (`/medley~food`, via the slug token — `~` is a token edge). The skeleton
|
|
16
|
+
* keeps the English word "bare" out of its copy so every remaining standalone
|
|
17
|
+
* token is identity.
|
|
14
18
|
*
|
|
15
19
|
* The display name and the slug go in ONE pass (an alternation), so a name that
|
|
16
20
|
* holds the old slug as a word ("simply bare") is never rewritten by the slug
|
|
17
21
|
* pass. Nothing the earlier passes write can match it: the slug they write
|
|
18
22
|
* follows a `-` and a class prefix is followed by one, and a token has a `-` on
|
|
19
|
-
* neither side
|
|
23
|
+
* neither side — a store id (`<slug>-<id>`) keeps that shape, and a component
|
|
24
|
+
* head is only ever followed by an uppercase letter, which the token pass
|
|
25
|
+
* never spans.
|
|
20
26
|
*/
|
|
21
27
|
export declare function renameContent(content: string, ext: string, from: Identity, to: Identity): string;
|
|
22
28
|
/** Rename every text file of a theme folder in place. */
|
package/dist/rename.js
CHANGED
|
@@ -4,6 +4,20 @@ import { extname, join } from 'node:path';
|
|
|
4
4
|
export const SKELETON = { slug: 'bare', prefix: 'bare', name: 'Bare' };
|
|
5
5
|
const TEXT = new Set(['.ts', '.tsx', '.css', '.json', '.md', '.mdx']);
|
|
6
6
|
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
7
|
+
/**
|
|
8
|
+
* A URL (`https?://…` up to whitespace or a quote) names a hosted thing, not
|
|
9
|
+
* the copy: the source theme's art lives under its own folder until it is
|
|
10
|
+
* rehosted, so URLs stay out of every pass below.
|
|
11
|
+
*/
|
|
12
|
+
const URL = /(https?:\/\/[^\s'"`<>]*)/g;
|
|
13
|
+
/** `Sole Theory` → `SoleTheory`: the display name as the head of a component identifier. */
|
|
14
|
+
function pascalCase(name) {
|
|
15
|
+
return name
|
|
16
|
+
.split(/[^A-Za-z0-9]+/)
|
|
17
|
+
.filter((word) => word.length > 0)
|
|
18
|
+
.map((word) => word.slice(0, 1).toUpperCase() + word.slice(1))
|
|
19
|
+
.join('');
|
|
20
|
+
}
|
|
7
21
|
/** The display name as a literal of the file it is written into. */
|
|
8
22
|
function literal(ext, text) {
|
|
9
23
|
if (ext === '.json')
|
|
@@ -22,23 +36,54 @@ function literal(ext, text) {
|
|
|
22
36
|
/**
|
|
23
37
|
* Rename one file's identity as TOKENS: the root class (`theme-bare`), the demo
|
|
24
38
|
* ids (`demo-bare`, `demo-bare-home`), every class token (`bare-main
|
|
25
|
-
* bare-product` — both), the display name (`Bare`) and the slug (`bare`).
|
|
26
|
-
*
|
|
27
|
-
*
|
|
39
|
+
* bare-product` — both), the display name (`Bare`) and the slug (`bare`). A
|
|
40
|
+
* real theme adds more shapes of the same identity: CSS custom properties
|
|
41
|
+
* (`--md-accent`), data attributes (`data-md-open`), component heads
|
|
42
|
+
* (`MedleyModalLayer`), store ids (`medley-food`) and preview paths
|
|
43
|
+
* (`/medley~food`, via the slug token — `~` is a token edge). The skeleton
|
|
44
|
+
* keeps the English word "bare" out of its copy so every remaining standalone
|
|
45
|
+
* token is identity.
|
|
28
46
|
*
|
|
29
47
|
* The display name and the slug go in ONE pass (an alternation), so a name that
|
|
30
48
|
* holds the old slug as a word ("simply bare") is never rewritten by the slug
|
|
31
49
|
* pass. Nothing the earlier passes write can match it: the slug they write
|
|
32
50
|
* follows a `-` and a class prefix is followed by one, and a token has a `-` on
|
|
33
|
-
* neither side
|
|
51
|
+
* neither side — a store id (`<slug>-<id>`) keeps that shape, and a component
|
|
52
|
+
* head is only ever followed by an uppercase letter, which the token pass
|
|
53
|
+
* never spans.
|
|
34
54
|
*/
|
|
35
55
|
export function renameContent(content, ext, from, to) {
|
|
36
56
|
const nameOrSlug = new RegExp(`(?<![\\w-])(?:(${escape(from.name)})|${escape(from.slug)})(?![\\w-])`, 'g');
|
|
57
|
+
const rootClass = new RegExp(`(?<![\\w-])theme-${escape(from.slug)}(?![\\w-])`, 'g');
|
|
58
|
+
const demoId = new RegExp(`(?<![\\w-])demo-${escape(from.slug)}(?![\\w])`, 'g');
|
|
59
|
+
const storeId = new RegExp(`(?<![\\w-])${escape(from.slug)}-(?=[\\w$])`, 'g');
|
|
60
|
+
const cssVar = new RegExp(`--${escape(from.prefix)}-`, 'g');
|
|
61
|
+
const dataAttr = new RegExp(`data-${escape(from.prefix)}-`, 'g');
|
|
62
|
+
const classToken = new RegExp(`(?<![\\w-])${escape(from.prefix)}-(?=[\\w$])`, 'g');
|
|
63
|
+
const fromPascal = pascalCase(from.name);
|
|
64
|
+
const toPascal = pascalCase(to.name);
|
|
65
|
+
const componentHead = fromPascal.length > 0 && toPascal.length > 0 && fromPascal !== toPascal
|
|
66
|
+
? new RegExp(`(?<![\\w$])${escape(fromPascal)}(?=[A-Z])`, 'g')
|
|
67
|
+
: null;
|
|
68
|
+
const renameSegment = (segment) => {
|
|
69
|
+
let out = segment
|
|
70
|
+
.replace(rootClass, () => `theme-${to.slug}`)
|
|
71
|
+
.replace(demoId, () => `demo-${to.slug}`)
|
|
72
|
+
.replace(cssVar, () => `--${to.prefix}-`)
|
|
73
|
+
.replace(dataAttr, () => `data-${to.prefix}-`)
|
|
74
|
+
// The class prefix keeps its old priority: where slug and prefix spell the
|
|
75
|
+
// same token (the skeleton's `bare-`), the prefix wins, as before.
|
|
76
|
+
.replace(classToken, () => `${to.prefix}-`)
|
|
77
|
+
.replace(storeId, () => `${to.slug}-`);
|
|
78
|
+
if (componentHead)
|
|
79
|
+
out = out.replace(componentHead, () => toPascal);
|
|
80
|
+
return out.replace(nameOrSlug, (_match, name) => (name !== undefined ? literal(ext, to.name) : to.slug));
|
|
81
|
+
};
|
|
82
|
+
// Odd indexes are the URLs themselves (split keeps the capture); they pass through verbatim.
|
|
37
83
|
return content
|
|
38
|
-
.
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
.replace(nameOrSlug, (_match, name) => (name !== undefined ? literal(ext, to.name) : to.slug));
|
|
84
|
+
.split(URL)
|
|
85
|
+
.map((part, index) => (index % 2 === 1 ? part : renameSegment(part)))
|
|
86
|
+
.join('');
|
|
42
87
|
}
|
|
43
88
|
function walk(dir) {
|
|
44
89
|
return readdirSync(dir).flatMap((name) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usequeek/create-theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.0",
|
|
25
26
|
"giget": "^3.3.1"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|