@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,618 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Real package-boundary coverage for integration authoring. Authors a
|
|
5
|
+
* provider through the CLI, packs it, installs the tarball into a separate
|
|
6
|
+
* no-config consumer, then exercises packed docs, codemods, and source themes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import {spawnSync} from 'node:child_process';
|
|
13
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
14
|
+
|
|
15
|
+
let rootDir;
|
|
16
|
+
const CLI_BIN = path.join(
|
|
17
|
+
process.cwd(),
|
|
18
|
+
'packages',
|
|
19
|
+
'cli',
|
|
20
|
+
'clients',
|
|
21
|
+
'cli',
|
|
22
|
+
'bin',
|
|
23
|
+
'astryx.mjs',
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
function parseEnvelope(stdout) {
|
|
27
|
+
return JSON.parse(stdout.trim());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function writeJson(file, value) {
|
|
31
|
+
fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function runCliProcess(args, cwd) {
|
|
35
|
+
const result = spawnSync(process.execPath, [CLI_BIN, ...args], {
|
|
36
|
+
cwd,
|
|
37
|
+
encoding: 'utf-8',
|
|
38
|
+
timeout: 60_000,
|
|
39
|
+
env: process.env,
|
|
40
|
+
});
|
|
41
|
+
if (result.error) throw result.error;
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function runNpm(args, cwd) {
|
|
46
|
+
const command = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
47
|
+
const result = spawnSync(command, args, {
|
|
48
|
+
cwd,
|
|
49
|
+
encoding: 'utf-8',
|
|
50
|
+
timeout: 60_000,
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
npm_config_audit: 'false',
|
|
54
|
+
npm_config_fund: 'false',
|
|
55
|
+
npm_config_update_notifier: 'false',
|
|
56
|
+
npm_config_cache: path.join(rootDir, '.npm-cache'),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (result.error || result.status !== 0) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`npm ${args[0]} failed: ${result.error?.message ?? result.stderr.trim()}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return result.stdout;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
if (rootDir) fs.rmSync(rootDir, {recursive: true, force: true});
|
|
69
|
+
rootDir = undefined;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('integration authoring across a real npm package boundary', () => {
|
|
73
|
+
it('authors, packs, installs, upgrades, and builds contributed source', async () => {
|
|
74
|
+
rootDir = fs.mkdtempSync(
|
|
75
|
+
path.join(process.cwd(), '.astryx-theme-provider-consumer-'),
|
|
76
|
+
);
|
|
77
|
+
const providerDir = path.join(rootDir, 'provider');
|
|
78
|
+
const consumerDir = path.join(rootDir, 'consumer');
|
|
79
|
+
const packDir = path.join(rootDir, 'packed');
|
|
80
|
+
const coreVersion = JSON.parse(
|
|
81
|
+
fs.readFileSync(
|
|
82
|
+
path.join(process.cwd(), 'packages', 'core', 'package.json'),
|
|
83
|
+
'utf-8',
|
|
84
|
+
),
|
|
85
|
+
).version;
|
|
86
|
+
fs.mkdirSync(providerDir);
|
|
87
|
+
fs.mkdirSync(consumerDir);
|
|
88
|
+
fs.mkdirSync(packDir);
|
|
89
|
+
|
|
90
|
+
writeJson(path.join(providerDir, 'package.json'), {
|
|
91
|
+
name: '@acme/brand-integration',
|
|
92
|
+
version: '1.0.0',
|
|
93
|
+
type: 'module',
|
|
94
|
+
files: ['README.md'],
|
|
95
|
+
});
|
|
96
|
+
fs.writeFileSync(
|
|
97
|
+
path.join(providerDir, 'README.md'),
|
|
98
|
+
'# Acme brand integration\n',
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
for (const [kind, name] of [
|
|
102
|
+
['theme', 'ocean'],
|
|
103
|
+
['doc', 'brand-theme'],
|
|
104
|
+
['doc', 'theme-migration'],
|
|
105
|
+
]) {
|
|
106
|
+
const added = await runCli(
|
|
107
|
+
['integration', 'add', kind, name, '--json'],
|
|
108
|
+
providerDir,
|
|
109
|
+
);
|
|
110
|
+
expect(added.status, added.stderr).toBe(0);
|
|
111
|
+
expect(parseEnvelope(added.stdout)).toMatchObject({
|
|
112
|
+
type: 'integration.add',
|
|
113
|
+
data: {kind, name, written: true, dryRun: false},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const codemodName = 'packed-proof';
|
|
118
|
+
const codemodAdded = await runCli(
|
|
119
|
+
[
|
|
120
|
+
'integration',
|
|
121
|
+
'add',
|
|
122
|
+
'codemod',
|
|
123
|
+
codemodName,
|
|
124
|
+
'--to',
|
|
125
|
+
coreVersion,
|
|
126
|
+
'--json',
|
|
127
|
+
],
|
|
128
|
+
providerDir,
|
|
129
|
+
);
|
|
130
|
+
expect(codemodAdded.status, codemodAdded.stderr).toBe(0);
|
|
131
|
+
expect(parseEnvelope(codemodAdded.stdout)).toMatchObject({
|
|
132
|
+
type: 'integration.add',
|
|
133
|
+
data: {kind: 'codemod', name: codemodName, written: true},
|
|
134
|
+
});
|
|
135
|
+
const providerCodemod = path.join(
|
|
136
|
+
providerDir,
|
|
137
|
+
'codemods',
|
|
138
|
+
coreVersion,
|
|
139
|
+
`${codemodName}.mjs`,
|
|
140
|
+
);
|
|
141
|
+
fs.writeFileSync(
|
|
142
|
+
providerCodemod,
|
|
143
|
+
`export default {
|
|
144
|
+
type: 'code',
|
|
145
|
+
title: 'Packed proof',
|
|
146
|
+
transform(file) {
|
|
147
|
+
return file.source.replace(/old-token/g, 'new-token');
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
`,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const themeDir = path.join(providerDir, 'themes', 'ocean');
|
|
154
|
+
const paletteConfig = path.join(providerDir, 'palette.config.json');
|
|
155
|
+
writeJson(paletteConfig, {
|
|
156
|
+
modeStrategy: 'light-and-dark',
|
|
157
|
+
stops: [20, 50, 80],
|
|
158
|
+
families: [{id: 'blue', seed: '#0074e2'}],
|
|
159
|
+
});
|
|
160
|
+
const paletteOutput = path.join(
|
|
161
|
+
'themes',
|
|
162
|
+
'ocean',
|
|
163
|
+
'tokens',
|
|
164
|
+
'ocean.palette.ts',
|
|
165
|
+
);
|
|
166
|
+
const generatedPalette = await runCli(
|
|
167
|
+
[
|
|
168
|
+
'theme',
|
|
169
|
+
'palette',
|
|
170
|
+
'generate',
|
|
171
|
+
'palette.config.json',
|
|
172
|
+
'--out',
|
|
173
|
+
paletteOutput,
|
|
174
|
+
'--json',
|
|
175
|
+
],
|
|
176
|
+
providerDir,
|
|
177
|
+
);
|
|
178
|
+
expect(generatedPalette.status, generatedPalette.stderr).toBe(0);
|
|
179
|
+
expect(parseEnvelope(generatedPalette.stdout)).toMatchObject({
|
|
180
|
+
type: 'theme.palette.generate',
|
|
181
|
+
data: {
|
|
182
|
+
output: paletteOutput,
|
|
183
|
+
receipt: path.join(
|
|
184
|
+
'themes',
|
|
185
|
+
'ocean',
|
|
186
|
+
'tokens',
|
|
187
|
+
'ocean.palette.receipt.json',
|
|
188
|
+
),
|
|
189
|
+
written: true,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
fs.writeFileSync(
|
|
194
|
+
path.join(themeDir, 'oceanTheme.ts'),
|
|
195
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
196
|
+
import {palette} from './tokens/ocean.palette';
|
|
197
|
+
|
|
198
|
+
export const oceanTheme = defineTheme({
|
|
199
|
+
name: 'ocean',
|
|
200
|
+
tokens: {'--color-accent': palette.blue.light[50]},
|
|
201
|
+
});
|
|
202
|
+
`,
|
|
203
|
+
);
|
|
204
|
+
const catalogFile = path.join(providerDir, 'themes', 'manifest.json');
|
|
205
|
+
const catalog = JSON.parse(fs.readFileSync(catalogFile, 'utf-8'));
|
|
206
|
+
catalog.themes[0].files.push(
|
|
207
|
+
'tokens/ocean.palette.ts',
|
|
208
|
+
'tokens/ocean.palette.receipt.json',
|
|
209
|
+
);
|
|
210
|
+
writeJson(catalogFile, catalog);
|
|
211
|
+
|
|
212
|
+
const providerPackage = JSON.parse(
|
|
213
|
+
fs.readFileSync(path.join(providerDir, 'package.json'), 'utf-8'),
|
|
214
|
+
);
|
|
215
|
+
expect(providerPackage.files).toEqual([
|
|
216
|
+
'README.md',
|
|
217
|
+
'themes',
|
|
218
|
+
'astryx.integration.mjs',
|
|
219
|
+
'docs',
|
|
220
|
+
'codemods',
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
const checked = await runCli(
|
|
224
|
+
['integration', 'pack', '--check', '--json'],
|
|
225
|
+
providerDir,
|
|
226
|
+
);
|
|
227
|
+
expect(checked.status, checked.stderr).toBe(0);
|
|
228
|
+
const checkReceipt = parseEnvelope(checked.stdout);
|
|
229
|
+
expect(checkReceipt).toMatchObject({
|
|
230
|
+
type: 'integration.pack-check',
|
|
231
|
+
data: {
|
|
232
|
+
name: '@acme/brand-integration',
|
|
233
|
+
packable: true,
|
|
234
|
+
contributions: {
|
|
235
|
+
local: {
|
|
236
|
+
themes: [{slug: 'ocean', exportName: 'oceanTheme'}],
|
|
237
|
+
docs: ['brand-theme', 'theme-migration'],
|
|
238
|
+
codemods: [{version: coreVersion, id: codemodName}],
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
expect(checkReceipt.data.contributions.packed).toEqual(
|
|
244
|
+
checkReceipt.data.contributions.local,
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
const packOutput = JSON.parse(
|
|
248
|
+
runNpm(
|
|
249
|
+
['pack', '--json', '--silent', `--pack-destination=${packDir}`],
|
|
250
|
+
providerDir,
|
|
251
|
+
),
|
|
252
|
+
);
|
|
253
|
+
const tarball = path.join(packDir, packOutput[0].filename);
|
|
254
|
+
expect(fs.existsSync(tarball)).toBe(true);
|
|
255
|
+
|
|
256
|
+
writeJson(path.join(consumerDir, 'package.json'), {
|
|
257
|
+
name: 'theme-consumer',
|
|
258
|
+
version: '1.0.0',
|
|
259
|
+
private: true,
|
|
260
|
+
type: 'module',
|
|
261
|
+
});
|
|
262
|
+
runNpm(
|
|
263
|
+
[
|
|
264
|
+
'install',
|
|
265
|
+
'--ignore-scripts',
|
|
266
|
+
'--offline',
|
|
267
|
+
'--no-audit',
|
|
268
|
+
'--no-fund',
|
|
269
|
+
'--package-lock=false',
|
|
270
|
+
tarball,
|
|
271
|
+
],
|
|
272
|
+
consumerDir,
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const alternateProviderDir = path.join(rootDir, 'alternate-provider');
|
|
276
|
+
fs.mkdirSync(alternateProviderDir);
|
|
277
|
+
writeJson(path.join(alternateProviderDir, 'package.json'), {
|
|
278
|
+
name: '@acme/alternate-brand',
|
|
279
|
+
version: '1.0.0',
|
|
280
|
+
type: 'module',
|
|
281
|
+
files: [],
|
|
282
|
+
});
|
|
283
|
+
const alternateAdded = await runCli(
|
|
284
|
+
['integration', 'add', 'theme', 'ocean', '--json'],
|
|
285
|
+
alternateProviderDir,
|
|
286
|
+
);
|
|
287
|
+
expect(alternateAdded.status, alternateAdded.stderr).toBe(0);
|
|
288
|
+
const alternatePack = JSON.parse(
|
|
289
|
+
runNpm(
|
|
290
|
+
['pack', '--json', '--silent', `--pack-destination=${packDir}`],
|
|
291
|
+
alternateProviderDir,
|
|
292
|
+
),
|
|
293
|
+
);
|
|
294
|
+
runNpm(
|
|
295
|
+
[
|
|
296
|
+
'install',
|
|
297
|
+
'--ignore-scripts',
|
|
298
|
+
'--offline',
|
|
299
|
+
'--no-audit',
|
|
300
|
+
'--no-fund',
|
|
301
|
+
'--package-lock=false',
|
|
302
|
+
path.join(packDir, alternatePack[0].filename),
|
|
303
|
+
],
|
|
304
|
+
consumerDir,
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
const installedDir = path.join(
|
|
308
|
+
consumerDir,
|
|
309
|
+
'node_modules',
|
|
310
|
+
'@acme',
|
|
311
|
+
'brand-integration',
|
|
312
|
+
);
|
|
313
|
+
expect(fs.lstatSync(installedDir).isSymbolicLink()).toBe(false);
|
|
314
|
+
const alternateInstalledDir = path.join(
|
|
315
|
+
consumerDir,
|
|
316
|
+
'node_modules',
|
|
317
|
+
'@acme',
|
|
318
|
+
'alternate-brand',
|
|
319
|
+
);
|
|
320
|
+
expect(fs.lstatSync(alternateInstalledDir).isSymbolicLink()).toBe(false);
|
|
321
|
+
|
|
322
|
+
// The consumer installs both providers from tarballs. Link this checkout's
|
|
323
|
+
// Core package as the consumer's normal app dependency so the copied source
|
|
324
|
+
// can resolve the same peer it would get from `npm install @astryxdesign/core`.
|
|
325
|
+
const coreScope = path.join(consumerDir, 'node_modules', '@astryxdesign');
|
|
326
|
+
const coreLink = path.join(coreScope, 'core');
|
|
327
|
+
fs.mkdirSync(coreScope, {recursive: true});
|
|
328
|
+
fs.symlinkSync(
|
|
329
|
+
path.join(process.cwd(), 'packages', 'core'),
|
|
330
|
+
coreLink,
|
|
331
|
+
process.platform === 'win32' ? 'junction' : 'dir',
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const consumerSource = path.join(consumerDir, 'src', 'index.ts');
|
|
335
|
+
fs.mkdirSync(path.dirname(consumerSource), {recursive: true});
|
|
336
|
+
fs.writeFileSync(consumerSource, "export const value = 'old-token';\n");
|
|
337
|
+
const dryRun = await runCli(
|
|
338
|
+
[
|
|
339
|
+
'upgrade',
|
|
340
|
+
'--from',
|
|
341
|
+
'0.0.0',
|
|
342
|
+
'--integration',
|
|
343
|
+
'@acme/brand-integration',
|
|
344
|
+
'--path',
|
|
345
|
+
'src',
|
|
346
|
+
'--json',
|
|
347
|
+
],
|
|
348
|
+
consumerDir,
|
|
349
|
+
);
|
|
350
|
+
expect(dryRun.status, `${dryRun.stdout}\n${dryRun.stderr}`).toBe(0);
|
|
351
|
+
const dryRunReceipt = parseEnvelope(dryRun.stdout);
|
|
352
|
+
expect(dryRunReceipt).toMatchObject({
|
|
353
|
+
type: 'upgrade.run',
|
|
354
|
+
data: {
|
|
355
|
+
to: coreVersion,
|
|
356
|
+
integrations: expect.arrayContaining(['@acme/brand-integration']),
|
|
357
|
+
filesChanged: 1,
|
|
358
|
+
transformsApplied: 1,
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
expect(dryRunReceipt.data.codemods).toBeGreaterThan(0);
|
|
362
|
+
expect(fs.readFileSync(consumerSource, 'utf-8')).toBe(
|
|
363
|
+
"export const value = 'old-token';\n",
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
fs.rmSync(providerDir, {recursive: true, force: true});
|
|
367
|
+
fs.rmSync(alternateProviderDir, {recursive: true, force: true});
|
|
368
|
+
|
|
369
|
+
const consumerPackageFile = path.join(consumerDir, 'package.json');
|
|
370
|
+
const consumerPackage = JSON.parse(
|
|
371
|
+
fs.readFileSync(consumerPackageFile, 'utf-8'),
|
|
372
|
+
);
|
|
373
|
+
const providerSpec =
|
|
374
|
+
consumerPackage.dependencies['@acme/brand-integration'];
|
|
375
|
+
delete consumerPackage.dependencies['@acme/brand-integration'];
|
|
376
|
+
writeJson(consumerPackageFile, consumerPackage);
|
|
377
|
+
const undeclared = await runCli(
|
|
378
|
+
['theme', 'list', '--package', '@acme/brand-integration', '--json'],
|
|
379
|
+
consumerDir,
|
|
380
|
+
);
|
|
381
|
+
expect(undeclared.status, undeclared.stderr).toBe(0);
|
|
382
|
+
expect(parseEnvelope(undeclared.stdout).data).toEqual([]);
|
|
383
|
+
|
|
384
|
+
consumerPackage.devDependencies = {
|
|
385
|
+
'@acme/brand-integration': providerSpec,
|
|
386
|
+
};
|
|
387
|
+
writeJson(consumerPackageFile, consumerPackage);
|
|
388
|
+
const devLinked = await runCli(
|
|
389
|
+
['theme', 'list', '--package', '@acme/brand-integration', '--json'],
|
|
390
|
+
consumerDir,
|
|
391
|
+
);
|
|
392
|
+
expect(devLinked.status, devLinked.stderr).toBe(0);
|
|
393
|
+
expect(parseEnvelope(devLinked.stdout).data).toContainEqual(
|
|
394
|
+
expect.objectContaining({
|
|
395
|
+
slug: 'ocean',
|
|
396
|
+
package: '@acme/brand-integration',
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
delete consumerPackage.devDependencies;
|
|
401
|
+
consumerPackage.optionalDependencies = {
|
|
402
|
+
'@acme/brand-integration': providerSpec,
|
|
403
|
+
};
|
|
404
|
+
writeJson(consumerPackageFile, consumerPackage);
|
|
405
|
+
const optionalLinked = await runCli(
|
|
406
|
+
['theme', 'list', '--package', '@acme/brand-integration', '--json'],
|
|
407
|
+
consumerDir,
|
|
408
|
+
);
|
|
409
|
+
expect(optionalLinked.status, optionalLinked.stderr).toBe(0);
|
|
410
|
+
expect(parseEnvelope(optionalLinked.stdout).data).toContainEqual(
|
|
411
|
+
expect.objectContaining({
|
|
412
|
+
slug: 'ocean',
|
|
413
|
+
package: '@acme/brand-integration',
|
|
414
|
+
}),
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
delete consumerPackage.optionalDependencies;
|
|
418
|
+
consumerPackage.dependencies['@acme/brand-integration'] = providerSpec;
|
|
419
|
+
writeJson(consumerPackageFile, consumerPackage);
|
|
420
|
+
|
|
421
|
+
const listed = await runCli(['theme', 'list', '--json'], consumerDir);
|
|
422
|
+
expect(listed.status, listed.stderr).toBe(0);
|
|
423
|
+
expect(parseEnvelope(listed.stdout).data).toContainEqual(
|
|
424
|
+
expect.objectContaining({
|
|
425
|
+
slug: 'ocean',
|
|
426
|
+
package: '@acme/brand-integration',
|
|
427
|
+
}),
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
for (const topic of ['brand-theme', 'theme-migration']) {
|
|
431
|
+
const guide = await runCli(['docs', topic, '--json'], consumerDir);
|
|
432
|
+
expect(guide.status, guide.stderr).toBe(0);
|
|
433
|
+
expect(parseEnvelope(guide.stdout).data).toMatchObject({name: topic});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const ambiguous = await runCli(
|
|
437
|
+
['theme', 'add', 'ocean', 'src/themes/ambiguous', '--json'],
|
|
438
|
+
consumerDir,
|
|
439
|
+
);
|
|
440
|
+
expect(ambiguous.status).not.toBe(0);
|
|
441
|
+
expect(parseEnvelope(ambiguous.stdout)).toMatchObject({
|
|
442
|
+
code: 'ERR_AMBIGUOUS_THEME',
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
const target = path.join('src', 'themes', 'acme-ocean');
|
|
446
|
+
const copied = await runCli(
|
|
447
|
+
[
|
|
448
|
+
'theme',
|
|
449
|
+
'add',
|
|
450
|
+
'ocean',
|
|
451
|
+
target,
|
|
452
|
+
'--package',
|
|
453
|
+
'@acme/brand-integration',
|
|
454
|
+
'--json',
|
|
455
|
+
],
|
|
456
|
+
consumerDir,
|
|
457
|
+
);
|
|
458
|
+
expect(copied.status, copied.stderr).toBe(0);
|
|
459
|
+
expect(parseEnvelope(copied.stdout)).toMatchObject({
|
|
460
|
+
type: 'theme.add',
|
|
461
|
+
data: {
|
|
462
|
+
slug: 'ocean',
|
|
463
|
+
package: '@acme/brand-integration',
|
|
464
|
+
outputDir: target,
|
|
465
|
+
files: [
|
|
466
|
+
'oceanTheme.ts',
|
|
467
|
+
'tokens/ocean.palette.ts',
|
|
468
|
+
'tokens/ocean.palette.receipt.json',
|
|
469
|
+
],
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
expect(
|
|
473
|
+
fs.readFileSync(
|
|
474
|
+
path.join(consumerDir, target, 'tokens', 'ocean.palette.ts'),
|
|
475
|
+
'utf-8',
|
|
476
|
+
),
|
|
477
|
+
).toContain('export const palette');
|
|
478
|
+
expect(
|
|
479
|
+
JSON.parse(
|
|
480
|
+
fs.readFileSync(
|
|
481
|
+
path.join(
|
|
482
|
+
consumerDir,
|
|
483
|
+
target,
|
|
484
|
+
'tokens',
|
|
485
|
+
'ocean.palette.receipt.json',
|
|
486
|
+
),
|
|
487
|
+
'utf-8',
|
|
488
|
+
),
|
|
489
|
+
).recipe,
|
|
490
|
+
).toBe('astryx-oklch-v1');
|
|
491
|
+
|
|
492
|
+
const copiedEntry = path.join(target, 'oceanTheme.ts');
|
|
493
|
+
const built = await runCli(
|
|
494
|
+
['theme', 'build', copiedEntry, '--json'],
|
|
495
|
+
consumerDir,
|
|
496
|
+
);
|
|
497
|
+
expect(built.status, `${built.stdout}\n${built.stderr}`).toBe(0);
|
|
498
|
+
const buildReceipt = parseEnvelope(built.stdout);
|
|
499
|
+
expect(buildReceipt).toMatchObject({
|
|
500
|
+
type: 'theme.build',
|
|
501
|
+
data: {name: 'ocean'},
|
|
502
|
+
});
|
|
503
|
+
for (const output of Object.values(buildReceipt.data.outputs)) {
|
|
504
|
+
expect(fs.existsSync(path.join(consumerDir, output))).toBe(true);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const duplicate = await runCli(
|
|
508
|
+
[
|
|
509
|
+
'theme',
|
|
510
|
+
'add',
|
|
511
|
+
'ocean',
|
|
512
|
+
target,
|
|
513
|
+
'--package',
|
|
514
|
+
'@acme/brand-integration',
|
|
515
|
+
'--json',
|
|
516
|
+
],
|
|
517
|
+
consumerDir,
|
|
518
|
+
);
|
|
519
|
+
expect(duplicate.status).not.toBe(0);
|
|
520
|
+
expect(parseEnvelope(duplicate.stdout)).toMatchObject({
|
|
521
|
+
code: 'ERR_FILE_EXISTS',
|
|
522
|
+
});
|
|
523
|
+
const overwritten = await runCli(
|
|
524
|
+
[
|
|
525
|
+
'theme',
|
|
526
|
+
'add',
|
|
527
|
+
'ocean',
|
|
528
|
+
target,
|
|
529
|
+
'--package',
|
|
530
|
+
'@acme/brand-integration',
|
|
531
|
+
'--overwrite',
|
|
532
|
+
'--json',
|
|
533
|
+
],
|
|
534
|
+
consumerDir,
|
|
535
|
+
);
|
|
536
|
+
expect(overwritten.status, overwritten.stderr).toBe(0);
|
|
537
|
+
expect(parseEnvelope(overwritten.stdout).type).toBe('theme.add');
|
|
538
|
+
|
|
539
|
+
const installedCodemod = path.join(
|
|
540
|
+
installedDir,
|
|
541
|
+
'codemods',
|
|
542
|
+
coreVersion,
|
|
543
|
+
`${codemodName}.mjs`,
|
|
544
|
+
);
|
|
545
|
+
const validCodemod = fs.readFileSync(installedCodemod, 'utf-8');
|
|
546
|
+
fs.writeFileSync(installedCodemod, "export default {not: 'a codemod'};\n");
|
|
547
|
+
const invalidCodemod = runCliProcess(
|
|
548
|
+
[
|
|
549
|
+
'doctor',
|
|
550
|
+
'integration',
|
|
551
|
+
'validate',
|
|
552
|
+
'@acme/brand-integration',
|
|
553
|
+
'--json',
|
|
554
|
+
],
|
|
555
|
+
consumerDir,
|
|
556
|
+
);
|
|
557
|
+
expect(invalidCodemod.status).toBe(1);
|
|
558
|
+
const invalidCodemodEnvelope = parseEnvelope(invalidCodemod.stdout);
|
|
559
|
+
expect(invalidCodemodEnvelope).toMatchObject({
|
|
560
|
+
type: 'integration.validate',
|
|
561
|
+
data: {
|
|
562
|
+
name: '@acme/brand-integration',
|
|
563
|
+
issues: expect.arrayContaining([
|
|
564
|
+
expect.objectContaining({code: 'invalid_codemod', severity: 'error'}),
|
|
565
|
+
]),
|
|
566
|
+
},
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
fs.rmSync(path.join(installedDir, 'codemods'), {
|
|
570
|
+
recursive: true,
|
|
571
|
+
force: true,
|
|
572
|
+
});
|
|
573
|
+
const missingCodemods = runCliProcess(
|
|
574
|
+
[
|
|
575
|
+
'doctor',
|
|
576
|
+
'integration',
|
|
577
|
+
'validate',
|
|
578
|
+
'@acme/brand-integration',
|
|
579
|
+
'--json',
|
|
580
|
+
],
|
|
581
|
+
consumerDir,
|
|
582
|
+
);
|
|
583
|
+
expect(missingCodemods.status).toBe(1);
|
|
584
|
+
const missingCodemodsEnvelope = parseEnvelope(missingCodemods.stdout);
|
|
585
|
+
expect(missingCodemodsEnvelope).toMatchObject({
|
|
586
|
+
type: 'integration.validate',
|
|
587
|
+
data: {
|
|
588
|
+
name: '@acme/brand-integration',
|
|
589
|
+
issues: expect.arrayContaining([
|
|
590
|
+
expect.objectContaining({code: 'missing_root', severity: 'error'}),
|
|
591
|
+
]),
|
|
592
|
+
},
|
|
593
|
+
});
|
|
594
|
+
fs.mkdirSync(path.dirname(installedCodemod), {recursive: true});
|
|
595
|
+
fs.writeFileSync(installedCodemod, validCodemod);
|
|
596
|
+
|
|
597
|
+
fs.rmSync(
|
|
598
|
+
path.join(installedDir, 'themes', 'ocean', 'tokens', 'ocean.palette.ts'),
|
|
599
|
+
);
|
|
600
|
+
const corruptedInstall = await runCli(
|
|
601
|
+
[
|
|
602
|
+
'theme',
|
|
603
|
+
'add',
|
|
604
|
+
'ocean',
|
|
605
|
+
'src/themes/corrupted',
|
|
606
|
+
'--package',
|
|
607
|
+
'@acme/brand-integration',
|
|
608
|
+
'--json',
|
|
609
|
+
],
|
|
610
|
+
consumerDir,
|
|
611
|
+
);
|
|
612
|
+
expect(corruptedInstall.status).not.toBe(0);
|
|
613
|
+
expect(parseEnvelope(corruptedInstall.stdout)).toMatchObject({
|
|
614
|
+
code: 'ERR_THEME_INVALID',
|
|
615
|
+
error: expect.stringContaining('ocean.palette.ts'),
|
|
616
|
+
});
|
|
617
|
+
}, 120_000);
|
|
618
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').CommandDoc} */
|
|
4
|
+
export const doc = {
|
|
5
|
+
type: 'command',
|
|
6
|
+
name: 'integration',
|
|
7
|
+
displayName: 'astryx integration',
|
|
8
|
+
namespace: 'cli',
|
|
9
|
+
summary: 'Author and verify an Astryx integration package',
|
|
10
|
+
description:
|
|
11
|
+
'Add contributions that are valid on arrival, then prove the packed package exposes the same contributions a consumer will receive.',
|
|
12
|
+
subcommands: ['add', 'pack'],
|
|
13
|
+
examples: [
|
|
14
|
+
{
|
|
15
|
+
label: 'Add a component',
|
|
16
|
+
cli: 'astryx integration add component AcmeWidget',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: 'Check the package tarball',
|
|
20
|
+
cli: 'astryx integration pack --check',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
exitCodes: [
|
|
24
|
+
{code: 0, when: 'help is shown or a subcommand succeeds'},
|
|
25
|
+
{code: 1, when: 'an unknown subcommand is provided'},
|
|
26
|
+
],
|
|
27
|
+
related: ['doctor integration', 'theme add'],
|
|
28
|
+
};
|