@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
package/api/theme/_adapter.mjs
CHANGED
|
@@ -1,63 +1,126 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file Shared data layer for
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* @file Shared data layer for `theme list` and `theme add`.
|
|
5
|
+
*
|
|
6
|
+
* `listThemes()` intentionally keeps its historical synchronous, bundled-only
|
|
7
|
+
* contract. Project-aware callers use `listAvailableThemes()`, which asks
|
|
8
|
+
* Project for the bundled catalog plus every installed integration catalog.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
11
|
+
import {Project} from '../../foundation/config/project.mjs';
|
|
12
|
+
import {
|
|
13
|
+
BUNDLED_THEME_PACKAGE,
|
|
14
|
+
MANIFEST_PATH,
|
|
15
|
+
THEMES_DIR,
|
|
16
|
+
discoverBundledThemes,
|
|
17
|
+
} from '../../foundation/discovery/theme-discovery.mjs';
|
|
13
18
|
import {AstryxError} from '../error.mjs';
|
|
14
19
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
|
|
18
|
-
/** The bundle manifest that lists every theme (+ its files). */
|
|
19
|
-
export const MANIFEST_PATH = path.join(THEMES_DIR, 'manifest.json');
|
|
21
|
+
export {BUNDLED_THEME_PACKAGE, MANIFEST_PATH, THEMES_DIR};
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
|
-
* A
|
|
23
|
-
* @typedef {
|
|
24
|
-
* @property {string} slug
|
|
25
|
-
* @property {string} displayName
|
|
26
|
-
* @property {string} description
|
|
27
|
-
* @property {boolean} maintained
|
|
28
|
-
* @property {string} entry
|
|
29
|
-
* @property {string} exportName
|
|
30
|
-
* @property {string[]} files
|
|
24
|
+
* A bundled theme entry kept for the historical public `listThemes()` helper.
|
|
25
|
+
* @typedef {Pick<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme, 'slug' | 'displayName' | 'description' | 'maintained' | 'entry' | 'exportName' | 'files'>} BundledTheme
|
|
31
26
|
*/
|
|
32
27
|
|
|
33
28
|
/**
|
|
34
|
-
*
|
|
29
|
+
* The themes bundled in this CLI build. Kept synchronous for compatibility with
|
|
30
|
+
* programmatic callers that use this low-level helper directly.
|
|
35
31
|
* @returns {BundledTheme[]}
|
|
36
32
|
*/
|
|
37
33
|
export function listThemes() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
return availableBundledThemes().map(theme => ({
|
|
35
|
+
slug: theme.slug,
|
|
36
|
+
displayName: theme.displayName,
|
|
37
|
+
description: theme.description,
|
|
38
|
+
maintained: theme.maintained,
|
|
39
|
+
entry: theme.entry,
|
|
40
|
+
exportName: theme.exportName,
|
|
41
|
+
files: theme.files,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @returns {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} */
|
|
46
|
+
function availableBundledThemes() {
|
|
41
47
|
try {
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
return discoverBundledThemes();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
throw new AstryxError(message, undefined, ERROR_CODES.ERR_NO_SOURCE);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Load available themes with any package-owned integration issues found while
|
|
57
|
+
* discovering them. The issue set lets a package-scoped lookup distinguish an
|
|
58
|
+
* absent theme from an installed package whose catalog is broken.
|
|
59
|
+
* @param {string} cwd
|
|
60
|
+
* @returns {Promise<{themes: import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[], issues: Array<import('../../foundation/integrations/issue').AstryxIntegrationIssue & {package: string}>}>}
|
|
61
|
+
*/
|
|
62
|
+
async function availableThemeState(cwd) {
|
|
63
|
+
try {
|
|
64
|
+
const project = await Project.load(cwd);
|
|
65
|
+
const themes = await project.themes();
|
|
66
|
+
return {themes, issues: await project.issues()};
|
|
67
|
+
} catch {
|
|
68
|
+
return {themes: availableBundledThemes(), issues: []};
|
|
49
69
|
}
|
|
50
|
-
return Array.isArray(manifest.themes) ? manifest.themes : [];
|
|
51
70
|
}
|
|
52
71
|
|
|
53
72
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
73
|
+
* Bundled themes plus source themes from integrations installed in `cwd`.
|
|
74
|
+
* A project/config load failure degrades to the bundled catalog, preserving the
|
|
75
|
+
* command's historical usefulness outside a configured project.
|
|
76
|
+
* @param {string} [cwd]
|
|
77
|
+
* @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]>}
|
|
78
|
+
*/
|
|
79
|
+
export async function listAvailableThemes(cwd = process.cwd()) {
|
|
80
|
+
return (await availableThemeState(cwd)).themes;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Resolve an available theme by case-insensitive slug and optional owner package.
|
|
85
|
+
* Duplicate slugs fail closed until the caller selects an owner.
|
|
56
86
|
* @param {string} [slug]
|
|
57
|
-
* @
|
|
87
|
+
* @param {{cwd?: string, package?: string}} [options]
|
|
88
|
+
* @returns {Promise<import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined>}
|
|
58
89
|
*/
|
|
59
|
-
export function findTheme(slug) {
|
|
90
|
+
export async function findTheme(slug, options = {}) {
|
|
60
91
|
if (!slug) return undefined;
|
|
61
|
-
const
|
|
62
|
-
|
|
92
|
+
const {themes, issues} = await availableThemeState(
|
|
93
|
+
options.cwd ?? process.cwd(),
|
|
94
|
+
);
|
|
95
|
+
const normalized = String(slug).toLowerCase();
|
|
96
|
+
const matches = themes.filter(
|
|
97
|
+
theme =>
|
|
98
|
+
theme.slug.toLowerCase() === normalized &&
|
|
99
|
+
(options.package == null || theme.package === options.package),
|
|
100
|
+
);
|
|
101
|
+
if (matches.length === 0 && options.package != null) {
|
|
102
|
+
const packageIssue = issues.find(
|
|
103
|
+
issue => issue.package === options.package && issue.severity === 'error',
|
|
104
|
+
);
|
|
105
|
+
if (packageIssue) {
|
|
106
|
+
throw new AstryxError(
|
|
107
|
+
`Theme package "${options.package}" is installed but unavailable: ${packageIssue.message}`,
|
|
108
|
+
undefined,
|
|
109
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (matches.length > 1) {
|
|
114
|
+
throw new AstryxError(
|
|
115
|
+
`Theme "${slug}" is provided by more than one package. Select one with --package.`,
|
|
116
|
+
matches.map(theme => ({
|
|
117
|
+
name: `${theme.slug} --package ${theme.package}`,
|
|
118
|
+
reason: theme.bundled
|
|
119
|
+
? 'bundled theme'
|
|
120
|
+
: `provided by ${theme.package}`,
|
|
121
|
+
})),
|
|
122
|
+
ERROR_CODES.ERR_AMBIGUOUS_THEME,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return matches[0];
|
|
63
126
|
}
|
package/api/theme/add/add.d.mts
CHANGED
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
* file (without `overwrite`), a missing bundled file, or a write failure.
|
|
10
10
|
*
|
|
11
11
|
* @param {string} slug
|
|
12
|
-
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} [options]
|
|
12
|
+
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}} [options]
|
|
13
13
|
* @returns {Promise<import('../theme.type.mjs').ThemeAddResponse>}
|
|
14
14
|
*/
|
|
15
15
|
export function themeAdd(slug: string, options?: {
|
|
16
16
|
targetPath?: string;
|
|
17
17
|
overwrite?: boolean;
|
|
18
18
|
cwd?: string;
|
|
19
|
+
package?: string;
|
|
19
20
|
}): Promise<import("../theme.type.mjs").ThemeAddResponse>;
|
package/api/theme/add/add.mjs
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file `astryx theme add` leaf — copies
|
|
5
|
-
*
|
|
6
|
-
* without needing the theme package. Which theme is resolved by ../_adapter.mjs;
|
|
4
|
+
* @file `astryx theme add` leaf — copies an available theme's source from the
|
|
5
|
+
* CLI bundle or an installed integration into the consumer's project so they own it.
|
|
7
6
|
* this leaf owns the copy I/O + path-safety and returns a `theme.add` receipt.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import * as fs from 'node:fs';
|
|
11
10
|
import * as path from 'node:path';
|
|
12
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
assertWithin,
|
|
13
|
+
PathSafetyError,
|
|
14
|
+
} from '../../../foundation/fs/path-safety.mjs';
|
|
13
15
|
import {AstryxError} from '../../error.mjs';
|
|
14
16
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
15
|
-
import {
|
|
17
|
+
import {listAvailableThemes, findTheme} from '../_adapter.mjs';
|
|
16
18
|
// Scaffolded files must not carry our repo boilerplate into a consumer's tree.
|
|
17
19
|
import {stripCopyrightHeader} from '../../../foundation/text/copyright-header.mjs';
|
|
18
20
|
|
|
@@ -32,25 +34,33 @@ function defaultTargetDir(slug) {
|
|
|
32
34
|
* file (without `overwrite`), a missing bundled file, or a write failure.
|
|
33
35
|
*
|
|
34
36
|
* @param {string} slug
|
|
35
|
-
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} [options]
|
|
37
|
+
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}} [options]
|
|
36
38
|
* @returns {Promise<import('../theme.type.mjs').ThemeAddResponse>}
|
|
37
39
|
*/
|
|
38
40
|
export async function themeAdd(slug, options = {}) {
|
|
39
|
-
const {
|
|
41
|
+
const {
|
|
42
|
+
targetPath,
|
|
43
|
+
overwrite = false,
|
|
44
|
+
cwd = process.cwd(),
|
|
45
|
+
package: packageName,
|
|
46
|
+
} = options;
|
|
40
47
|
|
|
41
|
-
const match = findTheme(slug);
|
|
48
|
+
const match = await findTheme(slug, {cwd, package: packageName});
|
|
42
49
|
if (!match) {
|
|
50
|
+
const available = await listAvailableThemes(cwd);
|
|
43
51
|
throw new AstryxError(
|
|
44
|
-
`Unknown theme "${slug}"`,
|
|
45
|
-
|
|
46
|
-
name:
|
|
47
|
-
reason:
|
|
52
|
+
`Unknown theme "${slug}"${packageName ? ` in package "${packageName}"` : ''}`,
|
|
53
|
+
available.map(theme => ({
|
|
54
|
+
name: `${theme.slug} --package ${theme.package}`,
|
|
55
|
+
reason: theme.bundled
|
|
56
|
+
? 'bundled theme'
|
|
57
|
+
: `provided by ${theme.package}`,
|
|
48
58
|
})),
|
|
49
59
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
50
60
|
);
|
|
51
61
|
}
|
|
52
62
|
|
|
53
|
-
const themeSrcDir =
|
|
63
|
+
const themeSrcDir = match.sourceDir;
|
|
54
64
|
|
|
55
65
|
// Path-safe destination; reject traversal outside cwd.
|
|
56
66
|
const rawTarget = targetPath || defaultTargetDir(match.slug);
|
|
@@ -68,11 +78,25 @@ export async function themeAdd(slug, options = {}) {
|
|
|
68
78
|
throw err;
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
let writes;
|
|
82
|
+
try {
|
|
83
|
+
writes = match.files.map(name => ({
|
|
84
|
+
name,
|
|
85
|
+
src: path.join(themeSrcDir, name),
|
|
86
|
+
dest: assertWithin(name, resolvedDir, {
|
|
87
|
+
label: `theme destination for ${name}`,
|
|
88
|
+
}),
|
|
89
|
+
}));
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (err instanceof PathSafetyError) {
|
|
92
|
+
throw new AstryxError(
|
|
93
|
+
err.message,
|
|
94
|
+
undefined,
|
|
95
|
+
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
76
100
|
for (const w of writes) {
|
|
77
101
|
if (!fs.existsSync(w.src)) {
|
|
78
102
|
throw new AstryxError(
|
|
@@ -106,10 +130,14 @@ export async function themeAdd(slug, options = {}) {
|
|
|
106
130
|
try {
|
|
107
131
|
fs.mkdirSync(resolvedDir, {recursive: true});
|
|
108
132
|
for (const w of writes) {
|
|
109
|
-
const
|
|
133
|
+
const dest = assertWithin(w.name, resolvedDir, {
|
|
134
|
+
label: `theme destination for ${w.name}`,
|
|
135
|
+
});
|
|
136
|
+
fs.mkdirSync(path.dirname(dest), {recursive: true});
|
|
137
|
+
const tmp = `${dest}.${process.pid}.tmp`;
|
|
110
138
|
const contents = stripCopyrightHeader(fs.readFileSync(w.src, 'utf-8'));
|
|
111
139
|
fs.writeFileSync(tmp, contents);
|
|
112
|
-
staged.push({tmp, dest
|
|
140
|
+
staged.push({tmp, dest});
|
|
113
141
|
}
|
|
114
142
|
for (const s of staged) {
|
|
115
143
|
fs.renameSync(s.tmp, s.dest);
|
|
@@ -122,6 +150,13 @@ export async function themeAdd(slug, options = {}) {
|
|
|
122
150
|
/* best-effort */
|
|
123
151
|
}
|
|
124
152
|
}
|
|
153
|
+
if (err instanceof PathSafetyError) {
|
|
154
|
+
throw new AstryxError(
|
|
155
|
+
err.message,
|
|
156
|
+
undefined,
|
|
157
|
+
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
125
160
|
throw new AstryxError(
|
|
126
161
|
`Failed to write theme files: ${/** @type {any} */ (err).message}`,
|
|
127
162
|
undefined,
|
|
@@ -136,6 +171,7 @@ export async function themeAdd(slug, options = {}) {
|
|
|
136
171
|
slug: match.slug,
|
|
137
172
|
displayName: match.displayName,
|
|
138
173
|
maintained: match.maintained,
|
|
174
|
+
package: match.package,
|
|
139
175
|
outputDir: relDir,
|
|
140
176
|
entry: match.entry,
|
|
141
177
|
exportName: match.exportName,
|
|
@@ -28,6 +28,7 @@ describe('themeAdd (api/theme/add)', () => {
|
|
|
28
28
|
const result = await themeAdd('neutral', {cwd: tmpDir});
|
|
29
29
|
expect(result.type).toBe('theme.add');
|
|
30
30
|
expect(result.data.slug).toBe('neutral');
|
|
31
|
+
expect(result.data.package).toBe('@astryxdesign/cli');
|
|
31
32
|
expect(result.data.outputDir).toBe(path.join('src', 'themes', 'neutral'));
|
|
32
33
|
expect(result.data.files.length).toBeGreaterThan(0);
|
|
33
34
|
for (const f of result.data.files) {
|
|
@@ -13,6 +13,31 @@
|
|
|
13
13
|
* @returns {string}
|
|
14
14
|
*/
|
|
15
15
|
export function importSpecifier(relDir: string, base: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Validate component overrides against one discovered target registry.
|
|
18
|
+
*
|
|
19
|
+
* @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
|
|
20
|
+
* @param {{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>}} knownComponents
|
|
21
|
+
* @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
export function validateComponentOverridesAgainstRegistry(themeDef: {
|
|
24
|
+
components?: Record<string, Record<string, unknown>>;
|
|
25
|
+
onDark?: {
|
|
26
|
+
components?: Record<string, Record<string, unknown>>;
|
|
27
|
+
};
|
|
28
|
+
onLight?: {
|
|
29
|
+
components?: Record<string, Record<string, unknown>>;
|
|
30
|
+
};
|
|
31
|
+
__onDark?: {
|
|
32
|
+
components?: Record<string, Record<string, unknown>>;
|
|
33
|
+
};
|
|
34
|
+
__onLight?: {
|
|
35
|
+
components?: Record<string, Record<string, unknown>>;
|
|
36
|
+
};
|
|
37
|
+
}, knownComponents: {
|
|
38
|
+
propsByKey: Record<string, string[]>;
|
|
39
|
+
deprecatedByKey: Record<string, string>;
|
|
40
|
+
}): string[];
|
|
16
41
|
/**
|
|
17
42
|
* Compile a defineTheme file to CSS + JS + .d.ts (and an optional
|
|
18
43
|
* `.variants.d.ts`). Performs the writes and returns a `theme.build` receipt,
|
|
@@ -54,7 +54,7 @@ import {logger} from '../../logger.mjs';
|
|
|
54
54
|
import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
|
|
55
55
|
import {
|
|
56
56
|
collectThemingTargets,
|
|
57
|
-
|
|
57
|
+
targetValidationRegistry,
|
|
58
58
|
} from '../../../foundation/discovery/theming-targets.mjs';
|
|
59
59
|
import {collectUnloadedFonts, formatFontLoadingHelp} from './font-warning.mjs';
|
|
60
60
|
import {interceptCore} from './core-interception.mjs';
|
|
@@ -1497,32 +1497,30 @@ ${iconType}export declare const ${toIdentifier(themeDef.name)}Theme: DefinedThem
|
|
|
1497
1497
|
|
|
1498
1498
|
/**
|
|
1499
1499
|
* Load known theme target keys from core component docs: the visual props AND
|
|
1500
|
-
*
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
* warnings rather than guessing from a second registry.
|
|
1500
|
+
* runtime states each target reflects, plus canonical replacements for
|
|
1501
|
+
* deprecated target keys. Deprecated targets remain accepted for compatibility,
|
|
1502
|
+
* but every use receives actionable build guidance. Returns null when docs are
|
|
1503
|
+
* unavailable so validation skips warnings rather than guessing from a second
|
|
1504
|
+
* registry.
|
|
1506
1505
|
*
|
|
1507
|
-
*
|
|
1508
|
-
* is exactly what this validator accepts.
|
|
1509
|
-
*
|
|
1510
|
-
* @returns {Promise<Record<string, string[]> | null>}
|
|
1506
|
+
* @returns {Promise<{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>} | null>}
|
|
1511
1507
|
*/
|
|
1512
1508
|
async function loadKnownComponents() {
|
|
1513
1509
|
const coreRoot = resolveCoreRoot();
|
|
1514
1510
|
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1515
1511
|
if (!coreSrc || !fs.existsSync(coreSrc)) return null;
|
|
1516
1512
|
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1513
|
+
const registry = targetValidationRegistry(
|
|
1514
|
+
await collectThemingTargets(coreSrc),
|
|
1515
|
+
);
|
|
1516
|
+
return Object.keys(registry.propsByKey).length > 0 ? registry : null;
|
|
1519
1517
|
}
|
|
1520
1518
|
|
|
1521
|
-
/** @type {Record<string, string[]> | null | undefined} */
|
|
1519
|
+
/** @type {{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>} | null | undefined} */
|
|
1522
1520
|
let knownComponentsCache;
|
|
1523
1521
|
|
|
1524
1522
|
/**
|
|
1525
|
-
* @returns {Promise<Record<string, string[]> | null>}
|
|
1523
|
+
* @returns {Promise<{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>} | null>}
|
|
1526
1524
|
*/
|
|
1527
1525
|
async function getKnownComponents() {
|
|
1528
1526
|
if (knownComponentsCache === undefined) {
|
|
@@ -1532,67 +1530,86 @@ async function getKnownComponents() {
|
|
|
1532
1530
|
}
|
|
1533
1531
|
|
|
1534
1532
|
/**
|
|
1535
|
-
* Validate component overrides
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1538
|
-
* @param {{
|
|
1539
|
-
* @returns {
|
|
1533
|
+
* Validate component overrides against one discovered target registry.
|
|
1534
|
+
*
|
|
1535
|
+
* @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
|
|
1536
|
+
* @param {{propsByKey: Record<string, string[]>, deprecatedByKey: Record<string, string>}} knownComponents
|
|
1537
|
+
* @returns {string[]}
|
|
1540
1538
|
*/
|
|
1541
|
-
|
|
1539
|
+
export function validateComponentOverridesAgainstRegistry(
|
|
1540
|
+
themeDef,
|
|
1541
|
+
knownComponents,
|
|
1542
|
+
) {
|
|
1542
1543
|
/** @type {string[]} */
|
|
1543
1544
|
const warnings = [];
|
|
1544
|
-
|
|
1545
|
-
|
|
1545
|
+
/** @type {{name: string, components: Record<string, Record<string, unknown>>}[]} */
|
|
1546
|
+
const layers = [...getThemeComponentLayers(themeDef)];
|
|
1547
|
+
let adaptationIndex = 0;
|
|
1548
|
+
for (const value of adaptationRuleValues(themeDef)) {
|
|
1549
|
+
adaptationIndex++;
|
|
1550
|
+
if (
|
|
1551
|
+
value.components &&
|
|
1552
|
+
typeof value.components === 'object' &&
|
|
1553
|
+
Object.keys(value.components).length > 0
|
|
1554
|
+
) {
|
|
1555
|
+
layers.push({
|
|
1556
|
+
name: `adaptation rule ${adaptationIndex}`,
|
|
1557
|
+
components: value.components,
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1546
1561
|
|
|
1547
|
-
const
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1562
|
+
for (const {name: layerName, components} of layers) {
|
|
1563
|
+
for (const [component, rules] of Object.entries(components)) {
|
|
1564
|
+
const location = layerName === 'base' ? '' : ` in ${layerName}`;
|
|
1565
|
+
if (!(component in knownComponents.propsByKey)) {
|
|
1566
|
+
const similar = Object.keys(knownComponents.propsByKey)
|
|
1567
|
+
.filter(k => {
|
|
1568
|
+
if (k.includes(component) || component.includes(k)) return true;
|
|
1569
|
+
if (Math.abs(k.length - component.length) <= 2) {
|
|
1570
|
+
let diff = 0;
|
|
1571
|
+
const longer = k.length >= component.length ? k : component;
|
|
1572
|
+
const shorter = k.length < component.length ? k : component;
|
|
1573
|
+
let j = 0;
|
|
1574
|
+
for (let i = 0; i < longer.length && diff <= 2; i++) {
|
|
1575
|
+
if (longer[i] !== shorter[j]) diff++;
|
|
1576
|
+
else j++;
|
|
1577
|
+
}
|
|
1578
|
+
diff += shorter.length - j;
|
|
1579
|
+
return diff <= 2;
|
|
1565
1580
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
.
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
warnings.push(`Unknown component "${component}".${hint}`);
|
|
1575
|
-
continue;
|
|
1576
|
-
}
|
|
1581
|
+
return false;
|
|
1582
|
+
})
|
|
1583
|
+
.slice(0, 3);
|
|
1584
|
+
const hint =
|
|
1585
|
+
similar.length > 0 ? ` Did you mean: ${similar.join(', ')}?` : '';
|
|
1586
|
+
warnings.push(`Unknown component "${component}".${hint}`);
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1577
1589
|
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
const
|
|
1586
|
-
for (const
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1590
|
+
const replacement = knownComponents.deprecatedByKey[component];
|
|
1591
|
+
if (replacement != null) {
|
|
1592
|
+
warnings.push(
|
|
1593
|
+
`Deprecated component target "${component}"${location}. Use "${replacement}" instead.`,
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
const knownProps = knownComponents.propsByKey[component];
|
|
1598
|
+
for (const key of Object.keys(rules)) {
|
|
1599
|
+
if (key === 'base') continue;
|
|
1600
|
+
|
|
1601
|
+
const pairs = key.split('+');
|
|
1602
|
+
for (const pair of pairs) {
|
|
1603
|
+
const [prop] = pair.split(':');
|
|
1604
|
+
if (prop && !knownProps.includes(prop)) {
|
|
1605
|
+
const hint =
|
|
1606
|
+
knownProps.length > 0
|
|
1607
|
+
? ` Known props/states: ${knownProps.join(', ')}`
|
|
1608
|
+
: ' This component has no variant props or states.';
|
|
1609
|
+
warnings.push(
|
|
1610
|
+
`Unknown prop "${prop}" on component "${component}".${hint}`,
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1596
1613
|
}
|
|
1597
1614
|
}
|
|
1598
1615
|
}
|
|
@@ -1601,6 +1618,20 @@ async function validateComponentOverrides(themeDef) {
|
|
|
1601
1618
|
return [...new Set(warnings)];
|
|
1602
1619
|
}
|
|
1603
1620
|
|
|
1621
|
+
/**
|
|
1622
|
+
* Validate component overrides in a theme definition.
|
|
1623
|
+
* Warns on unknown component names, deprecated targets, and unknown prop names.
|
|
1624
|
+
*
|
|
1625
|
+
* @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
|
|
1626
|
+
* @returns {Promise<string[]>}
|
|
1627
|
+
*/
|
|
1628
|
+
async function validateComponentOverrides(themeDef) {
|
|
1629
|
+
const knownComponents = await getKnownComponents();
|
|
1630
|
+
return knownComponents == null
|
|
1631
|
+
? []
|
|
1632
|
+
: validateComponentOverridesAgainstRegistry(themeDef, knownComponents);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1604
1635
|
/**
|
|
1605
1636
|
* Validate that themes don't set private (--_*) CSS custom properties directly.
|
|
1606
1637
|
* Private vars are internal implementation details managed by the derived var
|