@astryxdesign/cli 0.7.0-canary.450c68d → 0.7.0-canary.4ec1f4e
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 +30 -33
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.test.mjs +28 -0
- package/api/doctor/theme-checks.mjs +10 -10
- package/api/doctor/theme-checks.test.mjs +5 -4
- package/api/gap-report/gap-report.doc.mjs +1 -1
- package/api/gap-report/gap-report.mjs +15 -0
- package/api/gap-report/gap-report.test.mjs +1 -1
- package/api/index.d.mts +0 -2
- package/api/index.mjs +0 -2
- package/api/init/init.doc.mjs +5 -1
- package/api/init/init.mjs +22 -0
- package/api/init/init.type.d.mts +4 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/remove/remove.mjs +8 -3
- package/api/init/remove/remove.test.mjs +12 -0
- package/api/init/run/run.d.mts +1 -1
- package/api/init/run/run.mjs +3 -3
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +5 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +0 -1
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +1 -1
- package/api/search/search.test.mjs +1 -1
- package/api/search/search.type.d.mts +1 -1
- package/api/search/search.type.mjs +1 -1
- package/api/template/template-integration.test.mjs +37 -100
- package/api/template/template.doc.mjs +5 -1
- package/api/template/template.mjs +45 -0
- package/api/theme/_adapter.mjs +3 -3
- package/api/theme/add/add.d.mts +11 -5
- package/api/theme/add/add.mjs +19 -192
- package/api/theme/add/add.test.mjs +68 -258
- package/api/theme/add/add.types.test.mjs +0 -1
- package/api/theme/build/build.d.mts +3 -3
- package/api/theme/build/build.mjs +22 -36
- package/api/theme/build/build.test.mjs +11 -24
- package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
- package/api/theme/integration-themes.test.mjs +3 -3
- package/api/theme/remove/remove.test.mjs +1 -1
- package/api/theme/targets/targets.test.mjs +0 -4
- package/api/theme/template/template.mjs +1 -1
- package/api/theme/theme.type.d.mts +1 -30
- package/api/theme/theme.type.mjs +3 -13
- package/api/theme/themeAdd.doc.mjs +19 -27
- package/api/theme/themeTargets.doc.mjs +3 -4
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/api/theme/use/use.test.mjs +1 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.mjs +19 -0
- package/assets/codemods/transforms/next/README.md +15 -17
- package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
- package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
- package/assets/docs/tree/versioning.doc.mjs +1 -4
- package/assets/docs/use-a-theme.doc.mjs +16 -16
- package/authoring/debug/type.ts +2 -2
- package/authoring/doctypes/base/type.ts +0 -9
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/command-result-coverage.test.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
- package/clients/cli/commands/build-theme.mjs +31 -67
- package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
- package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
- package/clients/cli/commands/discover.mjs +2 -1
- package/clients/cli/commands/doctor.mjs +5 -2
- package/clients/cli/commands/empty-argument.test.mjs +16 -0
- package/clients/cli/commands/gap-report.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.test.mjs +2 -2
- package/clients/cli/commands/init.doc.mjs +4 -4
- package/clients/cli/commands/init.flag-help.test.mjs +7 -10
- package/clients/cli/commands/init.next-steps.test.mjs +1 -1
- package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
- package/clients/cli/commands/search.test.mjs +1 -1
- package/clients/cli/commands/swizzle.mjs +4 -1
- package/clients/cli/commands/template.doc.mjs +3 -3
- package/clients/cli/commands/template.flag-help.test.mjs +18 -11
- package/clients/cli/commands/template.mjs +7 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
- package/clients/cli/commands/theme-add.doc.mjs +10 -17
- package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
- package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +1 -1
- package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
- package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/cli-error.mjs +19 -0
- package/clients/cli/lib/component-format.mjs +111 -57
- package/clients/cli/lib/component-format.test.mjs +28 -39
- package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
- package/clients/cli/lib/exit-codes.test.mjs +0 -7
- package/clients/cli/lib/json-shim.test.mjs +0 -24
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +6 -1
- package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
- package/foundation/config/theme-state.mjs +3 -3
- package/foundation/debug/debug-fields.test.mjs +13 -35
- package/foundation/debug/event.mjs +13 -78
- package/foundation/debug/privacy-contract.test.mjs +20 -12
- package/foundation/debug/redact.d.mts +2 -2
- package/foundation/debug/redact.mjs +2 -2
- package/foundation/discovery/theme-imports.mjs +1 -1
- package/foundation/discovery/theming-targets.d.mts +1 -20
- package/foundation/discovery/theming-targets.mjs +1 -38
- package/foundation/discovery/theming-targets.test.mjs +9 -175
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +11 -30
- package/foundation/response/response-types.doc.test.mjs +36 -14
- package/foundation/response/response.doc.mjs +1 -1
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/browser.mjs +2 -2
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/print.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -17
- package/api/layout/check/check.mjs +0 -41
- package/api/layout/expand/expand.d.mts +0 -23
- package/api/layout/expand/expand.mjs +0 -161
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/expand/expand.receipt.test.mjs +0 -74
- package/api/layout/grammar/grammar.d.mts +0 -14
- package/api/layout/grammar/grammar.mjs +0 -88
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -90
- package/api/layout/layout.type.mjs +0 -104
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/api/theme/add/add.binary.test.mjs +0 -157
- package/api/theme/add/add.rollback.test.mjs +0 -158
- package/api/theme/add/add.staging.test.mjs +0 -83
- package/clients/cli/commands/layout-check.doc.mjs +0 -67
- package/clients/cli/commands/layout-expand.doc.mjs +0 -87
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
- package/clients/cli/commands/layout.doc.mjs +0 -36
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
- package/clients/cli/commands/layout.mjs +0 -327
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
package/api/search/search.mjs
CHANGED
|
@@ -1749,7 +1749,7 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1749
1749
|
result = {
|
|
1750
1750
|
...base,
|
|
1751
1751
|
displayName: c._displayName,
|
|
1752
|
-
command: `astryx theme add
|
|
1752
|
+
command: `astryx theme add ${c.name}`,
|
|
1753
1753
|
};
|
|
1754
1754
|
break;
|
|
1755
1755
|
default:
|
|
@@ -99,7 +99,7 @@ describe('search leaf — per-domain result fields', () => {
|
|
|
99
99
|
expect(['page', 'block']).toContain(res.kind);
|
|
100
100
|
} else if (res.domain === 'theme') {
|
|
101
101
|
expect(res.displayName).toMatch(/\S/);
|
|
102
|
-
expect(res.command).
|
|
102
|
+
expect(res.command).toBe(`astryx theme add ${res.name}`);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}, SLOW);
|
|
@@ -30,7 +30,7 @@ export type SearchResultEntry = {
|
|
|
30
30
|
*/
|
|
31
31
|
description: string;
|
|
32
32
|
/**
|
|
33
|
-
* - Follow-up command to act on this result (e.g. `astryx component Button`, or `astryx theme add
|
|
33
|
+
* - Follow-up command to act on this result (e.g. `astryx component Button`, or `astryx theme add neutral` for a theme).
|
|
34
34
|
*/
|
|
35
35
|
command: string;
|
|
36
36
|
/**
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* @property {number} score - Relevance score (higher is better).
|
|
21
21
|
* @property {string} reason - Human-readable reason the candidate matched (e.g. `keyword "button"`).
|
|
22
22
|
* @property {string} description - One-line description, when available.
|
|
23
|
-
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button`, or `astryx theme add
|
|
23
|
+
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button`, or `astryx theme add neutral` for a theme).
|
|
24
24
|
* @property {string} [import] - Import path — present for component and hook results.
|
|
25
25
|
* @property {string} [title] - Doc title — present for doc results.
|
|
26
26
|
* @property {string} [section] - Section key — present when a doc result is one section of a topic; `command` reads only that section.
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
} from './template.mjs';
|
|
20
20
|
import {search} from '../search/search.mjs';
|
|
21
21
|
import {build} from '../build/build.mjs';
|
|
22
|
-
import {layoutExpand} from '../layout/layout.mjs';
|
|
23
22
|
import {runCli} from '../../test-utils/run-cli.mjs';
|
|
24
23
|
|
|
25
24
|
let tmpDir;
|
|
@@ -532,105 +531,6 @@ describe('integration template discovery', () => {
|
|
|
532
531
|
});
|
|
533
532
|
});
|
|
534
533
|
|
|
535
|
-
it('resolves a replacement block through the layout alias', async () => {
|
|
536
|
-
const pkgDir = installWidgets(tmpDir);
|
|
537
|
-
writeTemplate(pkgDir, 'acme-card-callout', {
|
|
538
|
-
kind: 'block',
|
|
539
|
-
source:
|
|
540
|
-
'export default function AcmeCardCallout() { return <span>Acme replacement block</span>; }\n',
|
|
541
|
-
});
|
|
542
|
-
declareReplaces(pkgDir, {
|
|
543
|
-
'acme-card-callout': 'CardCallout',
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
const accidental = path.join(tmpDir, 'node_modules', '@acme', 'extra');
|
|
547
|
-
fs.mkdirSync(path.join(accidental, 'templates'), {recursive: true});
|
|
548
|
-
fs.writeFileSync(
|
|
549
|
-
path.join(accidental, 'package.json'),
|
|
550
|
-
JSON.stringify({name: '@acme/extra', version: '1.0.0'}),
|
|
551
|
-
);
|
|
552
|
-
fs.writeFileSync(
|
|
553
|
-
path.join(accidental, 'astryx.integration.mjs'),
|
|
554
|
-
`export default {templates: './templates'};\n`,
|
|
555
|
-
);
|
|
556
|
-
writeTemplate(accidental, 'CardCallout', {
|
|
557
|
-
kind: 'block',
|
|
558
|
-
body: `export default {type: 'block', name: 'ZZZ accidental block', description: 'collision'};\n`,
|
|
559
|
-
source:
|
|
560
|
-
'export default function Accidental() { return <span>Accidental block</span>; }\n',
|
|
561
|
-
});
|
|
562
|
-
fs.writeFileSync(
|
|
563
|
-
path.join(tmpDir, 'astryx.config.mjs'),
|
|
564
|
-
`export default { integrations: ['@acme/widgets', '@acme/extra'] };\n`,
|
|
565
|
-
);
|
|
566
|
-
|
|
567
|
-
const result = await layoutExpand('C{card-callout}', {
|
|
568
|
-
name: 'ReplacementLayout',
|
|
569
|
-
cwd: tmpDir,
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
expect(result.data.code).toContain('Acme replacement block');
|
|
573
|
-
expect(result.data.code).not.toContain('Accidental block');
|
|
574
|
-
expect(result.data.blocksReferenced).toEqual(
|
|
575
|
-
expect.arrayContaining([
|
|
576
|
-
expect.objectContaining({name: 'CardCallout', mode: 'splice'}),
|
|
577
|
-
]),
|
|
578
|
-
);
|
|
579
|
-
}, 30_000);
|
|
580
|
-
|
|
581
|
-
it('resolves chained block aliases consistently in template and layout', async () => {
|
|
582
|
-
const [firstTarget, secondTarget] = (await discoverCoreTemplates()).filter(
|
|
583
|
-
candidate => candidate.type === 'block',
|
|
584
|
-
);
|
|
585
|
-
expect(firstTarget).toBeDefined();
|
|
586
|
-
expect(secondTarget).toBeDefined();
|
|
587
|
-
|
|
588
|
-
const pkgDir = installWidgets(tmpDir);
|
|
589
|
-
writeTemplate(pkgDir, secondTarget.dirName, {
|
|
590
|
-
kind: 'block',
|
|
591
|
-
source:
|
|
592
|
-
'export default function FirstReplacement() { return <span>First chain replacement</span>; }\n',
|
|
593
|
-
});
|
|
594
|
-
writeTemplate(pkgDir, 'acme-final-block', {
|
|
595
|
-
kind: 'block',
|
|
596
|
-
source:
|
|
597
|
-
'export default function FinalReplacement() { return <span>Final chain replacement</span>; }\n',
|
|
598
|
-
});
|
|
599
|
-
declareReplaces(pkgDir, {
|
|
600
|
-
[secondTarget.dirName]: firstTarget.dirName,
|
|
601
|
-
'acme-final-block': secondTarget.dirName,
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
const firstTemplate = await template(firstTarget.dirName, {
|
|
605
|
-
show: true,
|
|
606
|
-
cwd: tmpDir,
|
|
607
|
-
});
|
|
608
|
-
expect(firstTemplate.data.source).toContain('First chain replacement');
|
|
609
|
-
const layoutId = id =>
|
|
610
|
-
id.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();
|
|
611
|
-
const firstLayout = await layoutExpand(
|
|
612
|
-
`C{${layoutId(firstTarget.dirName)}}`,
|
|
613
|
-
{
|
|
614
|
-
cwd: tmpDir,
|
|
615
|
-
},
|
|
616
|
-
);
|
|
617
|
-
expect(firstLayout.data.code).toContain('First chain replacement');
|
|
618
|
-
expect(firstLayout.data.code).not.toContain('Final chain replacement');
|
|
619
|
-
|
|
620
|
-
const secondTemplate = await template(secondTarget.dirName, {
|
|
621
|
-
show: true,
|
|
622
|
-
cwd: tmpDir,
|
|
623
|
-
});
|
|
624
|
-
expect(secondTemplate.data.source).toContain('Final chain replacement');
|
|
625
|
-
const secondLayout = await layoutExpand(
|
|
626
|
-
`C{${layoutId(secondTarget.dirName)}}`,
|
|
627
|
-
{
|
|
628
|
-
cwd: tmpDir,
|
|
629
|
-
},
|
|
630
|
-
);
|
|
631
|
-
expect(secondLayout.data.code).toContain('Final chain replacement');
|
|
632
|
-
}, 30_000);
|
|
633
|
-
|
|
634
534
|
it('keeps the old discovery behavior when no replacement is declared', async () => {
|
|
635
535
|
const pkgDir = installWidgets(tmpDir);
|
|
636
536
|
writeTemplate(pkgDir, 'acme-app-shell', {kind: 'page'});
|
|
@@ -1334,4 +1234,41 @@ describe('build names a start its command selects', () => {
|
|
|
1334
1234
|
template('contact-form', {show: true, cwd: tmpDir}),
|
|
1335
1235
|
).rejects.toMatchObject({code: 'ERR_AMBIGUOUS_TEMPLATE'});
|
|
1336
1236
|
});
|
|
1237
|
+
|
|
1238
|
+
it('resolves chained template aliases without the layout command', async () => {
|
|
1239
|
+
const [firstTarget, secondTarget] = (await discoverCoreTemplates()).filter(
|
|
1240
|
+
candidate => candidate.type === 'block',
|
|
1241
|
+
);
|
|
1242
|
+
expect(firstTarget).toBeDefined();
|
|
1243
|
+
expect(secondTarget).toBeDefined();
|
|
1244
|
+
|
|
1245
|
+
const pkgDir = installWidgets(tmpDir);
|
|
1246
|
+
writeTemplate(pkgDir, secondTarget.dirName, {
|
|
1247
|
+
kind: 'block',
|
|
1248
|
+
source:
|
|
1249
|
+
'export default function FirstReplacement() { return <span>First chain replacement</span>; }\n',
|
|
1250
|
+
});
|
|
1251
|
+
writeTemplate(pkgDir, 'acme-final-block', {
|
|
1252
|
+
kind: 'block',
|
|
1253
|
+
source:
|
|
1254
|
+
'export default function FinalReplacement() { return <span>Final chain replacement</span>; }\n',
|
|
1255
|
+
});
|
|
1256
|
+
declareReplaces(pkgDir, {
|
|
1257
|
+
[secondTarget.dirName]: firstTarget.dirName,
|
|
1258
|
+
'acme-final-block': secondTarget.dirName,
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
const firstTemplate = await template(firstTarget.dirName, {
|
|
1262
|
+
show: true,
|
|
1263
|
+
cwd: tmpDir,
|
|
1264
|
+
});
|
|
1265
|
+
expect(firstTemplate.data.source).toContain('First chain replacement');
|
|
1266
|
+
|
|
1267
|
+
const secondTemplate = await template(secondTarget.dirName, {
|
|
1268
|
+
show: true,
|
|
1269
|
+
cwd: tmpDir,
|
|
1270
|
+
});
|
|
1271
|
+
expect(secondTemplate.data.source).toContain('Final chain replacement');
|
|
1272
|
+
}, 30_000);
|
|
1273
|
+
|
|
1337
1274
|
});
|
|
@@ -48,7 +48,7 @@ export const doc = {
|
|
|
48
48
|
{
|
|
49
49
|
name: 'options.list',
|
|
50
50
|
type: 'boolean',
|
|
51
|
-
description: '
|
|
51
|
+
description: 'List templates instead of scaffolding; refused with ERR_INVALID_ARGUMENT when a name or path is also given.',
|
|
52
52
|
default: 'false',
|
|
53
53
|
},
|
|
54
54
|
{
|
|
@@ -133,6 +133,10 @@ export const doc = {
|
|
|
133
133
|
},
|
|
134
134
|
],
|
|
135
135
|
throws: [
|
|
136
|
+
{
|
|
137
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
138
|
+
when: '--cdn is combined with <name>, --list, --skeleton, --type, or --package; --list is combined with <name>, <path>, --skeleton, or --overwrite; --skeleton is combined with <path> or --overwrite',
|
|
139
|
+
},
|
|
136
140
|
{
|
|
137
141
|
code: 'ERR_UNKNOWN_TEMPLATE',
|
|
138
142
|
when: 'the named template does not exist, or options.skeleton is set without a name',
|
|
@@ -86,6 +86,51 @@ export async function template(name, options = {}) {
|
|
|
86
86
|
cwd = process.cwd(),
|
|
87
87
|
} = options;
|
|
88
88
|
|
|
89
|
+
if (cdn) {
|
|
90
|
+
const ignored = [
|
|
91
|
+
name ? '<name>' : null,
|
|
92
|
+
list ? '--list' : null,
|
|
93
|
+
skeleton ? '--skeleton' : null,
|
|
94
|
+
type ? '--type' : null,
|
|
95
|
+
packageFilter ? '--package' : null,
|
|
96
|
+
].filter(Boolean);
|
|
97
|
+
if (ignored.length > 0) {
|
|
98
|
+
throw new AstryxError(
|
|
99
|
+
`\`--cdn\` cannot be combined with ${ignored.join(', ')}: the CDN starter does not use templates.`,
|
|
100
|
+
undefined,
|
|
101
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (list) {
|
|
106
|
+
const ignored = [
|
|
107
|
+
name ? '<name>' : null,
|
|
108
|
+
targetPath ? '<path>' : null,
|
|
109
|
+
skeleton ? '--skeleton' : null,
|
|
110
|
+
overwrite ? '--overwrite' : null,
|
|
111
|
+
].filter(Boolean);
|
|
112
|
+
if (ignored.length > 0) {
|
|
113
|
+
throw new AstryxError(
|
|
114
|
+
`\`--list\` cannot be combined with ${ignored.join(', ')}: it lists templates and does not scaffold.`,
|
|
115
|
+
undefined,
|
|
116
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (skeleton) {
|
|
121
|
+
const ignored = [
|
|
122
|
+
targetPath ? '<path>' : null,
|
|
123
|
+
overwrite ? '--overwrite' : null,
|
|
124
|
+
].filter(Boolean);
|
|
125
|
+
if (ignored.length > 0) {
|
|
126
|
+
throw new AstryxError(
|
|
127
|
+
`\`--skeleton\` cannot be combined with ${ignored.join(', ')}: it prints the skeleton and does not write files.`,
|
|
128
|
+
undefined,
|
|
129
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
89
134
|
// The CDN starter ships as an asset rather than as a discovered template, so
|
|
90
135
|
// it answers before discovery — nothing here needs a name resolved.
|
|
91
136
|
if (cdn) {
|
package/api/theme/_adapter.mjs
CHANGED
|
@@ -565,7 +565,7 @@ export function resolveRecordedThemes(state, available) {
|
|
|
565
565
|
);
|
|
566
566
|
if (!theme) {
|
|
567
567
|
throw new AstryxError(
|
|
568
|
-
`Added theme "${slug}" from ${owner} is unavailable. Reinstall the package or restore the local theme, then run \`astryx theme add ${slug} --
|
|
568
|
+
`Added theme "${slug}" from ${owner} is unavailable. Reinstall the package or restore the local theme, then run \`astryx theme add ${slug} --package ${owner}\`.`,
|
|
569
569
|
undefined,
|
|
570
570
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
571
571
|
);
|
|
@@ -732,7 +732,7 @@ export async function removeThemeFromApp(slug, options = {}) {
|
|
|
732
732
|
const recordedSlug = recordedThemeSlug(state, slug);
|
|
733
733
|
if (!state.configured || recordedSlug == null) {
|
|
734
734
|
throw new AstryxError(
|
|
735
|
-
`Theme "${slug}" is not added. Run \`astryx theme add ${slug}
|
|
735
|
+
`Theme "${slug}" is not added. Run \`astryx theme add ${slug}\` first.`,
|
|
736
736
|
undefined,
|
|
737
737
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
738
738
|
);
|
|
@@ -776,7 +776,7 @@ export async function useThemeInApp(slug, options = {}) {
|
|
|
776
776
|
const recordedSlug = recordedThemeSlug(state, slug);
|
|
777
777
|
if (!state.configured || recordedSlug == null) {
|
|
778
778
|
throw new AstryxError(
|
|
779
|
-
`Theme "${slug}" is not added. Run \`astryx theme add ${slug}
|
|
779
|
+
`Theme "${slug}" is not added. Run \`astryx theme add ${slug}\` first.`,
|
|
780
780
|
undefined,
|
|
781
781
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
782
782
|
);
|
package/api/theme/add/add.d.mts
CHANGED
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Add one available built theme to the generated app module. `import` remains
|
|
6
|
+
* accepted as a no-op so callers that opted in before the cleanup keep working.
|
|
7
|
+
*
|
|
8
|
+
* Removed source-copy options are rejected before discovery or any write, and
|
|
9
|
+
* name the function that now owns them. `overwrite: false` remains an accepted
|
|
10
|
+
* compatibility no-op.
|
|
11
|
+
*
|
|
6
12
|
* @param {string} slug
|
|
7
|
-
* @param {{targetPath?: string, overwrite?: boolean,
|
|
8
|
-
* @returns {Promise<import('../theme.type.mjs').
|
|
13
|
+
* @param {{targetPath?: string, overwrite?: boolean, import?: boolean, cwd?: string, package?: string}} [options]
|
|
14
|
+
* @returns {Promise<import('../theme.type.mjs').ThemeAppResponse>}
|
|
9
15
|
*/
|
|
10
16
|
export function themeAdd(slug: string, options?: {
|
|
11
17
|
targetPath?: string;
|
|
12
18
|
overwrite?: boolean;
|
|
19
|
+
import?: boolean;
|
|
13
20
|
cwd?: string;
|
|
14
21
|
package?: string;
|
|
15
|
-
|
|
16
|
-
}): Promise<import("../theme.type.mjs").ThemeAddResponse | import("../theme.type.mjs").ThemeAppResponse>;
|
|
22
|
+
}): Promise<import("../theme.type.mjs").ThemeAppResponse>;
|
package/api/theme/add/add.mjs
CHANGED
|
@@ -1,210 +1,37 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file `astryx theme add` —
|
|
4
|
+
* @file `astryx theme add` — add built theme output to the app.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Plain `theme add` and the compatibility `--import` spelling both record the
|
|
7
|
+
* built theme in the generated app module. Source copying belongs only to
|
|
8
|
+
* `theme eject`.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
import
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import {addThemeToApp, findTheme, listAvailableThemes} from '../_adapter.mjs';
|
|
13
|
-
import {
|
|
14
|
-
assertWithin,
|
|
15
|
-
PathSafetyError,
|
|
16
|
-
} from '../../../foundation/fs/path-safety.mjs';
|
|
11
|
+
import {addThemeToApp} from '../_adapter.mjs';
|
|
17
12
|
import {AstryxError} from '../../error.mjs';
|
|
18
13
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
19
|
-
import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
20
|
-
import {stripCopyrightHeader} from '../../../foundation/text/copyright-header.mjs';
|
|
21
|
-
|
|
22
|
-
const COPY_DEPRECATION = Object.freeze({
|
|
23
|
-
id: 'DEP-0005',
|
|
24
|
-
replacements: ['theme eject', 'theme add --import'],
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
/** @param {string} slug */
|
|
28
|
-
function defaultTargetDir(slug) {
|
|
29
|
-
return path.join('src', 'themes', slug);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Strip repository boilerplate from UTF-8 text while preserving binary bytes.
|
|
34
|
-
* @param {Buffer} bytes
|
|
35
|
-
* @returns {Buffer|string}
|
|
36
|
-
*/
|
|
37
|
-
function scaffoldContents(bytes) {
|
|
38
|
-
const text = bytes.toString('utf-8');
|
|
39
|
-
return Buffer.from(text, 'utf-8').equals(bytes)
|
|
40
|
-
? stripCopyrightHeader(text)
|
|
41
|
-
: bytes;
|
|
42
|
-
}
|
|
43
14
|
|
|
44
15
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
16
|
+
* Add one available built theme to the generated app module. `import` remains
|
|
17
|
+
* accepted as a no-op so callers that opted in before the cleanup keep working.
|
|
18
|
+
*
|
|
19
|
+
* Removed source-copy options are rejected before discovery or any write, and
|
|
20
|
+
* name the function that now owns them. `overwrite: false` remains an accepted
|
|
21
|
+
* compatibility no-op.
|
|
50
22
|
*
|
|
51
23
|
* @param {string} slug
|
|
52
|
-
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}} options
|
|
53
|
-
* @returns {Promise<import('../theme.type.mjs').
|
|
54
|
-
*/
|
|
55
|
-
async function copyThemeSource(slug, options) {
|
|
56
|
-
const {
|
|
57
|
-
targetPath,
|
|
58
|
-
overwrite = false,
|
|
59
|
-
cwd = process.cwd(),
|
|
60
|
-
package: packageName,
|
|
61
|
-
} = options;
|
|
62
|
-
|
|
63
|
-
const match = await findTheme(slug, {
|
|
64
|
-
cwd,
|
|
65
|
-
package: packageName,
|
|
66
|
-
includeLocal: false,
|
|
67
|
-
});
|
|
68
|
-
if (!match) {
|
|
69
|
-
const available = await listAvailableThemes(cwd, {includeLocal: false});
|
|
70
|
-
throw new AstryxError(
|
|
71
|
-
`Unknown theme "${slug}"${packageName ? ` in package "${packageName}"` : ''}`,
|
|
72
|
-
available.map(theme => ({
|
|
73
|
-
name: `${theme.slug} --package ${theme.package}`,
|
|
74
|
-
reason:
|
|
75
|
-
theme.source === 'bundled'
|
|
76
|
-
? 'bundled theme'
|
|
77
|
-
: `provided by ${theme.package}`,
|
|
78
|
-
})),
|
|
79
|
-
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const rawTarget = targetPath || defaultTargetDir(match.slug);
|
|
84
|
-
let resolvedDir;
|
|
85
|
-
try {
|
|
86
|
-
resolvedDir = assertWithin(rawTarget, cwd, {label: 'theme target path'});
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (error instanceof PathSafetyError) {
|
|
89
|
-
throw new AstryxError(
|
|
90
|
-
error.message,
|
|
91
|
-
undefined,
|
|
92
|
-
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const descriptor = path
|
|
99
|
-
.relative(match.sourceDir, match.docPath)
|
|
100
|
-
.split(path.sep)
|
|
101
|
-
.join('/');
|
|
102
|
-
const copyFiles = match.bundled
|
|
103
|
-
? match.files.filter(name => name !== descriptor)
|
|
104
|
-
: [match.entry, ...match.files.filter(name => name !== match.entry).sort()];
|
|
105
|
-
let writes;
|
|
106
|
-
try {
|
|
107
|
-
writes = copyFiles.map(name => ({
|
|
108
|
-
name,
|
|
109
|
-
src: path.join(match.sourceDir, name),
|
|
110
|
-
dest: assertWithin(name, resolvedDir, {
|
|
111
|
-
label: `theme destination for ${name}`,
|
|
112
|
-
}),
|
|
113
|
-
}));
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (error instanceof PathSafetyError) {
|
|
116
|
-
throw new AstryxError(
|
|
117
|
-
error.message,
|
|
118
|
-
undefined,
|
|
119
|
-
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (const write of writes) {
|
|
126
|
-
if (!fs.existsSync(write.src)) {
|
|
127
|
-
throw new AstryxError(
|
|
128
|
-
`Theme "${match.slug}" is missing bundled file "${write.name}". ` +
|
|
129
|
-
'Re-run `node scripts/generate-cli-themes.mjs` to rebuild the bundle.',
|
|
130
|
-
undefined,
|
|
131
|
-
ERROR_CODES.ERR_NO_SOURCE,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!overwrite) {
|
|
137
|
-
const existing = writes.find(write => fs.existsSync(write.dest));
|
|
138
|
-
if (existing) {
|
|
139
|
-
const rel = path.relative(cwd, existing.dest) || existing.dest;
|
|
140
|
-
throw new AstryxError(
|
|
141
|
-
`Refusing to overwrite existing file ${rel}. ` +
|
|
142
|
-
'Re-run with --overwrite (or -f) to replace it.',
|
|
143
|
-
undefined,
|
|
144
|
-
ERROR_CODES.ERR_FILE_EXISTS,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
fs.mkdirSync(resolvedDir, {recursive: true});
|
|
151
|
-
const plans = writes.map(write => {
|
|
152
|
-
fs.mkdirSync(path.dirname(write.dest), {recursive: true});
|
|
153
|
-
const dest = assertWithin(write.name, resolvedDir, {
|
|
154
|
-
label: `theme destination for ${write.name}`,
|
|
155
|
-
});
|
|
156
|
-
return {
|
|
157
|
-
path: dest,
|
|
158
|
-
contents: scaffoldContents(fs.readFileSync(write.src)),
|
|
159
|
-
createOnly: !overwrite,
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
applyWrites(plans);
|
|
163
|
-
} catch (error) {
|
|
164
|
-
if (error instanceof AstryxError) throw error;
|
|
165
|
-
if (error instanceof PathSafetyError) {
|
|
166
|
-
throw new AstryxError(
|
|
167
|
-
error.message,
|
|
168
|
-
undefined,
|
|
169
|
-
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
173
|
-
throw new AstryxError(
|
|
174
|
-
`Failed to write theme files: ${message}`,
|
|
175
|
-
undefined,
|
|
176
|
-
ERROR_CODES.ERR_WRITE_FAILED,
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
type: 'theme.add',
|
|
182
|
-
data: {
|
|
183
|
-
slug: match.slug,
|
|
184
|
-
displayName: match.displayName,
|
|
185
|
-
maintained: match.maintained,
|
|
186
|
-
package: match.package,
|
|
187
|
-
outputDir: path.relative(cwd, resolvedDir) || '.',
|
|
188
|
-
entry: match.entry,
|
|
189
|
-
exportName: match.exportName,
|
|
190
|
-
files: copyFiles,
|
|
191
|
-
},
|
|
192
|
-
meta: {deprecations: [COPY_DEPRECATION]},
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Copy one available source theme, or import its built output with `import`.
|
|
198
|
-
* @param {string} slug
|
|
199
|
-
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string, import?: boolean}} [options]
|
|
200
|
-
* @returns {Promise<import('../theme.type.mjs').ThemeAddResponse | import('../theme.type.mjs').ThemeAppResponse>}
|
|
24
|
+
* @param {{targetPath?: string, overwrite?: boolean, import?: boolean, cwd?: string, package?: string}} [options]
|
|
25
|
+
* @returns {Promise<import('../theme.type.mjs').ThemeAppResponse>}
|
|
201
26
|
*/
|
|
202
27
|
export async function themeAdd(slug, options = {}) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
28
|
+
const legacy = /** @type {{targetPath?: unknown, overwrite?: unknown}} */ (
|
|
29
|
+
options
|
|
30
|
+
);
|
|
31
|
+
if (legacy.targetPath != null || legacy.overwrite === true) {
|
|
206
32
|
throw new AstryxError(
|
|
207
|
-
'`
|
|
33
|
+
'`themeAdd` no longer copies source or accepts targetPath or overwrite: true. ' +
|
|
34
|
+
'Call `themeEject` with the same slug and copy options to fork source.',
|
|
208
35
|
undefined,
|
|
209
36
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
210
37
|
);
|