@astryxdesign/cli 0.6.0 → 0.6.1
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/CHANGELOG.md +48 -1
- package/README.md +76 -67
- package/api/build/build.test.mjs +37 -0
- package/api/build/build.type.mjs +1 -1
- package/api/build/kit/kit.mjs +31 -1
- package/api/component/_adapter.mjs +14 -28
- package/api/component/integration-import-agreement.test.mjs +318 -0
- package/api/doctor/doctor.d.mts +32 -3
- package/api/doctor/doctor.doc.mjs +2 -1
- package/api/doctor/doctor.mjs +97 -4
- package/api/doctor/doctor.test.mjs +90 -1
- package/api/gap-report/gap-report-worker.d.mts +4 -0
- package/api/gap-report/gap-report-worker.mjs +73 -0
- package/api/gap-report/gap-report.d.mts +81 -0
- package/api/gap-report/gap-report.doc.d.mts +9 -0
- package/api/gap-report/gap-report.doc.mjs +127 -0
- package/api/gap-report/gap-report.mjs +707 -0
- package/api/gap-report/gap-report.test.mjs +1210 -0
- package/api/gap-report/gap-report.type.d.mts +88 -0
- package/api/gap-report/gap-report.type.mjs +69 -0
- package/api/index.d.mts +8 -1
- package/api/index.mjs +24 -1
- package/api/integration/add-contribution.d.mts +44 -0
- package/api/integration/add-contribution.mjs +1160 -0
- package/api/integration/add-contribution.test.mjs +733 -0
- package/api/integration/add-helpers.d.mts +80 -0
- package/api/integration/add-helpers.mjs +333 -0
- package/api/integration/add-helpers.test.mjs +161 -0
- package/api/integration/add-theme.d.mts +10 -0
- package/api/integration/add-theme.mjs +332 -0
- package/api/integration/add-theme.test.mjs +194 -0
- package/api/integration/integration-authoring.type.d.mts +55 -0
- package/api/integration/integration-authoring.type.mjs +76 -0
- package/api/integration/integration-block-exports.test.mjs +4 -0
- package/api/integration/integrationAdd.doc.d.mts +5 -0
- package/api/integration/integrationAdd.doc.mjs +100 -0
- package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
- package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
- package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
- package/api/integration/integrationAddCodemod.doc.mjs +55 -0
- package/api/integration/integrationAddComponent.doc.d.mts +5 -0
- package/api/integration/integrationAddComponent.doc.mjs +49 -0
- package/api/integration/integrationAddDoc.doc.d.mts +5 -0
- package/api/integration/integrationAddDoc.doc.mjs +59 -0
- package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
- package/api/integration/integrationAddTemplate.doc.mjs +55 -0
- package/api/integration/integrationAddTheme.doc.d.mts +5 -0
- package/api/integration/integrationAddTheme.doc.mjs +85 -0
- package/api/integration/integrationPackCheck.doc.d.mts +5 -0
- package/api/integration/integrationPackCheck.doc.mjs +35 -0
- package/api/integration/pack-check.d.mts +27 -0
- package/api/integration/pack-check.mjs +795 -0
- package/api/integration/pack-check.test.mjs +569 -0
- package/api/integration/pack-check.type.d.mts +45 -0
- package/api/integration/pack-check.type.mjs +56 -0
- package/api/integration/public-api.test.mjs +21 -0
- package/api/integration/validate-integration.mjs +221 -11
- package/api/integration/validate-integration.test.mjs +189 -5
- package/api/integration/validateIntegration.doc.mjs +2 -2
- package/api/json/index.ts +1 -0
- package/api/search/search.mjs +19 -1
- package/api/theme/_adapter.d.mts +26 -28
- package/api/theme/_adapter.mjs +101 -38
- package/api/theme/add/add.d.mts +2 -1
- package/api/theme/add/add.mjs +56 -20
- package/api/theme/add/add.test.mjs +1 -0
- package/api/theme/build/build.d.mts +25 -0
- package/api/theme/build/build.mjs +101 -70
- package/api/theme/build/build.test.mjs +77 -44
- package/api/theme/integration-themes.test.mjs +183 -0
- package/api/theme/list/list.d.mts +10 -2
- package/api/theme/list/list.mjs +31 -10
- package/api/theme/list/list.test.mjs +102 -23
- package/api/theme/listThemes.doc.d.mts +1 -5
- package/api/theme/listThemes.doc.mjs +6 -13
- package/api/theme/targets/targets.test.mjs +22 -8
- package/api/theme/theme.d.mts +1 -1
- package/api/theme/theme.mjs +1 -1
- package/api/theme/theme.type.d.mts +9 -0
- package/api/theme/theme.type.mjs +3 -1
- package/api/theme/themeAdd.doc.d.mts +1 -4
- package/api/theme/themeAdd.doc.mjs +31 -31
- package/api/theme/themeBuild.doc.mjs +1 -1
- package/api/theme/themeList.doc.d.mts +1 -4
- package/api/theme/themeList.doc.mjs +7 -15
- package/api/theme/themeListAvailable.doc.d.mts +8 -0
- package/api/theme/themeListAvailable.doc.mjs +57 -0
- package/api/theme/themeTargets.doc.mjs +21 -7
- package/api/upgrade/_adapter.d.mts +2 -0
- package/api/upgrade/_adapter.mjs +1 -0
- package/api/upgrade/registry/registry.d.mts +40 -0
- package/api/upgrade/registry/registry.mjs +1154 -0
- package/api/upgrade/registry/registry.test.mjs +826 -0
- package/api/upgrade/run/run.mjs +49 -8
- package/api/upgrade/status/status.d.mts +6 -4
- package/api/upgrade/status/status.mjs +26 -8
- package/api/upgrade/upgrade.d.mts +2 -2
- package/api/upgrade/upgrade.doc.mjs +33 -9
- package/api/upgrade/upgrade.mjs +34 -7
- package/api/upgrade/upgrade.test.mjs +198 -8
- package/api/upgrade/upgrade.type.d.mts +90 -1
- package/api/upgrade/upgrade.type.mjs +51 -2
- package/assets/docs/cli-integrations.doc.mjs +152 -28
- package/assets/docs/getting-started.doc.mjs +1 -1
- package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
- package/assets/docs/styling.doc.mjs +3 -3
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +23 -13
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
- package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
- package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
- package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
- package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +3 -3
- package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
- package/assets/templates/themes/stone/stoneTheme.ts +3 -3
- package/assets/theme.template.ts +4 -7
- package/authoring/config/config.doc.mjs +9 -1
- package/authoring/config/parse.d.mts +2 -0
- package/authoring/config/parse.mjs +28 -3
- package/authoring/config/parse.test.mjs +25 -3
- package/authoring/config/type.ts +3 -0
- package/authoring/doctypes/_schema.d.mts +3 -0
- package/authoring/doctypes/_schema.mjs +6 -1
- package/authoring/doctypes/base/type.ts +6 -6
- package/authoring/doctypes/component/component.doc.mjs +6 -0
- package/authoring/doctypes/component/type.ts +2 -0
- package/authoring/gap-report/parse.d.mts +63 -0
- package/authoring/gap-report/parse.mjs +121 -0
- package/authoring/gap-report/parse.test.mjs +172 -0
- package/authoring/gap-report/type.ts +107 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +4 -0
- package/authoring/integration/integration.doc.mjs +14 -2
- package/authoring/integration/parse.test.mjs +9 -4
- package/authoring/integration/schema.d.mts +2 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +23 -6
- package/authoring/shadcn/receipt.d.mts +219 -0
- package/authoring/shadcn/receipt.mjs +248 -0
- package/authoring/shadcn/receipt.test.mjs +187 -0
- package/authoring/shadcn/source-variants.d.mts +28 -0
- package/authoring/shadcn/source-variants.mjs +176 -0
- package/authoring/shadcn/source-variants.test.mjs +120 -0
- package/clients/cli/commands/build-theme.mjs +54 -19
- package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
- package/clients/cli/commands/component/index.mjs +1 -1
- package/clients/cli/commands/docs.test.mjs +1 -0
- package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.doc.mjs +73 -0
- package/clients/cli/commands/gap-report.mjs +114 -0
- package/clients/cli/commands/gap-report.test.mjs +198 -0
- package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
- package/clients/cli/commands/integration-add.doc.mjs +88 -0
- package/clients/cli/commands/integration-authoring.test.mjs +177 -0
- package/clients/cli/commands/integration-pack.doc.mjs +34 -0
- package/clients/cli/commands/integration-real-world.test.mjs +618 -0
- package/clients/cli/commands/integration.doc.mjs +28 -0
- package/clients/cli/commands/integration.mjs +153 -0
- package/clients/cli/commands/theme-add.doc.mjs +11 -6
- package/clients/cli/commands/theme-list.doc.mjs +21 -5
- package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +17 -4
- package/clients/cli/commands/upgrade.mjs +12 -1
- package/clients/cli/commands/upgrade.test.mjs +41 -0
- package/clients/cli/index.mjs +5 -0
- package/clients/cli/lib/component-format.mjs +42 -26
- package/clients/cli/lib/component-format.test.mjs +34 -3
- package/clients/cli/lib/manifest.mjs +12 -0
- package/foundation/config/project-themes.test.mjs +127 -0
- package/foundation/config/project.d.mts +23 -4
- package/foundation/config/project.mjs +96 -9
- package/foundation/config/project.test.mjs +132 -6
- package/foundation/discovery/component-discovery.d.mts +36 -0
- package/foundation/discovery/component-discovery.mjs +96 -0
- package/foundation/discovery/theme-discovery.d.mts +39 -0
- package/foundation/discovery/theme-discovery.mjs +650 -0
- package/foundation/discovery/theme-discovery.test.mjs +375 -0
- package/foundation/discovery/theming-targets.d.mts +16 -0
- package/foundation/discovery/theming-targets.mjs +39 -3
- package/foundation/discovery/theming-targets.test.mjs +139 -0
- package/foundation/integrations/autolink.d.mts +96 -0
- package/foundation/integrations/autolink.mjs +265 -0
- package/foundation/integrations/autolink.test.mjs +430 -0
- package/foundation/integrations/contribution-inventory.d.mts +152 -0
- package/foundation/integrations/contribution-inventory.mjs +497 -0
- package/foundation/integrations/contribution-inventory.test.mjs +361 -0
- package/foundation/integrations/integrations.d.mts +73 -9
- package/foundation/integrations/integrations.mjs +158 -8
- package/foundation/integrations/integrations.test.mjs +152 -29
- package/foundation/integrations/manifest-writer.d.mts +56 -0
- package/foundation/integrations/manifest-writer.mjs +328 -0
- package/foundation/integrations/manifest-writer.test.mjs +229 -0
- package/foundation/integrations/validate-contributions.mjs +81 -6
- package/foundation/response/error-codes.d.mts +4 -1
- package/foundation/response/error-codes.doc.mjs +16 -1
- package/foundation/response/error-codes.mjs +10 -1
- package/foundation/response/response-types.doc.mjs +23 -2
- package/package.json +8 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import {
|
|
5
|
+
shadcnJavaScriptTarget,
|
|
6
|
+
transformShadcnJavaScriptSource,
|
|
7
|
+
} from './source-variants.mjs';
|
|
8
|
+
import {
|
|
9
|
+
createRegistryReceipt,
|
|
10
|
+
parseRegistryReceipt,
|
|
11
|
+
registryContentHash,
|
|
12
|
+
registryReceiptTarget,
|
|
13
|
+
serializeRegistryReceipt,
|
|
14
|
+
} from './receipt.mjs';
|
|
15
|
+
|
|
16
|
+
function receipt() {
|
|
17
|
+
const target = 'components/astryx/examples/ButtonExample.tsx';
|
|
18
|
+
const receiptTarget = registryReceiptTarget(target, 'example-button-basic');
|
|
19
|
+
return createRegistryReceipt({
|
|
20
|
+
item: {
|
|
21
|
+
name: 'example-button-basic',
|
|
22
|
+
path: 'examples/button/basic',
|
|
23
|
+
aliases: ['examples/button/old-basic'],
|
|
24
|
+
kind: 'example',
|
|
25
|
+
},
|
|
26
|
+
sourceVersion: '0.6.0',
|
|
27
|
+
receiptTarget,
|
|
28
|
+
files: [
|
|
29
|
+
{
|
|
30
|
+
id: 'primary',
|
|
31
|
+
target,
|
|
32
|
+
registryPath: 'registry/example-button-basic/ButtonExample.tsx',
|
|
33
|
+
content: 'export default function Example(): null { return null; }\n',
|
|
34
|
+
variants: [
|
|
35
|
+
{
|
|
36
|
+
format: 'javascript',
|
|
37
|
+
target: shadcnJavaScriptTarget(target),
|
|
38
|
+
content: transformShadcnJavaScriptSource(
|
|
39
|
+
'export default function Example(): null { return null; }\n',
|
|
40
|
+
),
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('ShadCN registry receipts', () => {
|
|
49
|
+
it('places a unique receipt beside the copied source', () => {
|
|
50
|
+
expect(
|
|
51
|
+
registryReceiptTarget(
|
|
52
|
+
'components/astryx/examples/ButtonExample.tsx',
|
|
53
|
+
'example-button-basic',
|
|
54
|
+
),
|
|
55
|
+
).toBe('components/astryx/examples/.astryx/example-button-basic.json');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('records the installed base bytes and a relative target', () => {
|
|
59
|
+
const value = receipt();
|
|
60
|
+
expect(value.schemaVersion).toBe(2);
|
|
61
|
+
expect(value.files[0]).toMatchObject({
|
|
62
|
+
id: 'primary',
|
|
63
|
+
target: '../ButtonExample.tsx',
|
|
64
|
+
registryTarget: 'components/astryx/examples/ButtonExample.tsx',
|
|
65
|
+
registryPath: 'registry/example-button-basic/ButtonExample.tsx',
|
|
66
|
+
sha256: registryContentHash(value.files[0].content),
|
|
67
|
+
variants: [
|
|
68
|
+
expect.objectContaining({
|
|
69
|
+
format: 'javascript',
|
|
70
|
+
target: '../ButtonExample.jsx',
|
|
71
|
+
registryTarget: 'components/astryx/examples/ButtonExample.jsx',
|
|
72
|
+
}),
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
expect(value.files[0].variants[0].sha256).toBe(
|
|
76
|
+
registryContentHash(value.files[0].variants[0].content),
|
|
77
|
+
);
|
|
78
|
+
expect(
|
|
79
|
+
parseRegistryReceipt(JSON.parse(serializeRegistryReceipt(value))),
|
|
80
|
+
).toEqual(value);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('permits a canonical JavaScript base without a duplicate variant', () => {
|
|
84
|
+
const target = 'components/astryx/examples/CompiledExample.jsx';
|
|
85
|
+
const value = createRegistryReceipt({
|
|
86
|
+
item: {
|
|
87
|
+
name: 'example-compiled',
|
|
88
|
+
path: 'examples/compiled',
|
|
89
|
+
aliases: [],
|
|
90
|
+
kind: 'example',
|
|
91
|
+
},
|
|
92
|
+
sourceVersion: '0.6.0',
|
|
93
|
+
receiptTarget: registryReceiptTarget(target, 'example-compiled'),
|
|
94
|
+
files: [
|
|
95
|
+
{
|
|
96
|
+
id: 'primary',
|
|
97
|
+
target,
|
|
98
|
+
registryPath: 'registry/example-compiled/CompiledExample.jsx',
|
|
99
|
+
content:
|
|
100
|
+
'export default function CompiledExample() { return null; }\n',
|
|
101
|
+
variants: [],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(parseRegistryReceipt(value).files[0].variants).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('continues to parse version 1 receipts without variants', () => {
|
|
110
|
+
const value = receipt();
|
|
111
|
+
const {variants: _variants, ...legacyFile} = value.files[0];
|
|
112
|
+
expect(
|
|
113
|
+
parseRegistryReceipt({
|
|
114
|
+
...value,
|
|
115
|
+
schemaVersion: 1,
|
|
116
|
+
files: [legacyFile],
|
|
117
|
+
}),
|
|
118
|
+
).toMatchObject({schemaVersion: 1, files: [{id: 'primary'}]});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('rejects duplicate file identities', () => {
|
|
122
|
+
const value = receipt();
|
|
123
|
+
expect(() =>
|
|
124
|
+
parseRegistryReceipt({
|
|
125
|
+
...value,
|
|
126
|
+
files: [value.files[0], {...value.files[0]}],
|
|
127
|
+
}),
|
|
128
|
+
).toThrow(/must be unique/);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('rejects duplicate or escaping install variants', () => {
|
|
132
|
+
const value = receipt();
|
|
133
|
+
const variant = value.files[0].variants[0];
|
|
134
|
+
expect(() =>
|
|
135
|
+
parseRegistryReceipt({
|
|
136
|
+
...value,
|
|
137
|
+
files: [
|
|
138
|
+
{
|
|
139
|
+
...value.files[0],
|
|
140
|
+
variants: [variant, {...variant}],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
}),
|
|
144
|
+
).toThrow(/variant formats must be unique/);
|
|
145
|
+
expect(() =>
|
|
146
|
+
parseRegistryReceipt({
|
|
147
|
+
...value,
|
|
148
|
+
files: [
|
|
149
|
+
{
|
|
150
|
+
...value.files[0],
|
|
151
|
+
variants: [{...variant, target: '../../outside.jsx'}],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
}),
|
|
155
|
+
).toThrow(/adjacent source file/);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('rejects traversal and corrupt hashes', () => {
|
|
159
|
+
const value = receipt();
|
|
160
|
+
expect(() =>
|
|
161
|
+
parseRegistryReceipt({
|
|
162
|
+
...value,
|
|
163
|
+
files: [{...value.files[0], target: '../../outside.tsx'}],
|
|
164
|
+
}),
|
|
165
|
+
).toThrow(/adjacent source file/);
|
|
166
|
+
for (const target of ['../.', '../..']) {
|
|
167
|
+
expect(() =>
|
|
168
|
+
parseRegistryReceipt({
|
|
169
|
+
...value,
|
|
170
|
+
files: [{...value.files[0], target}],
|
|
171
|
+
}),
|
|
172
|
+
).toThrow(/adjacent source file/);
|
|
173
|
+
}
|
|
174
|
+
expect(() =>
|
|
175
|
+
parseRegistryReceipt({
|
|
176
|
+
...value,
|
|
177
|
+
source: {...value.source, version: '0.6.0\n<<<<<<< injected'},
|
|
178
|
+
}),
|
|
179
|
+
).toThrow(/semantic version/);
|
|
180
|
+
expect(() =>
|
|
181
|
+
parseRegistryReceipt({
|
|
182
|
+
...value,
|
|
183
|
+
files: [{...value.files[0], sha256: 'not-a-hash'}],
|
|
184
|
+
}),
|
|
185
|
+
).toThrow();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in authoring/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/** @param {string} target */
|
|
5
|
+
export function shadcnJavaScriptTarget(target: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Give precompiled JavaScript a narrow ambient type instead of labelling the
|
|
8
|
+
* untyped Babel output as TSX. The suffix wildcard covers relative and aliased
|
|
9
|
+
* imports of this exact composition without masking unrelated JavaScript.
|
|
10
|
+
* @param {string} sourceTarget
|
|
11
|
+
*/
|
|
12
|
+
export function createShadcnPrecompiledDeclaration(sourceTarget: string): string;
|
|
13
|
+
/** @param {string} sourceTarget */
|
|
14
|
+
export function shadcnPrecompiledDeclarationTarget(sourceTarget: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Match shadcn 4.19's tsx=false transform byte-for-byte. Keep this small and
|
|
17
|
+
* covered by a real stock-client install test rather than importing private
|
|
18
|
+
* chunks from the shadcn package.
|
|
19
|
+
* @param {string} source
|
|
20
|
+
*/
|
|
21
|
+
export function transformShadcnJavaScriptSource(source: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Recognize printer-only JavaScript differences without hiding code or comment
|
|
24
|
+
* edits. This protects receipts from compatible ShadCN formatter drift.
|
|
25
|
+
* @param {string} left
|
|
26
|
+
* @param {string} right
|
|
27
|
+
*/
|
|
28
|
+
export function shadcnJavaScriptSourcesEquivalent(left: string, right: string): boolean;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Reproduce the JavaScript transform used by the pinned ShadCN client.
|
|
5
|
+
* @input Registry TypeScript/TSX source and its explicit target path.
|
|
6
|
+
* @output Exact JavaScript/JSX bytes and target used when components.json has tsx=false.
|
|
7
|
+
* @position Shared compatibility boundary for generated receipt variants and upgrades.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {transformFromAstSync} from '@babel/core';
|
|
11
|
+
import {parse} from '@babel/parser';
|
|
12
|
+
import {createRequire} from 'node:module';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
import * as recast from 'recast';
|
|
15
|
+
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
/** @type {import('@babel/core').PluginItem} */
|
|
18
|
+
const transformTypeScript =
|
|
19
|
+
require('@babel/plugin-transform-typescript').default;
|
|
20
|
+
|
|
21
|
+
/** @type {import('@babel/parser').ParserOptions} */
|
|
22
|
+
const SHADCN_PARSER_OPTIONS = {
|
|
23
|
+
sourceType: 'module',
|
|
24
|
+
allowImportExportEverywhere: true,
|
|
25
|
+
allowReturnOutsideFunction: true,
|
|
26
|
+
startLine: 1,
|
|
27
|
+
tokens: true,
|
|
28
|
+
plugins: [
|
|
29
|
+
'asyncGenerators',
|
|
30
|
+
'bigInt',
|
|
31
|
+
'classPrivateMethods',
|
|
32
|
+
'classPrivateProperties',
|
|
33
|
+
'classProperties',
|
|
34
|
+
'classStaticBlock',
|
|
35
|
+
'decimal',
|
|
36
|
+
'decorators-legacy',
|
|
37
|
+
'doExpressions',
|
|
38
|
+
'dynamicImport',
|
|
39
|
+
'exportDefaultFrom',
|
|
40
|
+
'exportNamespaceFrom',
|
|
41
|
+
'functionBind',
|
|
42
|
+
'functionSent',
|
|
43
|
+
'importAssertions',
|
|
44
|
+
'importMeta',
|
|
45
|
+
'nullishCoalescingOperator',
|
|
46
|
+
'numericSeparator',
|
|
47
|
+
'objectRestSpread',
|
|
48
|
+
'optionalCatchBinding',
|
|
49
|
+
'optionalChaining',
|
|
50
|
+
['pipelineOperator', {proposal: 'minimal'}],
|
|
51
|
+
['recordAndTuple', {syntaxType: 'hash'}],
|
|
52
|
+
'throwExpressions',
|
|
53
|
+
'topLevelAwait',
|
|
54
|
+
'v8intrinsic',
|
|
55
|
+
'typescript',
|
|
56
|
+
'jsx',
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** @param {string} target */
|
|
61
|
+
export function shadcnJavaScriptTarget(target) {
|
|
62
|
+
const extension = path.posix.extname(target);
|
|
63
|
+
if (extension === '.tsx') return `${target.slice(0, -4)}.jsx`;
|
|
64
|
+
if (extension === '.ts') return `${target.slice(0, -3)}.js`;
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Give precompiled JavaScript a narrow ambient type instead of labelling the
|
|
70
|
+
* untyped Babel output as TSX. The suffix wildcard covers relative and aliased
|
|
71
|
+
* imports of this exact composition without masking unrelated JavaScript.
|
|
72
|
+
* @param {string} sourceTarget
|
|
73
|
+
*/
|
|
74
|
+
export function createShadcnPrecompiledDeclaration(sourceTarget) {
|
|
75
|
+
const extension = path.posix.extname(sourceTarget);
|
|
76
|
+
if (extension !== '.jsx' && extension !== '.js') {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Precompiled declaration source must be JavaScript: ${sourceTarget}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const moduleSuffix = sourceTarget.slice(0, -extension.length);
|
|
82
|
+
return (
|
|
83
|
+
`declare module '*${moduleSuffix}' {\n` +
|
|
84
|
+
` const Component: import('react').ComponentType;\n` +
|
|
85
|
+
` export default Component;\n` +
|
|
86
|
+
`}\n`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** @param {string} sourceTarget */
|
|
91
|
+
export function shadcnPrecompiledDeclarationTarget(sourceTarget) {
|
|
92
|
+
const extension = path.posix.extname(sourceTarget);
|
|
93
|
+
if (extension !== '.jsx' && extension !== '.js') {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Precompiled declaration source must be JavaScript: ${sourceTarget}`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return `${sourceTarget.slice(0, -extension.length)}.astryx.d.mts`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Match shadcn 4.19's tsx=false transform byte-for-byte. Keep this small and
|
|
103
|
+
* covered by a real stock-client install test rather than importing private
|
|
104
|
+
* chunks from the shadcn package.
|
|
105
|
+
* @param {string} source
|
|
106
|
+
*/
|
|
107
|
+
export function transformShadcnJavaScriptSource(source) {
|
|
108
|
+
const ast = recast.parse(source, {
|
|
109
|
+
parser: {
|
|
110
|
+
/** @param {string} input */
|
|
111
|
+
parse: input => parse(input, SHADCN_PARSER_OPTIONS),
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const transformed = transformFromAstSync(ast, source, {
|
|
115
|
+
cloneInputAst: false,
|
|
116
|
+
code: false,
|
|
117
|
+
ast: true,
|
|
118
|
+
plugins: [transformTypeScript],
|
|
119
|
+
configFile: false,
|
|
120
|
+
});
|
|
121
|
+
if (!transformed?.ast) {
|
|
122
|
+
throw new Error('ShadCN JavaScript transform produced no AST');
|
|
123
|
+
}
|
|
124
|
+
return recast.print(transformed.ast).code;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Ignore parser metadata and literal raw spelling while preserving the complete
|
|
129
|
+
* JavaScript/JSX syntax tree and attached comment text. AST structure keeps
|
|
130
|
+
* automatic-semicolon-insertion changes distinct from printer-only changes.
|
|
131
|
+
* @param {unknown} value
|
|
132
|
+
* @returns {unknown}
|
|
133
|
+
*/
|
|
134
|
+
function normalizeJavaScriptAst(value) {
|
|
135
|
+
if (Array.isArray(value)) return value.map(normalizeJavaScriptAst);
|
|
136
|
+
if (value == null || typeof value !== 'object') return value;
|
|
137
|
+
const objectValue = /** @type {Record<string, unknown>} */ (value);
|
|
138
|
+
/** @type {Record<string, unknown>} */
|
|
139
|
+
const normalized = {};
|
|
140
|
+
for (const key of Object.keys(objectValue).sort()) {
|
|
141
|
+
if (
|
|
142
|
+
key === 'start' ||
|
|
143
|
+
key === 'end' ||
|
|
144
|
+
key === 'loc' ||
|
|
145
|
+
key === 'range' ||
|
|
146
|
+
key === 'extra' ||
|
|
147
|
+
key === 'tokens' ||
|
|
148
|
+
key === 'errors'
|
|
149
|
+
) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
normalized[key] = normalizeJavaScriptAst(objectValue[key]);
|
|
153
|
+
}
|
|
154
|
+
return normalized;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Recognize printer-only JavaScript differences without hiding code or comment
|
|
159
|
+
* edits. This protects receipts from compatible ShadCN formatter drift.
|
|
160
|
+
* @param {string} left
|
|
161
|
+
* @param {string} right
|
|
162
|
+
*/
|
|
163
|
+
export function shadcnJavaScriptSourcesEquivalent(left, right) {
|
|
164
|
+
try {
|
|
165
|
+
return (
|
|
166
|
+
JSON.stringify(
|
|
167
|
+
normalizeJavaScriptAst(parse(left, SHADCN_PARSER_OPTIONS)),
|
|
168
|
+
) ===
|
|
169
|
+
JSON.stringify(
|
|
170
|
+
normalizeJavaScriptAst(parse(right, SHADCN_PARSER_OPTIONS)),
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {readFileSync} from 'node:fs';
|
|
4
|
+
import {describe, expect, it} from 'vitest';
|
|
5
|
+
import {
|
|
6
|
+
createShadcnPrecompiledDeclaration,
|
|
7
|
+
shadcnJavaScriptSourcesEquivalent,
|
|
8
|
+
shadcnJavaScriptTarget,
|
|
9
|
+
shadcnPrecompiledDeclarationTarget,
|
|
10
|
+
transformShadcnJavaScriptSource,
|
|
11
|
+
} from './source-variants.mjs';
|
|
12
|
+
|
|
13
|
+
describe('ShadCN JavaScript source variants', () => {
|
|
14
|
+
it('uses the target extension ShadCN writes for tsx=false', () => {
|
|
15
|
+
expect(shadcnJavaScriptTarget('components/Example.tsx')).toBe(
|
|
16
|
+
'components/Example.jsx',
|
|
17
|
+
);
|
|
18
|
+
expect(shadcnJavaScriptTarget('hooks/useExample.ts')).toBe(
|
|
19
|
+
'hooks/useExample.js',
|
|
20
|
+
);
|
|
21
|
+
expect(shadcnJavaScriptTarget('components/Example.jsx')).toBe(
|
|
22
|
+
'components/Example.jsx',
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('matches the pinned ShadCN TypeScript stripping shape', () => {
|
|
27
|
+
const source =
|
|
28
|
+
"'use client';\n\n" +
|
|
29
|
+
"import type {ReactNode} from 'react';\n" +
|
|
30
|
+
'const value: ReactNode = null;\n' +
|
|
31
|
+
'export default function Example() { return value; }\n';
|
|
32
|
+
|
|
33
|
+
expect(transformShadcnJavaScriptSource(source)).toBe(
|
|
34
|
+
"'use client';;\n" +
|
|
35
|
+
'const value = null;\n' +
|
|
36
|
+
'export default function Example() { return value; }\n',
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('is idempotent for already-precompiled JSX', () => {
|
|
41
|
+
const source =
|
|
42
|
+
"export default function Example() { return <Component label='A long label' value='A long value' onChange={() => {}} />; }\n";
|
|
43
|
+
const transformed = transformShadcnJavaScriptSource(source);
|
|
44
|
+
expect(transformShadcnJavaScriptSource(transformed)).toBe(transformed);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('recognizes printer-only JavaScript differences without hiding edits', () => {
|
|
48
|
+
const compact =
|
|
49
|
+
"// Keep this note\nexport default function Example(){return <Button label='Save'/>;}\n";
|
|
50
|
+
const formatted =
|
|
51
|
+
'// Keep this note\nexport default function Example() {\n return <Button label="Save" />;\n}\n';
|
|
52
|
+
expect(shadcnJavaScriptSourcesEquivalent(compact, formatted)).toBe(true);
|
|
53
|
+
expect(
|
|
54
|
+
shadcnJavaScriptSourcesEquivalent(
|
|
55
|
+
compact,
|
|
56
|
+
formatted.replace('Save', 'Delete'),
|
|
57
|
+
),
|
|
58
|
+
).toBe(false);
|
|
59
|
+
expect(
|
|
60
|
+
shadcnJavaScriptSourcesEquivalent(
|
|
61
|
+
compact,
|
|
62
|
+
formatted.replace('Keep this note', 'Changed note'),
|
|
63
|
+
),
|
|
64
|
+
).toBe(false);
|
|
65
|
+
expect(shadcnJavaScriptSourcesEquivalent('x++;\ny;\n', 'x\n++y;\n')).toBe(
|
|
66
|
+
false,
|
|
67
|
+
);
|
|
68
|
+
expect(
|
|
69
|
+
shadcnJavaScriptSourcesEquivalent(
|
|
70
|
+
'function value() { return 42; }\n',
|
|
71
|
+
'function value() { return\n42; }\n',
|
|
72
|
+
),
|
|
73
|
+
).toBe(false);
|
|
74
|
+
expect(shadcnJavaScriptSourcesEquivalent('not valid {', formatted)).toBe(
|
|
75
|
+
false,
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('pins every load-bearing transform dependency', () => {
|
|
80
|
+
const manifest = JSON.parse(
|
|
81
|
+
readFileSync('packages/cli/package.json', 'utf8'),
|
|
82
|
+
);
|
|
83
|
+
expect(manifest.dependencies).toMatchObject({
|
|
84
|
+
'@babel/core': '7.29.7',
|
|
85
|
+
'@babel/parser': '7.29.8',
|
|
86
|
+
'@babel/plugin-transform-typescript': '7.29.7',
|
|
87
|
+
'@babel/types': '7.29.8',
|
|
88
|
+
'ast-types': '0.16.3',
|
|
89
|
+
recast: '0.23.21',
|
|
90
|
+
});
|
|
91
|
+
const workspace = readFileSync('pnpm-workspace.yaml', 'utf8');
|
|
92
|
+
expect(workspace).toContain("'shadcn@4.19.0>@babel/core': 7.29.7");
|
|
93
|
+
expect(workspace).toContain("'shadcn@4.19.0>@babel/parser': 7.29.8");
|
|
94
|
+
expect(workspace).toContain(
|
|
95
|
+
"'shadcn@4.19.0>@babel/plugin-transform-typescript': 7.29.7",
|
|
96
|
+
);
|
|
97
|
+
expect(workspace).toContain("'shadcn@4.19.0>recast': 0.23.21");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('emits a narrow declaration for precompiled JavaScript', () => {
|
|
101
|
+
expect(
|
|
102
|
+
createShadcnPrecompiledDeclaration(
|
|
103
|
+
'components/astryx/examples/Example.jsx',
|
|
104
|
+
),
|
|
105
|
+
).toBe(
|
|
106
|
+
"declare module '*components/astryx/examples/Example' {\n" +
|
|
107
|
+
" const Component: import('react').ComponentType;\n" +
|
|
108
|
+
' export default Component;\n' +
|
|
109
|
+
'}\n',
|
|
110
|
+
);
|
|
111
|
+
expect(
|
|
112
|
+
shadcnPrecompiledDeclarationTarget(
|
|
113
|
+
'components/astryx/examples/Example.jsx',
|
|
114
|
+
),
|
|
115
|
+
).toBe('components/astryx/examples/Example.astryx.d.mts');
|
|
116
|
+
expect(() =>
|
|
117
|
+
createShadcnPrecompiledDeclaration('components/Example.tsx'),
|
|
118
|
+
).toThrow(/must be JavaScript/);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -35,9 +35,11 @@ import {emit, section, text, list, code} from '../formatters/index.mjs';
|
|
|
35
35
|
import {logger} from '../../../api/logger.mjs';
|
|
36
36
|
import {cliError} from '../lib/cli-error.mjs';
|
|
37
37
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
38
|
+
import {Project} from '../../../foundation/config/project.mjs';
|
|
39
|
+
import {warnOnIntegrationIssues} from '../../../foundation/integrations/integration-warnings.mjs';
|
|
38
40
|
import {themeAdd} from '../../../api/theme/add/add.mjs';
|
|
39
41
|
import {themeTemplate} from '../../../api/theme/template/template.mjs';
|
|
40
|
-
import {
|
|
42
|
+
import {themeListAvailable} from '../../../api/theme/list/list.mjs';
|
|
41
43
|
import {themeTargets} from '../../../api/theme/targets/targets.mjs';
|
|
42
44
|
import {
|
|
43
45
|
serializePaletteCandidate,
|
|
@@ -55,7 +57,7 @@ import {doc as themeTargetsCommand} from './theme-targets.doc.mjs';
|
|
|
55
57
|
import {doc as themePaletteGroup} from './theme-palette.doc.mjs';
|
|
56
58
|
import {doc as themePaletteGenerateCommand} from './theme-palette-generate.doc.mjs';
|
|
57
59
|
import {doc as themeBuildFn} from '../../../api/theme/themeBuild.doc.mjs';
|
|
58
|
-
import {doc as themeListFn} from '../../../api/theme/
|
|
60
|
+
import {doc as themeListFn} from '../../../api/theme/themeListAvailable.doc.mjs';
|
|
59
61
|
import {doc as themeAddFn} from '../../../api/theme/themeAdd.doc.mjs';
|
|
60
62
|
import {doc as themeTemplateFn} from '../../../api/theme/themeTemplate.doc.mjs';
|
|
61
63
|
import {doc as themeTargetsFn} from '../../../api/theme/themeTargets.doc.mjs';
|
|
@@ -181,14 +183,28 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
|
|
186
|
+
* Print the standard integration issue nudge without changing command results.
|
|
187
|
+
* @param {boolean} json
|
|
188
|
+
*/
|
|
189
|
+
async function warnOnThemeIntegrationIssues(json) {
|
|
190
|
+
try {
|
|
191
|
+
const project = await Project.load(process.cwd());
|
|
192
|
+
await project.themes();
|
|
193
|
+
await warnOnIntegrationIssues(project.loadedIntegrations, {json});
|
|
194
|
+
} catch {
|
|
195
|
+
// Never let the nudge break the command.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Emit available themes as a bulleted list plus the `theme add` usage hint —
|
|
201
|
+
* the human projection of a `theme.list` envelope. Each row names its owner so
|
|
202
|
+
* duplicate slugs are distinguishable.
|
|
187
203
|
* @param {import('../../../api/theme/theme.type.mjs').ThemeListEntry[]} themes
|
|
188
204
|
*/
|
|
189
205
|
function printThemeList(themes) {
|
|
190
206
|
if (themes.length === 0) {
|
|
191
|
-
emit(text('No themes are
|
|
207
|
+
emit(text('No themes are available in this project.'));
|
|
192
208
|
return;
|
|
193
209
|
}
|
|
194
210
|
const run = getCliInvocation();
|
|
@@ -196,7 +212,8 @@ function printThemeList(themes) {
|
|
|
196
212
|
section('Themes'),
|
|
197
213
|
list(
|
|
198
214
|
themes.map(t => {
|
|
199
|
-
const
|
|
215
|
+
const status = t.maintained ? 'maintained' : 'example';
|
|
216
|
+
const head = `${t.slug} (${status}, ${t.package})`;
|
|
200
217
|
return t.description ? [head, t.description] : head;
|
|
201
218
|
}),
|
|
202
219
|
),
|
|
@@ -215,7 +232,9 @@ function printThemeList(themes) {
|
|
|
215
232
|
*/
|
|
216
233
|
function formatTargetsTable(targets) {
|
|
217
234
|
const rows = targets.map(t => ({
|
|
218
|
-
key: t.
|
|
235
|
+
key: t.deprecatedFor
|
|
236
|
+
? `${t.key} [deprecated; use ${t.deprecatedFor}]`
|
|
237
|
+
: t.key,
|
|
219
238
|
component: t.component,
|
|
220
239
|
props: t.props.join(', ') || '-',
|
|
221
240
|
states: t.states.join(', ') || '-',
|
|
@@ -299,10 +318,13 @@ export function registerTheme(program) {
|
|
|
299
318
|
name: command.name(),
|
|
300
319
|
reason: 'available subcommand',
|
|
301
320
|
}));
|
|
302
|
-
return cliError(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
321
|
+
return cliError(
|
|
322
|
+
`unknown subcommand 'theme palette ${String(extras[0])}'`,
|
|
323
|
+
{
|
|
324
|
+
suggestions,
|
|
325
|
+
code: ERROR_CODES.ERR_UNKNOWN_SUBCOMMAND,
|
|
326
|
+
},
|
|
327
|
+
);
|
|
306
328
|
}
|
|
307
329
|
palette.help();
|
|
308
330
|
return NO_RESULT_SET;
|
|
@@ -518,12 +540,15 @@ export function registerTheme(program) {
|
|
|
518
540
|
|
|
519
541
|
defineCommand(theme, themeListCommand, {
|
|
520
542
|
fn: themeListFn,
|
|
521
|
-
action: async () => {
|
|
543
|
+
action: async (/** @type {{package?: string}} */ options) => {
|
|
522
544
|
const json = program.opts().json || false;
|
|
523
545
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeListResponse} */
|
|
524
546
|
let result;
|
|
525
547
|
try {
|
|
526
|
-
result =
|
|
548
|
+
result = await themeListAvailable({
|
|
549
|
+
cwd: process.cwd(),
|
|
550
|
+
package: options.package,
|
|
551
|
+
});
|
|
527
552
|
} catch (e) {
|
|
528
553
|
const err =
|
|
529
554
|
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
@@ -533,6 +558,7 @@ export function registerTheme(program) {
|
|
|
533
558
|
});
|
|
534
559
|
}
|
|
535
560
|
|
|
561
|
+
await warnOnThemeIntegrationIssues(json);
|
|
536
562
|
const answered = resultSet({
|
|
537
563
|
count: result.data.length,
|
|
538
564
|
resultKind: 'theme',
|
|
@@ -552,7 +578,7 @@ export function registerTheme(program) {
|
|
|
552
578
|
action: async (
|
|
553
579
|
/** @type {string | undefined} */ slug,
|
|
554
580
|
/** @type {string | undefined} */ targetPath,
|
|
555
|
-
/** @type {{list?: boolean, overwrite?: boolean}} */ options,
|
|
581
|
+
/** @type {{list?: boolean, overwrite?: boolean, package?: string}} */ options,
|
|
556
582
|
) => {
|
|
557
583
|
const json = program.opts().json || false;
|
|
558
584
|
|
|
@@ -565,11 +591,12 @@ export function registerTheme(program) {
|
|
|
565
591
|
try {
|
|
566
592
|
result =
|
|
567
593
|
options.list || !slug
|
|
568
|
-
?
|
|
594
|
+
? await themeListAvailable({cwd: process.cwd(), package: options.package})
|
|
569
595
|
: await themeAdd(slug, {
|
|
570
596
|
targetPath,
|
|
571
597
|
overwrite: options.overwrite,
|
|
572
598
|
cwd: process.cwd(),
|
|
599
|
+
package: options.package,
|
|
573
600
|
});
|
|
574
601
|
} catch (e) {
|
|
575
602
|
const err =
|
|
@@ -580,7 +607,8 @@ export function registerTheme(program) {
|
|
|
580
607
|
});
|
|
581
608
|
}
|
|
582
609
|
|
|
583
|
-
|
|
610
|
+
await warnOnThemeIntegrationIssues(json);
|
|
611
|
+
// `--list` (or no slug) browses all available themes; naming one copies it
|
|
584
612
|
// into the project, which is an effect with nothing to count.
|
|
585
613
|
const answered =
|
|
586
614
|
result.type === 'theme.list'
|
|
@@ -598,13 +626,20 @@ export function registerTheme(program) {
|
|
|
598
626
|
}
|
|
599
627
|
|
|
600
628
|
// theme.add — print where files landed + how to use the theme.
|
|
601
|
-
const {
|
|
629
|
+
const {
|
|
630
|
+
displayName,
|
|
631
|
+
outputDir,
|
|
632
|
+
entry,
|
|
633
|
+
exportName,
|
|
634
|
+
files,
|
|
635
|
+
package: owner,
|
|
636
|
+
} = result.data;
|
|
602
637
|
const entryModule = importSpecifier(
|
|
603
638
|
outputDir,
|
|
604
639
|
entry.replace(/\.tsx?$/, ''),
|
|
605
640
|
);
|
|
606
641
|
emit(
|
|
607
|
-
text(`[ok] Added ${displayName} theme to ${outputDir}/`),
|
|
642
|
+
text(`[ok] Added ${displayName} theme from ${owner} to ${outputDir}/`),
|
|
608
643
|
list(files.map(f => `${outputDir}/${f}`)),
|
|
609
644
|
text(
|
|
610
645
|
'Use it in your app (import path is relative to a file in src/ — adjust if yours lives elsewhere):',
|