@astryxdesign/cli 0.7.0-canary.450c68d → 0.7.0-canary.4ec1f4e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -33
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.test.mjs +28 -0
- package/api/doctor/theme-checks.mjs +10 -10
- package/api/doctor/theme-checks.test.mjs +5 -4
- package/api/gap-report/gap-report.doc.mjs +1 -1
- package/api/gap-report/gap-report.mjs +15 -0
- package/api/gap-report/gap-report.test.mjs +1 -1
- package/api/index.d.mts +0 -2
- package/api/index.mjs +0 -2
- package/api/init/init.doc.mjs +5 -1
- package/api/init/init.mjs +22 -0
- package/api/init/init.type.d.mts +4 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/remove/remove.mjs +8 -3
- package/api/init/remove/remove.test.mjs +12 -0
- package/api/init/run/run.d.mts +1 -1
- package/api/init/run/run.mjs +3 -3
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +5 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +0 -1
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +1 -1
- package/api/search/search.test.mjs +1 -1
- package/api/search/search.type.d.mts +1 -1
- package/api/search/search.type.mjs +1 -1
- package/api/template/template-integration.test.mjs +37 -100
- package/api/template/template.doc.mjs +5 -1
- package/api/template/template.mjs +45 -0
- package/api/theme/_adapter.mjs +3 -3
- package/api/theme/add/add.d.mts +11 -5
- package/api/theme/add/add.mjs +19 -192
- package/api/theme/add/add.test.mjs +68 -258
- package/api/theme/add/add.types.test.mjs +0 -1
- package/api/theme/build/build.d.mts +3 -3
- package/api/theme/build/build.mjs +22 -36
- package/api/theme/build/build.test.mjs +11 -24
- package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
- package/api/theme/integration-themes.test.mjs +3 -3
- package/api/theme/remove/remove.test.mjs +1 -1
- package/api/theme/targets/targets.test.mjs +0 -4
- package/api/theme/template/template.mjs +1 -1
- package/api/theme/theme.type.d.mts +1 -30
- package/api/theme/theme.type.mjs +3 -13
- package/api/theme/themeAdd.doc.mjs +19 -27
- package/api/theme/themeTargets.doc.mjs +3 -4
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/api/theme/use/use.test.mjs +1 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.mjs +19 -0
- package/assets/codemods/transforms/next/README.md +15 -17
- package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
- package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
- package/assets/docs/tree/versioning.doc.mjs +1 -4
- package/assets/docs/use-a-theme.doc.mjs +16 -16
- package/authoring/debug/type.ts +2 -2
- package/authoring/doctypes/base/type.ts +0 -9
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/command-result-coverage.test.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
- package/clients/cli/commands/build-theme.mjs +31 -67
- package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
- package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
- package/clients/cli/commands/discover.mjs +2 -1
- package/clients/cli/commands/doctor.mjs +5 -2
- package/clients/cli/commands/empty-argument.test.mjs +16 -0
- package/clients/cli/commands/gap-report.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.test.mjs +2 -2
- package/clients/cli/commands/init.doc.mjs +4 -4
- package/clients/cli/commands/init.flag-help.test.mjs +7 -10
- package/clients/cli/commands/init.next-steps.test.mjs +1 -1
- package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
- package/clients/cli/commands/search.test.mjs +1 -1
- package/clients/cli/commands/swizzle.mjs +4 -1
- package/clients/cli/commands/template.doc.mjs +3 -3
- package/clients/cli/commands/template.flag-help.test.mjs +18 -11
- package/clients/cli/commands/template.mjs +7 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
- package/clients/cli/commands/theme-add.doc.mjs +10 -17
- package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
- package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +1 -1
- package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
- package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/cli-error.mjs +19 -0
- package/clients/cli/lib/component-format.mjs +111 -57
- package/clients/cli/lib/component-format.test.mjs +28 -39
- package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
- package/clients/cli/lib/exit-codes.test.mjs +0 -7
- package/clients/cli/lib/json-shim.test.mjs +0 -24
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +6 -1
- package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
- package/foundation/config/theme-state.mjs +3 -3
- package/foundation/debug/debug-fields.test.mjs +13 -35
- package/foundation/debug/event.mjs +13 -78
- package/foundation/debug/privacy-contract.test.mjs +20 -12
- package/foundation/debug/redact.d.mts +2 -2
- package/foundation/debug/redact.mjs +2 -2
- package/foundation/discovery/theme-imports.mjs +1 -1
- package/foundation/discovery/theming-targets.d.mts +1 -20
- package/foundation/discovery/theming-targets.mjs +1 -38
- package/foundation/discovery/theming-targets.test.mjs +9 -175
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +11 -30
- package/foundation/response/response-types.doc.test.mjs +36 -14
- package/foundation/response/response.doc.mjs +1 -1
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/browser.mjs +2 -2
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/print.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -17
- package/api/layout/check/check.mjs +0 -41
- package/api/layout/expand/expand.d.mts +0 -23
- package/api/layout/expand/expand.mjs +0 -161
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/expand/expand.receipt.test.mjs +0 -74
- package/api/layout/grammar/grammar.d.mts +0 -14
- package/api/layout/grammar/grammar.mjs +0 -88
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -90
- package/api/layout/layout.type.mjs +0 -104
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/api/theme/add/add.binary.test.mjs +0 -157
- package/api/theme/add/add.rollback.test.mjs +0 -158
- package/api/theme/add/add.staging.test.mjs +0 -83
- package/clients/cli/commands/layout-check.doc.mjs +0 -67
- package/clients/cli/commands/layout-expand.doc.mjs +0 -87
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
- package/clients/cli/commands/layout.doc.mjs +0 -36
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
- package/clients/cli/commands/layout.mjs +0 -327
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file `astryx layout expand` leaf — expand a validated layout expression into
|
|
5
|
-
* XDS TSX (optionally written to disk). Resolution + validation come from
|
|
6
|
-
* ../_adapter.mjs (analyze); this leaf owns block-module assembly, code
|
|
7
|
-
* generation, and the path-safe write, and projects the `layout.expand` envelope.
|
|
8
|
-
*
|
|
9
|
-
* @input expression string (+ options)
|
|
10
|
-
* @output {type:'layout.expand', data}
|
|
11
|
-
* @position api — leaf over ../_adapter.mjs + lib/xle/expand
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import * as fs from 'node:fs';
|
|
15
|
-
import * as path from 'node:path';
|
|
16
|
-
import {AstryxError} from '../../error.mjs';
|
|
17
|
-
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
18
|
-
import {assertWithin, isFilePathArg, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
|
|
19
|
-
import {detectForm} from '../../../foundation/xle/parse.mjs';
|
|
20
|
-
import {expand} from '../../../foundation/xle/expand.mjs';
|
|
21
|
-
import {replaceDemoMedia} from '../../template/template.mjs';
|
|
22
|
-
import {analyze, formatIssue} from '../_adapter.mjs';
|
|
23
|
-
|
|
24
|
-
/** @param {string} name */
|
|
25
|
-
const normKey = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Collect the block names referenced by {hints} anywhere in the doc.
|
|
29
|
-
* @param {import('../../../foundation/xle/xle-ast').XLEDoc} doc
|
|
30
|
-
*/
|
|
31
|
-
function collectHintNames(doc) {
|
|
32
|
-
/** @type {Set<string>} */
|
|
33
|
-
const names = new Set();
|
|
34
|
-
/** @param {import('../../../foundation/xle/xle-ast').XLEItem} node */
|
|
35
|
-
const visitNode = (node) => {
|
|
36
|
-
if (!node || node.kind === 'group') {
|
|
37
|
-
(node?.children || []).forEach(visit);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (node.hint?.block) names.add(node.hint.block.name);
|
|
41
|
-
for (const slot of node.slots || []) {
|
|
42
|
-
const value = slot.value;
|
|
43
|
-
if (value && typeof value === 'object' && 'hint' in value && value.hint?.block) {
|
|
44
|
-
names.add(value.hint.block.name);
|
|
45
|
-
}
|
|
46
|
-
if (value && typeof value === 'object' && 'subexpr' in value) {
|
|
47
|
-
(value.subexpr || []).forEach(visit);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
(node.children || []).forEach(visit);
|
|
51
|
-
};
|
|
52
|
-
/** @param {import('../../../foundation/xle/xle-ast').XLEItem} item */
|
|
53
|
-
const visit = (item) => (item?.kind === 'group' ? item.children.forEach(visit) : visitNode(item));
|
|
54
|
-
doc.roots.forEach(visit);
|
|
55
|
-
doc.overlays.forEach(visit);
|
|
56
|
-
return names;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Build the blockModules map expand() needs: import-mode for app components,
|
|
61
|
-
* splice-mode (reading + asset-stripping the block source) for template blocks.
|
|
62
|
-
* Only blocks actually referenced are read. Also returns how many demo media
|
|
63
|
-
* references the splice-mode sources had replaced.
|
|
64
|
-
*
|
|
65
|
-
* @param {import('../../../foundation/xle/xle-ast').XLEDoc} doc
|
|
66
|
-
* @param {import('../_adapter.mjs').LayoutBlock[]} blocks
|
|
67
|
-
* @returns {{modules: Map<string, import('../../../foundation/xle/xle-ast').BlockModule>, demoMediaReplaced: number}}
|
|
68
|
-
*/
|
|
69
|
-
function buildBlockModules(doc, blocks) {
|
|
70
|
-
const referenced = collectHintNames(doc);
|
|
71
|
-
if (referenced.size === 0) return {modules: new Map(), demoMediaReplaced: 0};
|
|
72
|
-
const byKey = new Map(blocks.map(b => [normKey(b.dirName), b]));
|
|
73
|
-
/** @type {Map<string, import('../../../foundation/xle/xle-ast').BlockModule>} */
|
|
74
|
-
const modules = new Map();
|
|
75
|
-
let demoMediaReplaced = 0;
|
|
76
|
-
for (const name of referenced) {
|
|
77
|
-
const block = byKey.get(normKey(name));
|
|
78
|
-
if (!block) continue;
|
|
79
|
-
if (block.kind === 'component') {
|
|
80
|
-
modules.set(name, /** @type {import('../../../foundation/xle/xle-ast').BlockModule} */ (/** @type {unknown} */ ({mode: 'import', componentName: block.name, importPath: block.importPath, isDefault: block.isDefault})));
|
|
81
|
-
} else if (block.filePath && fs.existsSync(block.filePath)) {
|
|
82
|
-
const spliced = replaceDemoMedia(fs.readFileSync(block.filePath, 'utf-8'));
|
|
83
|
-
demoMediaReplaced += spliced.demoMediaReplaced;
|
|
84
|
-
modules.set(name, /** @type {import('../../../foundation/xle/xle-ast').BlockModule} */ ({mode: 'splice', componentName: block.dirName, source: spliced.source}));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return {modules, demoMediaReplaced};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @deprecated DEP-0006: Use `build`, `template`, and `docs layout` instead. Removal in CLN-0006.
|
|
92
|
-
* `astryx layout expand "<expr>" [path]`
|
|
93
|
-
*
|
|
94
|
-
* @param {string} expression
|
|
95
|
-
* @param {object} [options]
|
|
96
|
-
* @param {string} [options.targetPath] - write TSX here (validated against cwd)
|
|
97
|
-
* @param {'compact'|'outline'|'auto'} [options.form]
|
|
98
|
-
* @param {boolean} [options.loose] - downgrade unknown {hints} to TODO warnings
|
|
99
|
-
* @param {string} [options.name] - generated component name
|
|
100
|
-
* @param {string} [options.cwd]
|
|
101
|
-
* @returns {Promise<import('../layout.type.mjs').LayoutExpandResponse>}
|
|
102
|
-
*/
|
|
103
|
-
export async function layoutExpand(expression, options = {}) {
|
|
104
|
-
const {targetPath, form = 'auto', loose = false, name, cwd = process.cwd()} = options;
|
|
105
|
-
const {doc, registry, blocks, errors, warnings} = await analyze(expression, {form, loose, cwd});
|
|
106
|
-
|
|
107
|
-
if (errors.length > 0) {
|
|
108
|
-
throw new AstryxError(
|
|
109
|
-
`Layout expression is invalid:\n` + errors.map(e => ` - ${formatIssue(e)}`).join('\n'),
|
|
110
|
-
errors.flatMap(e => (e.suggestions || []).map(s => ({name: s, reason: 'did you mean this?'}))),
|
|
111
|
-
ERROR_CODES.ERR_LAYOUT_INVALID,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const componentName = name || 'GeneratedLayout';
|
|
116
|
-
if (!/^[A-Z][A-Za-z0-9]*$/.test(componentName)) {
|
|
117
|
-
throw new AstryxError(
|
|
118
|
-
`--name must be a PascalCase component name, got '${componentName}'`,
|
|
119
|
-
undefined,
|
|
120
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
const {modules: blockModules, demoMediaReplaced} = buildBlockModules(doc, blocks);
|
|
124
|
-
const result = expand(doc, registry, {componentName, blockModules});
|
|
125
|
-
|
|
126
|
-
let written = null;
|
|
127
|
-
if (targetPath) {
|
|
128
|
-
// The guard sees the file that will be written, not only its directory:
|
|
129
|
-
// a symlink at that name would otherwise carry the write outside the root.
|
|
130
|
-
const fileTarget = isFilePathArg(targetPath)
|
|
131
|
-
? targetPath
|
|
132
|
-
: path.join(targetPath, `${componentName}.tsx`);
|
|
133
|
-
let filePath;
|
|
134
|
-
try {
|
|
135
|
-
filePath = assertWithin(fileTarget, cwd, {label: 'layout target path'});
|
|
136
|
-
} catch (err) {
|
|
137
|
-
if (err instanceof PathSafetyError) {
|
|
138
|
-
throw new AstryxError(err.message, undefined, ERROR_CODES.ERR_PATH_TRAVERSAL);
|
|
139
|
-
}
|
|
140
|
-
throw err;
|
|
141
|
-
}
|
|
142
|
-
fs.mkdirSync(path.dirname(filePath), {recursive: true});
|
|
143
|
-
fs.writeFileSync(filePath, result.code);
|
|
144
|
-
written = path.relative(cwd, filePath);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
type: 'layout.expand',
|
|
149
|
-
data: {
|
|
150
|
-
form: form === 'auto' ? detectForm(expression) : form,
|
|
151
|
-
code: result.code,
|
|
152
|
-
componentsUsed: result.componentsUsed,
|
|
153
|
-
states: result.states,
|
|
154
|
-
todos: result.todos,
|
|
155
|
-
blocksReferenced: [...blockModules.entries()].map(([name, m]) => ({name, mode: m.mode})),
|
|
156
|
-
warnings: warnings.map(formatIssue),
|
|
157
|
-
written,
|
|
158
|
-
demoMediaReplaced,
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file Path-safety tests for the `layout.expand` write. The file written, not
|
|
5
|
-
* only the directory it lands in, must stay inside the project root.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {describe, it, expect, beforeAll} from 'vitest';
|
|
9
|
-
import * as fs from 'node:fs';
|
|
10
|
-
import * as os from 'node:os';
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import {layoutExpand} from '../layout.mjs';
|
|
13
|
-
import {buildRegistry} from '../../../foundation/xle/registry.mjs';
|
|
14
|
-
|
|
15
|
-
const SLOW = 30_000;
|
|
16
|
-
|
|
17
|
-
// The registry imports every component doc on first use; warm it once.
|
|
18
|
-
beforeAll(async () => {
|
|
19
|
-
await buildRegistry();
|
|
20
|
-
}, 120_000);
|
|
21
|
-
|
|
22
|
-
describe('layout.expand — write confinement', () => {
|
|
23
|
-
it('rejects a directory target whose generated file is a symlink leading outside cwd', async () => {
|
|
24
|
-
// Inside the workspace so @astryxdesign/core resolves.
|
|
25
|
-
const cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-confine-test-'));
|
|
26
|
-
const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'xle-confine-outside-'));
|
|
27
|
-
try {
|
|
28
|
-
const victim = path.join(outside, 'victim.tsx');
|
|
29
|
-
fs.writeFileSync(victim, 'OUTSIDE');
|
|
30
|
-
fs.mkdirSync(path.join(cwd, 'out'));
|
|
31
|
-
fs.symlinkSync(victim, path.join(cwd, 'out', 'GeneratedLayout.tsx'));
|
|
32
|
-
|
|
33
|
-
await expect(
|
|
34
|
-
layoutExpand('V > B', {targetPath: './out', cwd}),
|
|
35
|
-
).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
|
|
36
|
-
expect(fs.readFileSync(victim, 'utf-8')).toBe('OUTSIDE');
|
|
37
|
-
} finally {
|
|
38
|
-
fs.rmSync(cwd, {recursive: true, force: true});
|
|
39
|
-
fs.rmSync(outside, {recursive: true, force: true});
|
|
40
|
-
}
|
|
41
|
-
}, SLOW);
|
|
42
|
-
|
|
43
|
-
it('still writes <Name>.tsx into a plain directory target', async () => {
|
|
44
|
-
const cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-confine-test-'));
|
|
45
|
-
try {
|
|
46
|
-
const result = await layoutExpand('V > B', {targetPath: './out', name: 'Demo', cwd});
|
|
47
|
-
expect(result.data.written).toBe(path.join('out', 'Demo.tsx'));
|
|
48
|
-
expect(fs.existsSync(path.join(cwd, 'out', 'Demo.tsx'))).toBe(true);
|
|
49
|
-
} finally {
|
|
50
|
-
fs.rmSync(cwd, {recursive: true, force: true});
|
|
51
|
-
}
|
|
52
|
-
}, SLOW);
|
|
53
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file The layout.expand receipt discloses demo media replaced in the template
|
|
5
|
-
* blocks it splices. Blocks are picked by what their source contains, not by
|
|
6
|
-
* name, so catalog renames do not break the suite.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {describe, it, expect, beforeAll} from 'vitest';
|
|
10
|
-
import * as fs from 'node:fs';
|
|
11
|
-
import {layoutExpand} from '../layout.mjs';
|
|
12
|
-
import {discoverTemplates} from '../../template/template.mjs';
|
|
13
|
-
import {buildRegistry} from '../../../foundation/xle/registry.mjs';
|
|
14
|
-
|
|
15
|
-
const SLOW = 60_000;
|
|
16
|
-
const FIXTURE_REF = /\/template-assets\/[\w.-]+\.\w+/g;
|
|
17
|
-
|
|
18
|
-
beforeAll(async () => {
|
|
19
|
-
await buildRegistry();
|
|
20
|
-
}, 120_000);
|
|
21
|
-
|
|
22
|
-
/** @param {string} name */
|
|
23
|
-
const hintKey = name => name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
24
|
-
|
|
25
|
-
/** @type {Promise<Array<{hint: string, refs: number}>> | undefined} */
|
|
26
|
-
let catalog;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Template blocks a `{hint}` resolves to unambiguously, with the number of demo
|
|
30
|
-
* media references in each one's source.
|
|
31
|
-
* @returns {Promise<Array<{hint: string, refs: number}>>}
|
|
32
|
-
*/
|
|
33
|
-
function catalogBlocks() {
|
|
34
|
-
catalog ??= discoverTemplates().then(found => {
|
|
35
|
-
const all = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
|
|
36
|
-
found
|
|
37
|
-
).filter(t => t.type === 'block' && t.filePath && fs.existsSync(t.filePath));
|
|
38
|
-
const seen = new Map();
|
|
39
|
-
for (const t of all) seen.set(hintKey(t.dirName), (seen.get(hintKey(t.dirName)) ?? 0) + 1);
|
|
40
|
-
return all
|
|
41
|
-
.filter(t => seen.get(hintKey(t.dirName)) === 1)
|
|
42
|
-
.map(t => ({
|
|
43
|
-
hint: hintKey(t.dirName),
|
|
44
|
-
refs: (fs.readFileSync(t.filePath, 'utf-8').match(FIXTURE_REF) ?? []).length,
|
|
45
|
-
}));
|
|
46
|
-
});
|
|
47
|
-
return catalog;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
describe('layout.expand receipt - replaced demo media', () => {
|
|
51
|
-
it('counts the demo media of a spliced block once, however often it is referenced', async () => {
|
|
52
|
-
const block = (await catalogBlocks()).find(b => b.refs > 0);
|
|
53
|
-
if (!block) throw new Error('no template block carries demo media');
|
|
54
|
-
const res = await layoutExpand(`V > {${block.hint}}*3`);
|
|
55
|
-
expect(res.type).toBe('layout.expand');
|
|
56
|
-
expect(res.data.blocksReferenced).toHaveLength(1);
|
|
57
|
-
expect(res.data.demoMediaReplaced).toBe(block.refs);
|
|
58
|
-
expect(res.data.code).not.toContain('/template-assets/');
|
|
59
|
-
}, SLOW);
|
|
60
|
-
|
|
61
|
-
it('sums the demo media of every spliced block', async () => {
|
|
62
|
-
const [a, b] = (await catalogBlocks()).filter(x => x.refs > 0);
|
|
63
|
-
if (!b) throw new Error('fewer than two template blocks carry demo media');
|
|
64
|
-
const res = await layoutExpand(`V > {${a.hint}} + {${b.hint}}`);
|
|
65
|
-
expect(res.data.demoMediaReplaced).toBe(a.refs + b.refs);
|
|
66
|
-
}, SLOW);
|
|
67
|
-
|
|
68
|
-
it('reports 0 when nothing spliced carries demo media', async () => {
|
|
69
|
-
const plain = (await catalogBlocks()).find(b => b.refs === 0);
|
|
70
|
-
if (!plain) throw new Error('every template block carries demo media');
|
|
71
|
-
expect((await layoutExpand(`V > {${plain.hint}}`)).data.demoMediaReplaced).toBe(0);
|
|
72
|
-
expect((await layoutExpand('V > B"Save"')).data.demoMediaReplaced).toBe(0);
|
|
73
|
-
}, SLOW);
|
|
74
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
-
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated DEP-0006: Use `build`, `template`, and `docs layout` instead. Removal in CLN-0006.
|
|
6
|
-
* `astryx layout grammar` — the agent cheatsheet, with the alias table
|
|
7
|
-
* generated from this branch's registry (never hand-maintained).
|
|
8
|
-
*
|
|
9
|
-
* @param {{cwd?: string}} [options]
|
|
10
|
-
* @returns {Promise<import('../layout.type.mjs').LayoutGrammarResponse>}
|
|
11
|
-
*/
|
|
12
|
-
export function layoutGrammar(options?: {
|
|
13
|
-
cwd?: string;
|
|
14
|
-
}): Promise<import("../layout.type.mjs").LayoutGrammarResponse>;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file `astryx layout grammar` leaf — the agent cheatsheet, with the alias
|
|
5
|
-
* table generated from this branch's registry (never hand-maintained). Reads
|
|
6
|
-
* only the registry; shares nothing with expand/check, so it has no adapter.
|
|
7
|
-
*
|
|
8
|
-
* @output {type:'layout.grammar', data}
|
|
9
|
-
* @position api — leaf over lib/xle/registry
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import {buildRegistry} from '../../../foundation/xle/registry.mjs';
|
|
13
|
-
import {MAX_REPEAT} from '../../../foundation/xle/expand.mjs';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated DEP-0006: Use `build`, `template`, and `docs layout` instead. Removal in CLN-0006.
|
|
17
|
-
* `astryx layout grammar` — the agent cheatsheet, with the alias table
|
|
18
|
-
* generated from this branch's registry (never hand-maintained).
|
|
19
|
-
*
|
|
20
|
-
* @param {{cwd?: string}} [options]
|
|
21
|
-
* @returns {Promise<import('../layout.type.mjs').LayoutGrammarResponse>}
|
|
22
|
-
*/
|
|
23
|
-
export async function layoutGrammar(options = {}) {
|
|
24
|
-
const {cwd = process.cwd()} = options;
|
|
25
|
-
const registry = await buildRegistry({cwd});
|
|
26
|
-
|
|
27
|
-
/** @type {string[]} */
|
|
28
|
-
const aliasLines = [];
|
|
29
|
-
/** @type {Map<string, string[]>} */
|
|
30
|
-
const byTarget = new Map();
|
|
31
|
-
for (const [alias, target] of registry.aliases) {
|
|
32
|
-
if (!byTarget.has(target)) byTarget.set(target, []);
|
|
33
|
-
byTarget.get(target)?.push(alias);
|
|
34
|
-
}
|
|
35
|
-
for (const [target, aliases] of [...byTarget.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
36
|
-
aliasLines.push(`${aliases.join('/')}=${target}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const text = `XLE/XLO — XDS layout expressions (branch-generated; aliases reflect this install)
|
|
40
|
-
|
|
41
|
-
WORKFLOW
|
|
42
|
-
astryx layout check "<expr>" validate; echoes canonical compact + outline forms
|
|
43
|
-
astryx layout expand "<expr>" [path] emit validated TSX (path optional; --name <Pascal>)
|
|
44
|
-
Errors carry line/col + suggestions. Fix and resubmit; nothing is guessed.
|
|
45
|
-
|
|
46
|
-
TWO SURFACES, ONE LANGUAGE (autodetected; --form to force)
|
|
47
|
-
compact: A[cp6 @topNav=TN] > L > LC > S[p6] > (C{card-callout}*4) + T
|
|
48
|
-
outline: indentation = nesting · same-indent = siblings · "repeat N:" block = (...)*N
|
|
49
|
-
slot lines: topNav: TN (or a block: topNav:\\n TN ...)
|
|
50
|
-
|
|
51
|
-
NODE ANATOMY Name#id.enum"payload"[attrs]{hint}*N > children
|
|
52
|
-
.enum unique enum value of any prop: Bd.success Tx.lg B.primary
|
|
53
|
-
"payload" primary text prop (label/title/heading) or text child: TI"Email" B"Save"
|
|
54
|
-
{hint} kebab-case template/component reference (see TEMPLATE REFERENCING) — NEVER text
|
|
55
|
-
*N / xN repeat, at most ${MAX_REPEAT} copies (use $ for the counter: Tk"item-$"*3)
|
|
56
|
-
trailing ! initial selection for scaffolded state: Tab"Overview"!
|
|
57
|
-
|
|
58
|
-
ATTRS [...] (outline: bare tokens after the name, no brackets)
|
|
59
|
-
fused p6 g4 c4 w240 h2 cp2 mw960 rg2 cg2 (per-component: padding lives on Card/Section/AppShell.cp — p6 on AppShell/Layout/VStack errors with a correction)
|
|
60
|
-
key=value t=email href='/x' c{min:340} dv=[top,bottom] — keys validated per component
|
|
61
|
-
flags req opt dis striped hover divider … (isX/hasX props) · negate: !scroll
|
|
62
|
-
align j= main axis, a= cross axis — expander picks hAlign/vAlign per stack direction
|
|
63
|
-
slots @slotName=Node | @slotName=(sub > expr) | @slotName='text' | @slotName=#id
|
|
64
|
-
trigger opens=#id (a plain attr, no @ — binds an onClick that opens the overlay)
|
|
65
|
-
fill on a stack child → wraps in <StackItem size="fill">
|
|
66
|
-
|
|
67
|
-
TEMPLATE REFERENCING ({hint} pulls in real content — this is how XLE reaches past the @astryxdesign/core shell)
|
|
68
|
-
C{card-callout} splice a template block (astryx template --list --type block):
|
|
69
|
-
the block is co-defined once in the file, referenced, imports merged
|
|
70
|
-
{kpi-card} standalone reference (no wrapper element) — place a component directly
|
|
71
|
-
{kpi-card}*4 repeat a reference; the definition/import is emitted once
|
|
72
|
-
app components register local ones in astryx.config.mjs to import them by name:
|
|
73
|
-
export default {experimental: {xle: {components: {KpiCard: {from: '@/components/KpiCard'}}}}}
|
|
74
|
-
then {kpi-card} → import {KpiCard} + <KpiCard /> (kebab ↔ Pascal)
|
|
75
|
-
|
|
76
|
-
STRUCTURE THE EXPANDER HANDLES
|
|
77
|
-
Layout > LH + LC + LF + LP children auto-route into header/content/footer/start slots
|
|
78
|
-
T > (TR>THC*4) + (TR>TC*4)*6 rows partition into TableHeader/TableBody automatically
|
|
79
|
-
TabList/inputs required value+onChange scaffold typed useState automatically
|
|
80
|
-
overlays compact: tree ;; Dlg#confirm[...] · outline: overlays: section
|
|
81
|
-
trigger: B"Delete"[opens=#confirm]
|
|
82
|
-
|
|
83
|
-
ALIASES (full component names always valid; XDS prefix optional)
|
|
84
|
-
${aliasLines.join(' ')}
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
return {type: 'layout.grammar', data: {text, aliases: Object.fromEntries(registry.aliases)}};
|
|
88
|
-
}
|
package/api/layout/layout.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
-
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
-
|
|
4
|
-
export { layoutExpand } from "./expand/expand.mjs";
|
|
5
|
-
export { layoutCheck } from "./check/check.mjs";
|
|
6
|
-
export { layoutGrammar } from "./grammar/grammar.mjs";
|
package/api/layout/layout.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file `layout` command barrel — re-exports the expand/check/grammar leaves so
|
|
5
|
-
* the CLI (cli/commands/layout.mjs) and scripted callers import from one place.
|
|
6
|
-
* Each leaf is also importable directly (e.g. api/layout/expand/expand.mjs). The
|
|
7
|
-
* shared analysis core lives in ./_adapter.mjs. `layout` has real subcommands,
|
|
8
|
-
* so there is no flag-dispatch here — the CLI calls the leaf it wants.
|
|
9
|
-
*
|
|
10
|
-
* @input layout expressions (+ options), per leaf
|
|
11
|
-
* @output {type, data} envelopes: layout.expand / layout.check / layout.grammar
|
|
12
|
-
* @position api — command barrel over the expand/check/grammar leaves
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export {layoutExpand} from './expand/expand.mjs';
|
|
16
|
-
export {layoutCheck} from './check/check.mjs';
|
|
17
|
-
export {layoutGrammar} from './grammar/grammar.mjs';
|