@astryxdesign/cli 0.6.5-canary.eb58bba → 0.6.5-canary.efac39f
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/README.md +2 -2
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-theme.mjs +243 -22
- package/api/integration/add-theme.test.mjs +213 -0
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/template/copy/copy.mjs +5 -3
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +1 -1
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +8 -3
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/response/response-types.doc.mjs +2 -2
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -453,7 +453,7 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
453
453
|
| `template.list` | The effective discovered TemplateListEntry[] for pages and blocks. A winning replacement entry includes optional `replaces`, naming the Core id omitted from the default list. |
|
|
454
454
|
| `template.show` | The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media). |
|
|
455
455
|
| `template.skeleton` | A layout skeleton (structural tags with spatial annotations) plus the template's description and the components it composes. |
|
|
456
|
-
| `template.copy` | A scaffold receipt: template id, output directory, written file name, and
|
|
456
|
+
| `template.copy` | A scaffold receipt: template id, output directory, written file name, file count, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media). |
|
|
457
457
|
| `template.cdn` | A write receipt for the no-build-step CDN starter page: the path (relative to cwd), the Astryx version every CDN URL was pinned to, whether it was written, and the reason it was not. `exists` when a file was already there, which is a success. |
|
|
458
458
|
| `hook.list` | The hook catalog grouped by category: `detail` (the level: names \| compact \| full) and `components`, the grouped map of hook names, brief entries, or a full HookDoc per entry. |
|
|
459
459
|
| `hook.detail` | One hook's full authored HookDoc. |
|
|
@@ -480,7 +480,7 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
480
480
|
| `integration.template-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking Core template-id conflicts as {id, severity: warning, integrationPackage, integrationType, integrationName, coreMatches, message, command}. |
|
|
481
481
|
| `integration.component-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking conflicts where an integration component name is also owned by Core; each conflict includes the exact package-qualified command. |
|
|
482
482
|
| `integration.doc-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` \| `error`) and `relationship` (`replaces` \| `extends` \| `accidental`). |
|
|
483
|
-
| `layout.expand` | The expansion: parsed form, generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings,
|
|
483
|
+
| `layout.expand` | The expansion: parsed form, generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings, written (the output path, or null when nothing was written), and demoMediaReplaced (count of demo media placeholders). |
|
|
484
484
|
| `layout.check` | The validation result: a valid flag, the detected form, errors (each with line/col, message, formatted text, and suggestions), warnings, and the expression re-printed in both canonical surfaces (compact and outline). |
|
|
485
485
|
| `layout.grammar` | The XLE/XLO grammar cheatsheet: a text field with the full reference plus an aliases map (short name → canonical component) generated from this install's registry. |
|
|
486
486
|
|
|
@@ -31,7 +31,7 @@ export function integrationAddAgentDoc(line: string, options?: import("./integra
|
|
|
31
31
|
*
|
|
32
32
|
* @param {'component'|'doc'|'template'|'codemod'|'agent-doc'|'theme'} kind
|
|
33
33
|
* @param {string} name
|
|
34
|
-
* @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string}} [options]
|
|
34
|
+
* @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string, from?: string}} [options]
|
|
35
35
|
* @returns {Promise<import('./integration-authoring.type.mjs').IntegrationAddResponse>}
|
|
36
36
|
*/
|
|
37
37
|
export function integrationAdd(kind: "component" | "doc" | "template" | "codemod" | "agent-doc" | "theme", name: string, options?: {
|
|
@@ -42,4 +42,5 @@ export function integrationAdd(kind: "component" | "doc" | "template" | "codemod
|
|
|
42
42
|
replaces?: string;
|
|
43
43
|
extends?: string;
|
|
44
44
|
parent?: string;
|
|
45
|
+
from?: string;
|
|
45
46
|
}): Promise<import("./integration-authoring.type.mjs").IntegrationAddResponse>;
|
|
@@ -1211,7 +1211,7 @@ const KIND_OPTIONS = {
|
|
|
1211
1211
|
template: new Set(['cwd', 'dryRun', 'templateType']),
|
|
1212
1212
|
codemod: new Set(['cwd', 'dryRun', 'to']),
|
|
1213
1213
|
'agent-doc': new Set(['cwd', 'dryRun']),
|
|
1214
|
-
theme: new Set(['cwd', 'dryRun']),
|
|
1214
|
+
theme: new Set(['cwd', 'dryRun', 'from']),
|
|
1215
1215
|
};
|
|
1216
1216
|
|
|
1217
1217
|
/**
|
|
@@ -1238,7 +1238,7 @@ function validateKindOptions(kind, options) {
|
|
|
1238
1238
|
*
|
|
1239
1239
|
* @param {'component'|'doc'|'template'|'codemod'|'agent-doc'|'theme'} kind
|
|
1240
1240
|
* @param {string} name
|
|
1241
|
-
* @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string}} [options]
|
|
1241
|
+
* @param {{cwd?: string, dryRun?: boolean, templateType?: 'page'|'block', to?: string, replaces?: string, extends?: string, parent?: string, from?: string}} [options]
|
|
1242
1242
|
* @returns {Promise<import('./integration-authoring.type.mjs').IntegrationAddResponse>}
|
|
1243
1243
|
*/
|
|
1244
1244
|
export async function integrationAdd(kind, name, options = {}) {
|
|
@@ -1270,6 +1270,10 @@ export async function integrationAdd(kind, name, options = {}) {
|
|
|
1270
1270
|
case 'agent-doc':
|
|
1271
1271
|
return integrationAddAgentDoc(name, options);
|
|
1272
1272
|
case 'theme':
|
|
1273
|
-
return integrationAddTheme(name,
|
|
1273
|
+
return integrationAddTheme(name, {
|
|
1274
|
+
cwd: options.cwd,
|
|
1275
|
+
dryRun: options.dryRun,
|
|
1276
|
+
from: options.from,
|
|
1277
|
+
});
|
|
1274
1278
|
}
|
|
1275
1279
|
}
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* @file `astryx integration add theme` — scaffold one strongly typed,
|
|
5
5
|
* same-stem source/descriptor pair into an integration package and declare the
|
|
6
6
|
* themes root on first use.
|
|
7
|
+
*
|
|
8
|
+
* `--from <base>` forks an existing theme's source files as the starting point
|
|
9
|
+
* instead of writing a blank `defineTheme` skeleton.
|
|
7
10
|
*/
|
|
8
11
|
|
|
9
12
|
import * as fs from 'node:fs';
|
|
@@ -15,7 +18,10 @@ import {
|
|
|
15
18
|
PathSafetyError,
|
|
16
19
|
sanitizeName,
|
|
17
20
|
} from '../../foundation/fs/path-safety.mjs';
|
|
18
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
discoverBundledThemes,
|
|
23
|
+
discoverThemeDirectory,
|
|
24
|
+
} from '../../foundation/discovery/theme-discovery.mjs';
|
|
19
25
|
import {
|
|
20
26
|
findLocalIntegrationManifestOrNull,
|
|
21
27
|
IntegrationRootConflictError,
|
|
@@ -29,6 +35,7 @@ import {
|
|
|
29
35
|
themesCliProblem,
|
|
30
36
|
withCliPeer,
|
|
31
37
|
} from '../../foundation/integrations/cli-requirement.mjs';
|
|
38
|
+
import {stripCopyrightHeader} from '../../foundation/text/copyright-header.mjs';
|
|
32
39
|
import {
|
|
33
40
|
applyWrites,
|
|
34
41
|
findPackageDir,
|
|
@@ -70,6 +77,7 @@ function themeIdentity(slug) {
|
|
|
70
77
|
.join(' ');
|
|
71
78
|
return {
|
|
72
79
|
slug,
|
|
80
|
+
identifier,
|
|
73
81
|
displayName,
|
|
74
82
|
exportName: `${identifier}Theme`,
|
|
75
83
|
entry: `${identifier}Theme.ts`,
|
|
@@ -93,6 +101,182 @@ function themeDescriptor(identity) {
|
|
|
93
101
|
});
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
// ── --from: resolve and fork a base theme ───────────────────────────
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Resolve a theme slug to its discovered record, searching the bundled themes
|
|
108
|
+
* and the package's own themes root (when it has one).
|
|
109
|
+
* @param {string} slug
|
|
110
|
+
* @param {string} packageDir
|
|
111
|
+
* @param {string} owner
|
|
112
|
+
* @param {string | undefined} themesRoot resolved absolute themes root, if any
|
|
113
|
+
* @returns {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme}
|
|
114
|
+
*/
|
|
115
|
+
function resolveBaseTheme(slug, packageDir, owner, themesRoot) {
|
|
116
|
+
const normalized = slug.toLowerCase();
|
|
117
|
+
|
|
118
|
+
/** @type {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} */
|
|
119
|
+
let candidates = [];
|
|
120
|
+
try {
|
|
121
|
+
candidates = discoverBundledThemes();
|
|
122
|
+
} catch {
|
|
123
|
+
// Bundled themes unavailable — not fatal, package themes may suffice.
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Also check the package's own themes root.
|
|
127
|
+
if (themesRoot && fs.existsSync(themesRoot)) {
|
|
128
|
+
try {
|
|
129
|
+
candidates = [...candidates, ...discoverThemeDirectory(themesRoot, owner)];
|
|
130
|
+
} catch {
|
|
131
|
+
// A broken local root is not the caller's problem here.
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const match = candidates.find(t => t.slug.toLowerCase() === normalized);
|
|
136
|
+
if (!match) {
|
|
137
|
+
throw new AstryxError(
|
|
138
|
+
`Unknown base theme "${slug}". Available themes: ${candidates.map(t => t.slug).join(', ') || '(none)'}.`,
|
|
139
|
+
candidates.map(t => ({
|
|
140
|
+
name: t.slug,
|
|
141
|
+
reason: t.bundled ? 'bundled theme' : `provided by ${t.package}`,
|
|
142
|
+
})),
|
|
143
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return match;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Rename a file from the base theme's namespace to the new theme's namespace.
|
|
151
|
+
* Files whose name starts with the base identifier get the new identifier;
|
|
152
|
+
* others keep their name as-is.
|
|
153
|
+
* @param {string} file POSIX relative path inside the theme directory
|
|
154
|
+
* @param {string} baseIdentifier
|
|
155
|
+
* @param {string} newIdentifier
|
|
156
|
+
* @returns {string}
|
|
157
|
+
*/
|
|
158
|
+
function renameThemeFile(file, baseIdentifier, newIdentifier) {
|
|
159
|
+
const basename = path.posix.basename(file);
|
|
160
|
+
const dir = path.posix.dirname(file);
|
|
161
|
+
if (!basename.startsWith(baseIdentifier)) return file;
|
|
162
|
+
const renamed = newIdentifier + basename.slice(baseIdentifier.length);
|
|
163
|
+
return dir === '.' ? renamed : `${dir}/${renamed}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Rewrite a source file's contents from the base theme's names to the new
|
|
168
|
+
* theme's names. This replaces:
|
|
169
|
+
* 1. Identifier prefixes (camelCase variables, import paths): baseIdentifier
|
|
170
|
+
* followed by an uppercase letter.
|
|
171
|
+
* 2. The theme slug in string literals: 'baseSlug' → 'newSlug' and
|
|
172
|
+
* 'astryx-baseSlug' → 'astryx-newSlug'.
|
|
173
|
+
* 3. CSS custom properties scoped to the theme: --astryx-theme-baseSlug-.
|
|
174
|
+
* @param {string} source
|
|
175
|
+
* @param {string} baseSlug
|
|
176
|
+
* @param {string} baseIdentifier
|
|
177
|
+
* @param {string} newSlug
|
|
178
|
+
* @param {string} newIdentifier
|
|
179
|
+
* @returns {string}
|
|
180
|
+
*/
|
|
181
|
+
function rewriteThemeSource(
|
|
182
|
+
source,
|
|
183
|
+
baseSlug,
|
|
184
|
+
baseIdentifier,
|
|
185
|
+
newSlug,
|
|
186
|
+
newIdentifier,
|
|
187
|
+
) {
|
|
188
|
+
let result = source;
|
|
189
|
+
// 1. Identifier prefixes: neutralPalettes → oceanPalettes, neutralTheme → oceanTheme
|
|
190
|
+
const identRe = new RegExp(`${escapeRegExp(baseIdentifier)}(?=[A-Z])`, 'gu');
|
|
191
|
+
result = result.replace(identRe, newIdentifier);
|
|
192
|
+
// 2. String-literal theme names
|
|
193
|
+
result = result.replace(
|
|
194
|
+
new RegExp(`'astryx-${escapeRegExp(baseSlug)}'`, 'gu'),
|
|
195
|
+
`'astryx-${newSlug}'`,
|
|
196
|
+
);
|
|
197
|
+
result = result.replace(
|
|
198
|
+
new RegExp(`'${escapeRegExp(baseSlug)}'`, 'gu'),
|
|
199
|
+
`'${newSlug}'`,
|
|
200
|
+
);
|
|
201
|
+
// 3. CSS custom properties scoped to the base theme
|
|
202
|
+
result = result.replace(
|
|
203
|
+
new RegExp(
|
|
204
|
+
`--astryx-theme-${escapeRegExp(baseSlug)}-`,
|
|
205
|
+
'gu',
|
|
206
|
+
),
|
|
207
|
+
`--astryx-theme-${newSlug}-`,
|
|
208
|
+
);
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** @param {string} s */
|
|
213
|
+
function escapeRegExp(s) {
|
|
214
|
+
return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Build the write plans for a forked theme.
|
|
219
|
+
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} base
|
|
220
|
+
* @param {ReturnType<typeof themeIdentity>} identity new theme identity
|
|
221
|
+
* @param {string} themeDir absolute target directory
|
|
222
|
+
* @returns {import('./add-helpers.mjs').WritePlan[]}
|
|
223
|
+
*/
|
|
224
|
+
function forkThemePlans(base, identity, themeDir) {
|
|
225
|
+
const baseIdentity = themeIdentity(base.slug);
|
|
226
|
+
/** @type {import('./add-helpers.mjs').WritePlan[]} */
|
|
227
|
+
const plans = [];
|
|
228
|
+
|
|
229
|
+
// Copy every file the base theme ships (entry first, then the rest), except
|
|
230
|
+
// the descriptor — we write a fresh one.
|
|
231
|
+
const filesToCopy = base.files.filter(
|
|
232
|
+
file => path.posix.basename(file) !== `${baseIdentity.exportName}.doc.mjs`,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
for (const file of filesToCopy) {
|
|
236
|
+
const srcPath = path.join(base.sourceDir, file);
|
|
237
|
+
const newFileName = renameThemeFile(
|
|
238
|
+
file,
|
|
239
|
+
baseIdentity.identifier,
|
|
240
|
+
identity.identifier,
|
|
241
|
+
);
|
|
242
|
+
const destPath = assertWithin(newFileName, themeDir, {
|
|
243
|
+
label: `forked theme file "${newFileName}"`,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Read source bytes; for text, strip copyright and rewrite identifiers.
|
|
247
|
+
const bytes = fs.readFileSync(srcPath);
|
|
248
|
+
const text = bytes.toString('utf-8');
|
|
249
|
+
const isText = Buffer.from(text, 'utf-8').equals(bytes);
|
|
250
|
+
|
|
251
|
+
/** @type {string | Buffer} */
|
|
252
|
+
let contents;
|
|
253
|
+
if (isText) {
|
|
254
|
+
contents = rewriteThemeSource(
|
|
255
|
+
stripCopyrightHeader(text),
|
|
256
|
+
base.slug,
|
|
257
|
+
baseIdentity.identifier,
|
|
258
|
+
identity.slug,
|
|
259
|
+
identity.identifier,
|
|
260
|
+
);
|
|
261
|
+
} else {
|
|
262
|
+
contents = bytes;
|
|
263
|
+
}
|
|
264
|
+
plans.push({path: destPath, contents, createOnly: true});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Write a fresh descriptor — the fork is a new theme, not a derivative.
|
|
268
|
+
const descriptorPath = assertWithin(identity.descriptor, themeDir, {
|
|
269
|
+
label: 'theme descriptor file',
|
|
270
|
+
});
|
|
271
|
+
plans.push({
|
|
272
|
+
path: descriptorPath,
|
|
273
|
+
contents: themeDescriptor(identity),
|
|
274
|
+
createOnly: true,
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
return plans;
|
|
278
|
+
}
|
|
279
|
+
|
|
96
280
|
/**
|
|
97
281
|
* Read bytes back through the same discovery seam Project uses. A write is not
|
|
98
282
|
* successful until the requested slug resolves.
|
|
@@ -130,7 +314,7 @@ async function verifyThemeContribution(packageDir, manifestFile, owner, slug) {
|
|
|
130
314
|
* @returns {Promise<import('./integration-authoring.type.mjs').IntegrationAddResponse>}
|
|
131
315
|
*/
|
|
132
316
|
export async function integrationAddTheme(name, options = {}) {
|
|
133
|
-
const {cwd = process.cwd(), dryRun = false} = options;
|
|
317
|
+
const {cwd = process.cwd(), dryRun = false, from} = options;
|
|
134
318
|
const packageDir = findPackageDir(cwd);
|
|
135
319
|
const packageFile = path.join(packageDir, 'package.json');
|
|
136
320
|
let pkg;
|
|
@@ -212,32 +396,64 @@ export async function integrationAddTheme(name, options = {}) {
|
|
|
212
396
|
const themeDir = assertWithin(identity.slug, root, {
|
|
213
397
|
label: 'theme directory',
|
|
214
398
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// An existing folder is filled; only a file this would write is refused.
|
|
222
|
-
for (const file of [sourceFile, descriptorFile]) {
|
|
223
|
-
if (fs.existsSync(file)) {
|
|
399
|
+
|
|
400
|
+
// Resolve the base theme when --from is given, before writing anything.
|
|
401
|
+
/** @type {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined} */
|
|
402
|
+
let baseTheme;
|
|
403
|
+
if (from != null) {
|
|
404
|
+
if (from === name) {
|
|
224
405
|
throw new AstryxError(
|
|
225
|
-
`
|
|
406
|
+
`Cannot fork theme "${from}" into itself.`,
|
|
226
407
|
undefined,
|
|
227
|
-
ERROR_CODES.
|
|
408
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
228
409
|
);
|
|
229
410
|
}
|
|
411
|
+
baseTheme = resolveBaseTheme(from, packageDir, owner, root);
|
|
230
412
|
}
|
|
231
413
|
|
|
232
414
|
/** @type {import('./add-helpers.mjs').WritePlan[]} */
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
415
|
+
let plans;
|
|
416
|
+
|
|
417
|
+
if (baseTheme) {
|
|
418
|
+
// Fork: copy the base theme's files, renamed and rewritten.
|
|
419
|
+
plans = forkThemePlans(baseTheme, identity, themeDir);
|
|
420
|
+
// Check that no target file already exists.
|
|
421
|
+
for (const plan of plans) {
|
|
422
|
+
if (fs.existsSync(plan.path)) {
|
|
423
|
+
throw new AstryxError(
|
|
424
|
+
`Refusing to overwrite existing file ${projectPath(path.relative(packageDir, plan.path))}.`,
|
|
425
|
+
undefined,
|
|
426
|
+
ERROR_CODES.ERR_FILE_EXISTS,
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} else {
|
|
431
|
+
// Blank scaffold.
|
|
432
|
+
const sourceFile = assertWithin(identity.entry, themeDir, {
|
|
433
|
+
label: 'theme source file',
|
|
434
|
+
});
|
|
435
|
+
const descriptorFile = assertWithin(identity.descriptor, themeDir, {
|
|
436
|
+
label: 'theme descriptor file',
|
|
437
|
+
});
|
|
438
|
+
for (const file of [sourceFile, descriptorFile]) {
|
|
439
|
+
if (fs.existsSync(file)) {
|
|
440
|
+
throw new AstryxError(
|
|
441
|
+
`Refusing to overwrite existing file ${projectPath(path.relative(packageDir, file))}.`,
|
|
442
|
+
undefined,
|
|
443
|
+
ERROR_CODES.ERR_FILE_EXISTS,
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
plans = [
|
|
448
|
+
{path: sourceFile, contents: themeSource(identity), createOnly: true},
|
|
449
|
+
{
|
|
450
|
+
path: descriptorFile,
|
|
451
|
+
contents: themeDescriptor(identity),
|
|
452
|
+
createOnly: true,
|
|
453
|
+
},
|
|
454
|
+
];
|
|
455
|
+
}
|
|
456
|
+
|
|
241
457
|
let packageUpdate = packageJsonUpdate(
|
|
242
458
|
packageFile,
|
|
243
459
|
rootPath,
|
|
@@ -309,7 +525,8 @@ export async function integrationAddTheme(name, options = {}) {
|
|
|
309
525
|
writtenFiles.push(manifestPath);
|
|
310
526
|
}
|
|
311
527
|
|
|
312
|
-
|
|
528
|
+
/** @type {import('./integration-authoring.type.mjs').IntegrationAddResponse} */
|
|
529
|
+
const response = {
|
|
313
530
|
type: 'integration.add',
|
|
314
531
|
data: {
|
|
315
532
|
kind: 'theme',
|
|
@@ -321,4 +538,8 @@ export async function integrationAddTheme(name, options = {}) {
|
|
|
321
538
|
dryRun,
|
|
322
539
|
},
|
|
323
540
|
};
|
|
541
|
+
if (from != null) {
|
|
542
|
+
response.data.from = from;
|
|
543
|
+
}
|
|
544
|
+
return response;
|
|
324
545
|
}
|
|
@@ -310,3 +310,216 @@ describe('integrationAddTheme', () => {
|
|
|
310
310
|
);
|
|
311
311
|
});
|
|
312
312
|
});
|
|
313
|
+
|
|
314
|
+
describe('integrationAddTheme --from', () => {
|
|
315
|
+
it('forks a bundled theme into the integration package', async () => {
|
|
316
|
+
setup();
|
|
317
|
+
const result = await integrationAddTheme('ocean', {
|
|
318
|
+
cwd: tmpDir,
|
|
319
|
+
from: 'neutral',
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
expect(result.type).toBe('integration.add');
|
|
323
|
+
expect(result.data.kind).toBe('theme');
|
|
324
|
+
expect(result.data.name).toBe('ocean');
|
|
325
|
+
expect(result.data.from).toBe('neutral');
|
|
326
|
+
expect(result.data.written).toBe(true);
|
|
327
|
+
expect(result.data.dryRun).toBe(false);
|
|
328
|
+
expect(result.data.root).toEqual({path: './themes', created: true});
|
|
329
|
+
|
|
330
|
+
// The entry file must exist with the new export name.
|
|
331
|
+
const entry = fs.readFileSync(
|
|
332
|
+
path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
|
|
333
|
+
'utf-8',
|
|
334
|
+
);
|
|
335
|
+
expect(entry).toContain('oceanTheme');
|
|
336
|
+
expect(entry).toContain("name: 'ocean'");
|
|
337
|
+
// It must NOT contain the original theme identifier as a prefix.
|
|
338
|
+
expect(entry).not.toMatch(/\bneutralTheme\b/);
|
|
339
|
+
expect(entry).not.toMatch(/\bneutralPalettes\b/);
|
|
340
|
+
expect(entry).not.toMatch(/\bneutralSyntax\b/);
|
|
341
|
+
expect(entry).toContain('defineTheme');
|
|
342
|
+
|
|
343
|
+
// A fresh descriptor, not copied from the base.
|
|
344
|
+
const descriptor = fs.readFileSync(
|
|
345
|
+
path.join(tmpDir, 'themes/ocean/oceanTheme.doc.mjs'),
|
|
346
|
+
'utf-8',
|
|
347
|
+
);
|
|
348
|
+
expect(descriptor).toContain("name: 'ocean'");
|
|
349
|
+
expect(descriptor).toContain("@astryxdesign/cli/authoring').ThemeDoc");
|
|
350
|
+
expect(descriptor).toContain('maintained: true');
|
|
351
|
+
|
|
352
|
+
// The theme must validate.
|
|
353
|
+
expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('renames palette and support files from the base theme', async () => {
|
|
357
|
+
setup();
|
|
358
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
359
|
+
|
|
360
|
+
const themeDir = path.join(tmpDir, 'themes/ocean');
|
|
361
|
+
const files = fs.readdirSync(themeDir).sort();
|
|
362
|
+
// neutralPalettes.ts → oceanPalettes.ts, etc.
|
|
363
|
+
expect(files).toContain('oceanTheme.ts');
|
|
364
|
+
expect(files).toContain('oceanTheme.doc.mjs');
|
|
365
|
+
expect(files).toContain('oceanPalettes.ts');
|
|
366
|
+
expect(files).toContain('oceanPaletteRefs.generated.ts');
|
|
367
|
+
expect(files).toContain('icons.tsx');
|
|
368
|
+
// Must not contain any file starting with 'neutral'.
|
|
369
|
+
expect(files.filter(f => f.startsWith('neutral'))).toEqual([]);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('rewrites import paths inside forked files', async () => {
|
|
373
|
+
setup();
|
|
374
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
375
|
+
|
|
376
|
+
const entry = fs.readFileSync(
|
|
377
|
+
path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
|
|
378
|
+
'utf-8',
|
|
379
|
+
);
|
|
380
|
+
// Import references must use the new identifier.
|
|
381
|
+
expect(entry).toContain('./oceanPaletteRefs.generated');
|
|
382
|
+
expect(entry).not.toContain('./neutralPaletteRefs.generated');
|
|
383
|
+
// The icon registry import must also be renamed.
|
|
384
|
+
expect(entry).toContain('oceanIconRegistry');
|
|
385
|
+
expect(entry).not.toContain('neutralIconRegistry');
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('rewrites CSS custom properties scoped to the base theme', async () => {
|
|
389
|
+
setup();
|
|
390
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
391
|
+
|
|
392
|
+
const entry = fs.readFileSync(
|
|
393
|
+
path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
|
|
394
|
+
'utf-8',
|
|
395
|
+
);
|
|
396
|
+
expect(entry).toContain('--astryx-theme-ocean-');
|
|
397
|
+
expect(entry).not.toContain('--astryx-theme-neutral-');
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('rewrites the syntax theme name', async () => {
|
|
401
|
+
setup();
|
|
402
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
403
|
+
|
|
404
|
+
const entry = fs.readFileSync(
|
|
405
|
+
path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
|
|
406
|
+
'utf-8',
|
|
407
|
+
);
|
|
408
|
+
expect(entry).toContain("'astryx-ocean'");
|
|
409
|
+
expect(entry).not.toContain("'astryx-neutral'");
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('strips the copyright header from forked files', async () => {
|
|
413
|
+
setup();
|
|
414
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
415
|
+
|
|
416
|
+
const entry = fs.readFileSync(
|
|
417
|
+
path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
|
|
418
|
+
'utf-8',
|
|
419
|
+
);
|
|
420
|
+
expect(entry).not.toContain('Copyright (c) Meta Platforms');
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('includes data.from in the receipt only when --from is used', async () => {
|
|
424
|
+
setup();
|
|
425
|
+
const blank = await integrationAddTheme('plain', {cwd: tmpDir});
|
|
426
|
+
expect(blank.data).not.toHaveProperty('from');
|
|
427
|
+
|
|
428
|
+
const forked = await integrationAddTheme('ocean', {
|
|
429
|
+
cwd: tmpDir,
|
|
430
|
+
from: 'neutral',
|
|
431
|
+
});
|
|
432
|
+
expect(forked.data.from).toBe('neutral');
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('refuses to fork a theme into itself', async () => {
|
|
436
|
+
setup();
|
|
437
|
+
await expect(
|
|
438
|
+
integrationAddTheme('neutral', {cwd: tmpDir, from: 'neutral'}),
|
|
439
|
+
).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('refuses an unknown base theme with a helpful suggestion list', async () => {
|
|
443
|
+
setup();
|
|
444
|
+
await expect(
|
|
445
|
+
integrationAddTheme('ocean', {cwd: tmpDir, from: 'nonexistent'}),
|
|
446
|
+
).rejects.toMatchObject({
|
|
447
|
+
code: 'ERR_UNKNOWN_THEME',
|
|
448
|
+
message: expect.stringContaining('nonexistent'),
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('dry-runs with --from without writing anything', async () => {
|
|
453
|
+
setup();
|
|
454
|
+
const result = await integrationAddTheme('ocean', {
|
|
455
|
+
cwd: tmpDir,
|
|
456
|
+
from: 'neutral',
|
|
457
|
+
dryRun: true,
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
expect(result.data.written).toBe(false);
|
|
461
|
+
expect(result.data.dryRun).toBe(true);
|
|
462
|
+
expect(result.data.from).toBe('neutral');
|
|
463
|
+
expect(result.data.files).toContain('themes/ocean/oceanTheme.ts');
|
|
464
|
+
expect(result.data.files).toContain('themes/ocean/oceanTheme.doc.mjs');
|
|
465
|
+
expect(fs.existsSync(path.join(tmpDir, 'themes'))).toBe(false);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('refuses to overwrite when the target already exists', async () => {
|
|
469
|
+
setup();
|
|
470
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
471
|
+
await expect(
|
|
472
|
+
integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'}),
|
|
473
|
+
).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it('works with different bundled themes', async () => {
|
|
477
|
+
setup();
|
|
478
|
+
const result = await integrationAddTheme('dusk', {
|
|
479
|
+
cwd: tmpDir,
|
|
480
|
+
from: 'gothic',
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
expect(result.data.from).toBe('gothic');
|
|
484
|
+
const entry = fs.readFileSync(
|
|
485
|
+
path.join(tmpDir, 'themes/dusk/duskTheme.ts'),
|
|
486
|
+
'utf-8',
|
|
487
|
+
);
|
|
488
|
+
expect(entry).toContain('duskTheme');
|
|
489
|
+
expect(entry).toContain("name: 'dusk'");
|
|
490
|
+
expect(entry).not.toMatch(/\bgothicTheme\b/);
|
|
491
|
+
expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('forks from a theme the package already owns', async () => {
|
|
495
|
+
setup();
|
|
496
|
+
// First, add a blank theme.
|
|
497
|
+
await integrationAddTheme('base', {cwd: tmpDir});
|
|
498
|
+
// Then fork it.
|
|
499
|
+
const result = await integrationAddTheme('variant', {
|
|
500
|
+
cwd: tmpDir,
|
|
501
|
+
from: 'base',
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
expect(result.data.from).toBe('base');
|
|
505
|
+
const entry = fs.readFileSync(
|
|
506
|
+
path.join(tmpDir, 'themes/variant/variantTheme.ts'),
|
|
507
|
+
'utf-8',
|
|
508
|
+
);
|
|
509
|
+
expect(entry).toContain('variantTheme');
|
|
510
|
+
expect(entry).toContain("name: 'variant'");
|
|
511
|
+
expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('declares the optional CLI peer that reads typed theme descriptors', async () => {
|
|
515
|
+
setup({includeFiles: false});
|
|
516
|
+
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
517
|
+
const pkg = JSON.parse(
|
|
518
|
+
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
519
|
+
);
|
|
520
|
+
expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
|
|
521
|
+
expect(pkg.peerDependenciesMeta).toEqual({
|
|
522
|
+
'@astryxdesign/cli': {optional: true},
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
});
|
|
@@ -19,7 +19,9 @@ export type IntegrationAddCodemodOptions = IntegrationAddBaseOptions & {
|
|
|
19
19
|
to: string;
|
|
20
20
|
};
|
|
21
21
|
export type IntegrationAddAgentDocOptions = IntegrationAddBaseOptions;
|
|
22
|
-
export type IntegrationAddThemeOptions = IntegrationAddBaseOptions
|
|
22
|
+
export type IntegrationAddThemeOptions = IntegrationAddBaseOptions & {
|
|
23
|
+
from?: string;
|
|
24
|
+
};
|
|
23
25
|
/**
|
|
24
26
|
* Options for the generic `integrationAdd` dispatcher. Prefer a per-kind API
|
|
25
27
|
* when the contribution kind is known so the accepted options stay narrow.
|
|
@@ -54,4 +56,5 @@ export type IntegrationAddData = {
|
|
|
54
56
|
files: string[];
|
|
55
57
|
written: boolean;
|
|
56
58
|
dryRun: boolean;
|
|
59
|
+
from?: string | undefined;
|
|
57
60
|
};
|
|
@@ -37,7 +37,11 @@
|
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
/** @typedef {IntegrationAddBaseOptions} IntegrationAddAgentDocOptions */
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {IntegrationAddBaseOptions & {
|
|
42
|
+
* from?: string,
|
|
43
|
+
* }} IntegrationAddThemeOptions
|
|
44
|
+
*/
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
47
|
* Options for the generic `integrationAdd` dispatcher. Prefer a per-kind API
|
|
@@ -73,6 +77,7 @@
|
|
|
73
77
|
* @property {string[]} files
|
|
74
78
|
* @property {boolean} written
|
|
75
79
|
* @property {boolean} dryRun
|
|
80
|
+
* @property {string} [from]
|
|
76
81
|
*/
|
|
77
82
|
|
|
78
83
|
export {};
|
|
@@ -78,6 +78,12 @@ export const doc = {
|
|
|
78
78
|
type: 'string',
|
|
79
79
|
description: 'Exact target semver (e.g. 1.2.0). Required for codemod and only valid there.',
|
|
80
80
|
},
|
|
81
|
+
{
|
|
82
|
+
name: 'options.from',
|
|
83
|
+
type: 'string',
|
|
84
|
+
description:
|
|
85
|
+
'Slug of an existing theme to fork as the starting point. Only valid for theme.',
|
|
86
|
+
},
|
|
81
87
|
],
|
|
82
88
|
returns: [
|
|
83
89
|
{
|