@usequeek/create-theme 0.4.0 → 0.4.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/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`). The
12
- * skeleton keeps the English word "bare" out of its copy so every remaining
13
- * standalone token is identity.
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`). The
26
- * skeleton keeps the English word "bare" out of its copy so every remaining
27
- * standalone token is identity.
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
- .replace(new RegExp(`(?<![\\w-])theme-${escape(from.slug)}(?![\\w-])`, 'g'), () => `theme-${to.slug}`)
39
- .replace(new RegExp(`(?<![\\w-])demo-${escape(from.slug)}(?![\\w])`, 'g'), () => `demo-${to.slug}`)
40
- .replace(new RegExp(`(?<![\\w-])${escape(from.prefix)}-(?=[\\w$])`, 'g'), () => `${to.prefix}-`)
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.4.0",
3
+ "version": "0.4.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",