@astryxdesign/cli 0.6.5 → 0.6.6
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 +87 -0
- package/README.md +16 -15
- package/api/build/_adapter.d.mts +50 -2
- package/api/build/_adapter.mjs +98 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/kit/kit.mjs +98 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +12 -2
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +338 -26
- package/api/integration/add-theme.test.mjs +314 -1
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +36 -5
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +194 -54
- package/api/search/search.test.mjs +825 -0
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +3 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/clients/cli/commands/build-theme.mjs +8 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +60 -16
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* The domain a search result belongs to.
|
|
6
6
|
*/
|
|
7
|
-
export type SearchDomain = "component" | "hook" | "doc" | "template";
|
|
7
|
+
export type SearchDomain = "component" | "hook" | "doc" | "template" | "theme";
|
|
8
8
|
/**
|
|
9
9
|
* A single ranked search result, tagged with its domain.
|
|
10
10
|
*/
|
|
@@ -14,7 +14,7 @@ export type SearchResultEntry = {
|
|
|
14
14
|
*/
|
|
15
15
|
domain: SearchDomain;
|
|
16
16
|
/**
|
|
17
|
-
* - Primary identifier (component/hook name, doc topic or docs-tree route, template dir).
|
|
17
|
+
* - Primary identifier (component/hook name, doc topic or docs-tree route, template dir, theme slug).
|
|
18
18
|
*/
|
|
19
19
|
name: string;
|
|
20
20
|
/**
|
|
@@ -30,7 +30,7 @@ export type SearchResultEntry = {
|
|
|
30
30
|
*/
|
|
31
31
|
description: string;
|
|
32
32
|
/**
|
|
33
|
-
* - Follow-up command to act on this result (e.g. `astryx component Button`).
|
|
33
|
+
* - Follow-up command to act on this result (e.g. `astryx component Button`, or `astryx theme add neutral` for a theme).
|
|
34
34
|
*/
|
|
35
35
|
command: string;
|
|
36
36
|
/**
|
|
@@ -46,7 +46,7 @@ export type SearchResultEntry = {
|
|
|
46
46
|
*/
|
|
47
47
|
section?: string | undefined;
|
|
48
48
|
/**
|
|
49
|
-
* - The npm package that authored a doc result
|
|
49
|
+
* - The npm package that authored a doc result (for a section, the package whose file the section came from), or that ships a theme result.
|
|
50
50
|
*/
|
|
51
51
|
package?: string | undefined;
|
|
52
52
|
/**
|
|
@@ -54,7 +54,7 @@ export type SearchResultEntry = {
|
|
|
54
54
|
*/
|
|
55
55
|
parent?: string | undefined;
|
|
56
56
|
/**
|
|
57
|
-
* - Friendly display name — present for template results.
|
|
57
|
+
* - Friendly display name — present for template and theme results.
|
|
58
58
|
*/
|
|
59
59
|
displayName?: string | undefined;
|
|
60
60
|
/**
|
|
@@ -9,24 +9,24 @@
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* The domain a search result belongs to.
|
|
12
|
-
* @typedef {'component' | 'hook' | 'doc' | 'template'} SearchDomain
|
|
12
|
+
* @typedef {'component' | 'hook' | 'doc' | 'template' | 'theme'} SearchDomain
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* A single ranked search result, tagged with its domain.
|
|
17
17
|
* @typedef {object} SearchResultEntry
|
|
18
18
|
* @property {SearchDomain} domain - Which content domain this result came from.
|
|
19
|
-
* @property {string} name - Primary identifier (component/hook name, doc topic or docs-tree route, template dir).
|
|
19
|
+
* @property {string} name - Primary identifier (component/hook name, doc topic or docs-tree route, template dir, theme slug).
|
|
20
20
|
* @property {number} score - Relevance score (higher is better).
|
|
21
21
|
* @property {string} reason - Human-readable reason the candidate matched (e.g. `keyword "button"`).
|
|
22
22
|
* @property {string} description - One-line description, when available.
|
|
23
|
-
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button`).
|
|
23
|
+
* @property {string} command - Follow-up command to act on this result (e.g. `astryx component Button`, or `astryx theme add neutral` for a theme).
|
|
24
24
|
* @property {string} [import] - Import path — present for component and hook results.
|
|
25
25
|
* @property {string} [title] - Doc title — present for doc results.
|
|
26
26
|
* @property {string} [section] - Section key — present when a doc result is one section of a topic; `command` reads only that section.
|
|
27
|
-
* @property {string} [package] - The npm package that authored a doc result
|
|
27
|
+
* @property {string} [package] - The npm package that authored a doc result (for a section, the package whose file the section came from), or that ships a theme result.
|
|
28
28
|
* @property {string} [parent] - Command that opens the level above a doc result — its topic's section list for a section, the docs-tree namespace it sits in for a tree node — so a reader can see the siblings and open another.
|
|
29
|
-
* @property {string} [displayName] - Friendly display name — present for template results.
|
|
29
|
+
* @property {string} [displayName] - Friendly display name — present for template and theme results.
|
|
30
30
|
* @property {'page' | 'block'} [kind] - Template kind (`page` | `block`) — present for template results.
|
|
31
31
|
*/
|
|
32
32
|
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
findIntegrationComponentSource,
|
|
26
26
|
} from '../../../foundation/discovery/component-discovery.mjs';
|
|
27
27
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
28
|
-
import {AstryxError} from '../../error.mjs';
|
|
28
|
+
import {AstryxError, writeFailed} from '../../error.mjs';
|
|
29
29
|
|
|
30
30
|
/** Default issue tracker for maintainer feedback after swizzling. */
|
|
31
31
|
const DEFAULT_ISSUES_URL = 'https://github.com/facebook/astryx/issues/new';
|
|
@@ -290,11 +290,21 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
290
290
|
);
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
fs.
|
|
293
|
+
const outputDirExisted = fs.existsSync(outputDir);
|
|
294
|
+
try {
|
|
295
|
+
fs.mkdirSync(outputDir, {recursive: true});
|
|
296
|
+
} catch (err) {
|
|
297
|
+
throw writeFailed(outputDir, cwd, err);
|
|
298
|
+
}
|
|
294
299
|
|
|
295
300
|
const files = fs.readdirSync(componentDir);
|
|
296
301
|
let copied = 0;
|
|
297
302
|
let usesStyleX = false;
|
|
303
|
+
// A copy that fails part-way undoes what it already wrote, so the report is
|
|
304
|
+
// true and a retry does not trip over half a component. Each entry keeps
|
|
305
|
+
// the bytes the file had before this run (null when the copy created it).
|
|
306
|
+
/** @type {Array<{dest: string, original: Buffer|null}>} */
|
|
307
|
+
const written = [];
|
|
298
308
|
for (const file of files) {
|
|
299
309
|
if (isExcludedFromCopy(file)) continue;
|
|
300
310
|
const srcPath = path.join(componentDir, file);
|
|
@@ -309,7 +319,25 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
309
319
|
) {
|
|
310
320
|
usesStyleX = true;
|
|
311
321
|
}
|
|
312
|
-
|
|
322
|
+
const dest = path.join(outputDir, file);
|
|
323
|
+
try {
|
|
324
|
+
// The snapshot read is guarded too: a destination that cannot be read
|
|
325
|
+
// back (no permission, or a directory with this name) must still undo
|
|
326
|
+
// the earlier writes and report ERR_WRITE_FAILED.
|
|
327
|
+
const original = fs.existsSync(dest) ? fs.readFileSync(dest) : null;
|
|
328
|
+
written.push({dest, original});
|
|
329
|
+
fs.writeFileSync(dest, content);
|
|
330
|
+
} catch (err) {
|
|
331
|
+
const unrestored = undoCopy(written);
|
|
332
|
+
if (!outputDirExisted) {
|
|
333
|
+
try {
|
|
334
|
+
fs.rmdirSync(outputDir);
|
|
335
|
+
} catch {
|
|
336
|
+
// Not empty (something could not be undone), or already gone.
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
throw writeFailed(dest, cwd, err, unrestored);
|
|
340
|
+
}
|
|
313
341
|
copied++;
|
|
314
342
|
}
|
|
315
343
|
|
|
@@ -333,3 +361,38 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
333
361
|
if (feedback) data.feedback = feedback;
|
|
334
362
|
return {type: 'swizzle.copy', data};
|
|
335
363
|
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Undo the writes of a copy that failed part-way, newest first: delete the
|
|
367
|
+
* files the copy created and put back the bytes of the files it replaced. A
|
|
368
|
+
* file whose bytes are already the original ones is left alone, so a write
|
|
369
|
+
* that failed before changing anything is not reported as unrestored.
|
|
370
|
+
*
|
|
371
|
+
* @param {Array<{dest: string, original: Buffer|null}>} written
|
|
372
|
+
* @returns {string[]} the files it could not restore
|
|
373
|
+
*/
|
|
374
|
+
function undoCopy(written) {
|
|
375
|
+
/** @type {string[]} */
|
|
376
|
+
const unrestored = [];
|
|
377
|
+
for (const {dest, original} of [...written].reverse()) {
|
|
378
|
+
try {
|
|
379
|
+
if (original == null) {
|
|
380
|
+
fs.rmSync(dest, {force: true});
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
/** @type {Buffer|null} */
|
|
384
|
+
let current = null;
|
|
385
|
+
try {
|
|
386
|
+
current = fs.readFileSync(dest);
|
|
387
|
+
} catch {
|
|
388
|
+
current = null;
|
|
389
|
+
}
|
|
390
|
+
if (current == null || !current.equals(original)) {
|
|
391
|
+
fs.writeFileSync(dest, original);
|
|
392
|
+
}
|
|
393
|
+
} catch {
|
|
394
|
+
unrestored.push(dest);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return unrestored;
|
|
398
|
+
}
|
|
@@ -101,6 +101,10 @@ export const doc = {
|
|
|
101
101
|
code: 'ERR_FILE_EXISTS',
|
|
102
102
|
when: 'copying would overwrite existing files and overwrite is not set',
|
|
103
103
|
},
|
|
104
|
+
{
|
|
105
|
+
code: 'ERR_WRITE_FAILED',
|
|
106
|
+
when: 'the output directory or a copied file could not be written (no permission, read-only mount, full disk)',
|
|
107
|
+
},
|
|
104
108
|
],
|
|
105
109
|
examples: [
|
|
106
110
|
{
|
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
isFilePathArg,
|
|
17
17
|
PathSafetyError,
|
|
18
18
|
} from '../../../foundation/fs/path-safety.mjs';
|
|
19
|
-
import {AstryxError} from '../../error.mjs';
|
|
19
|
+
import {AstryxError, writeFailed} from '../../error.mjs';
|
|
20
20
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {replaceDemoMedia} from '../../../foundation/discovery/template-adapter.mjs';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Scaffold an already-resolved template to `targetPath` (relative to `cwd`) and
|
|
@@ -80,13 +80,18 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
|
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
fs.mkdirSync(outputDir, {recursive: true});
|
|
84
|
-
|
|
85
83
|
// Strip demo image references so the scaffolded file renders without a
|
|
86
|
-
// Meta-only network dependency.
|
|
87
|
-
|
|
88
|
-
const outputSource =
|
|
89
|
-
|
|
84
|
+
// Meta-only network dependency. Read before any write, so a failure below
|
|
85
|
+
// leaves nothing behind.
|
|
86
|
+
const {source: outputSource, demoMediaReplaced} = replaceDemoMedia(
|
|
87
|
+
fs.readFileSync(match.filePath, 'utf-8'),
|
|
88
|
+
);
|
|
89
|
+
try {
|
|
90
|
+
fs.mkdirSync(outputDir, {recursive: true});
|
|
91
|
+
fs.writeFileSync(outputFilePath, outputSource);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
throw writeFailed(outputFilePath, cwd, err);
|
|
94
|
+
}
|
|
90
95
|
|
|
91
96
|
const relOutput = path.relative(cwd, outputDir) || '.';
|
|
92
97
|
return {
|
|
@@ -96,6 +101,7 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
|
|
|
96
101
|
outputDir: relOutput,
|
|
97
102
|
fileName: outputFileName,
|
|
98
103
|
filesCopied: 1,
|
|
104
|
+
demoMediaReplaced,
|
|
99
105
|
},
|
|
100
106
|
};
|
|
101
107
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The template.copy receipt discloses replaced demo media. Templates are
|
|
5
|
+
* picked by what their source contains, not by slug, so catalog renames do not
|
|
6
|
+
* break the suite.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as os from 'node:os';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import {template, discoverTemplates} from '../template.mjs';
|
|
14
|
+
|
|
15
|
+
const SLOW = 60_000;
|
|
16
|
+
const FIXTURE_REF = /\/template-assets\/[\w.-]+\.(\w+)/g;
|
|
17
|
+
const VIDEO = new Set(['mp4', 'webm', 'mov', 'ogv', 'm4v']);
|
|
18
|
+
|
|
19
|
+
/** @param {string} filePath */
|
|
20
|
+
const fixtureRefs = filePath =>
|
|
21
|
+
[...fs.readFileSync(filePath, 'utf-8').matchAll(FIXTURE_REF)].map(m =>
|
|
22
|
+
m[1].toLowerCase(),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {(refs: string[]) => boolean} predicate
|
|
27
|
+
* @param {'page' | 'block'} type
|
|
28
|
+
*/
|
|
29
|
+
async function findTemplate(type, predicate) {
|
|
30
|
+
const all = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
|
|
31
|
+
await discoverTemplates()
|
|
32
|
+
);
|
|
33
|
+
const ids = new Map();
|
|
34
|
+
for (const t of all) ids.set(t.dirName, (ids.get(t.dirName) ?? 0) + 1);
|
|
35
|
+
const found = all.find(
|
|
36
|
+
t =>
|
|
37
|
+
t.type === type &&
|
|
38
|
+
ids.get(t.dirName) === 1 &&
|
|
39
|
+
fs.existsSync(t.filePath) &&
|
|
40
|
+
predicate(fixtureRefs(t.filePath)),
|
|
41
|
+
);
|
|
42
|
+
if (!found) throw new Error(`no ${type} template matches`);
|
|
43
|
+
return {id: found.dirName, refs: fixtureRefs(found.filePath)};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('template.copy receipt — replaced demo media', () => {
|
|
47
|
+
let dir;
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-receipt-'));
|
|
50
|
+
});
|
|
51
|
+
afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
52
|
+
|
|
53
|
+
it('counts every demo image a page template carried, and leaves none behind', async () => {
|
|
54
|
+
const {id, refs} = await findTemplate(
|
|
55
|
+
'page',
|
|
56
|
+
r => r.length > 0 && r.every(ext => !VIDEO.has(ext)),
|
|
57
|
+
);
|
|
58
|
+
const res = await template(id, {targetPath: './dest', cwd: dir});
|
|
59
|
+
expect(res.type).toBe('template.copy');
|
|
60
|
+
expect(res.data.demoMediaReplaced).toBe(refs.length);
|
|
61
|
+
expect(
|
|
62
|
+
fs.readFileSync(path.join(dir, 'dest', 'page.tsx'), 'utf-8'),
|
|
63
|
+
).not.toContain('/template-assets/');
|
|
64
|
+
}, SLOW);
|
|
65
|
+
|
|
66
|
+
it('counts a demo video in a block template', async () => {
|
|
67
|
+
const {id, refs} = await findTemplate('block', r => r.some(ext => VIDEO.has(ext)));
|
|
68
|
+
const res = await template(id, {targetPath: './dest', cwd: dir});
|
|
69
|
+
expect(res.data.demoMediaReplaced).toBe(refs.length);
|
|
70
|
+
}, SLOW);
|
|
71
|
+
|
|
72
|
+
it('reports 0 when the template carries no demo media', async () => {
|
|
73
|
+
const {id} = await findTemplate('page', r => r.length === 0);
|
|
74
|
+
const res = await template(id, {targetPath: './dest', cwd: dir});
|
|
75
|
+
expect(res.data.demoMediaReplaced).toBe(0);
|
|
76
|
+
}, SLOW);
|
|
77
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file `template.show` leaf — return a resolved template's
|
|
5
|
-
* components it composes.
|
|
4
|
+
* @file `template.show` leaf — return a resolved template's source, exactly as
|
|
5
|
+
* `template.copy` writes it, plus the components it composes.
|
|
6
6
|
*
|
|
7
7
|
* @position api/template/show — reads the resolved match's source file; the
|
|
8
8
|
* template dispatcher routes `show` (and the no-target-path default) here.
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
import * as fs from 'node:fs';
|
|
12
12
|
import {AstryxError} from '../../error.mjs';
|
|
13
13
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
extractComponents,
|
|
16
|
+
replaceDemoMedia,
|
|
17
|
+
} from '../../../foundation/discovery/template-adapter.mjs';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Build the `template.show` envelope for an already-resolved template.
|
|
@@ -27,6 +30,13 @@ export function templateShow(match) {
|
|
|
27
30
|
);
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
// The source template.copy writes (spec:AST-028 FR7): a template printed and
|
|
34
|
+
// pasted must not keep a media path only Astryx's previews serve, and the
|
|
35
|
+
// caller is told how many it replaced, the way the copy receipt tells it.
|
|
36
|
+
const {source, demoMediaReplaced} = replaceDemoMedia(
|
|
37
|
+
fs.readFileSync(match.filePath, 'utf-8'),
|
|
38
|
+
);
|
|
39
|
+
|
|
30
40
|
return {
|
|
31
41
|
type: 'template.show',
|
|
32
42
|
data: {
|
|
@@ -34,7 +44,8 @@ export function templateShow(match) {
|
|
|
34
44
|
description: match.description,
|
|
35
45
|
type: match.type,
|
|
36
46
|
components: extractComponents(match.filePath),
|
|
37
|
-
source
|
|
47
|
+
source,
|
|
48
|
+
demoMediaReplaced,
|
|
38
49
|
},
|
|
39
50
|
};
|
|
40
51
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Colocated tests for the template.show leaf — the source it returns is
|
|
5
|
+
* the source template.copy writes. An agent that prints a template and pastes
|
|
6
|
+
* it must end up with the same file as one that scaffolds it, demo media
|
|
7
|
+
* included (spec:AST-028 FR7).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {describe, it, expect, beforeAll, afterAll} from 'vitest';
|
|
11
|
+
import * as fs from 'node:fs';
|
|
12
|
+
import * as os from 'node:os';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
import {discoverAll, template} from '../template.mjs';
|
|
15
|
+
import {templateCopy} from '../copy/copy.mjs';
|
|
16
|
+
import {templateShow} from './show.mjs';
|
|
17
|
+
|
|
18
|
+
const SLOW = 60_000;
|
|
19
|
+
/** Astryx's demo-media namespace: only its own previews serve these files. */
|
|
20
|
+
const FIXTURE = '/template-assets/';
|
|
21
|
+
const FIXTURE_IMAGE = /\/template-assets\/[^'"`\s]+\.(png|jpe?g|webp)/i;
|
|
22
|
+
|
|
23
|
+
const read = (/** @type {string} */ file) => fs.readFileSync(file, 'utf-8');
|
|
24
|
+
|
|
25
|
+
describe('template.show', () => {
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
let dir;
|
|
28
|
+
/** @type {Awaited<ReturnType<typeof discoverAll>>} */
|
|
29
|
+
let templates;
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-show-'));
|
|
32
|
+
templates = await discoverAll(dir);
|
|
33
|
+
}, SLOW);
|
|
34
|
+
afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
35
|
+
|
|
36
|
+
it('returns exactly the source copy writes, for every template', () => {
|
|
37
|
+
let withFixtures = 0;
|
|
38
|
+
templates.forEach((match, index) => {
|
|
39
|
+
if (read(match.filePath).includes(FIXTURE)) withFixtures += 1;
|
|
40
|
+
const shown = templateShow(match).data.source;
|
|
41
|
+
const copied = templateCopy(match, {targetPath: `out-${index}`, cwd: dir});
|
|
42
|
+
const written = read(
|
|
43
|
+
path.join(dir, copied.data.outputDir, copied.data.fileName),
|
|
44
|
+
);
|
|
45
|
+
expect(shown, match.dirName).toBe(written);
|
|
46
|
+
});
|
|
47
|
+
// The templates with demo media are the ones that used to differ.
|
|
48
|
+
expect(withFixtures).toBeGreaterThan(0);
|
|
49
|
+
}, SLOW);
|
|
50
|
+
|
|
51
|
+
it('reports a replaced count when the source changed, and 0 when it did not', () => {
|
|
52
|
+
let reported = 0;
|
|
53
|
+
for (const match of templates) {
|
|
54
|
+
const raw = read(match.filePath);
|
|
55
|
+
const {source, demoMediaReplaced} = templateShow(match).data;
|
|
56
|
+
if (source === raw) expect(demoMediaReplaced, match.dirName).toBe(0);
|
|
57
|
+
else expect(demoMediaReplaced, match.dirName).toBeGreaterThan(0);
|
|
58
|
+
reported += demoMediaReplaced;
|
|
59
|
+
}
|
|
60
|
+
expect(reported).toBeGreaterThan(0);
|
|
61
|
+
}, SLOW);
|
|
62
|
+
|
|
63
|
+
it('prints a placeholder where a template shows a demo image', async () => {
|
|
64
|
+
const match = templates.find(
|
|
65
|
+
t => t.type === 'page' && FIXTURE_IMAGE.test(read(t.filePath)),
|
|
66
|
+
);
|
|
67
|
+
expect(match).toBeDefined();
|
|
68
|
+
if (!match) return;
|
|
69
|
+
const res = await template(match.dirName, {type: 'page', cwd: dir});
|
|
70
|
+
expect(res.type).toBe('template.show');
|
|
71
|
+
if (res.type !== 'template.show') return;
|
|
72
|
+
expect(res.data.source).not.toContain(FIXTURE);
|
|
73
|
+
expect(res.data.source).toContain('data:image/svg+xml,');
|
|
74
|
+
expect(res.data.demoMediaReplaced).toBeGreaterThan(0);
|
|
75
|
+
}, SLOW);
|
|
76
|
+
});
|
|
@@ -125,6 +125,20 @@ describe('integration template discovery', () => {
|
|
|
125
125
|
expect(entry.description).toBe('pricing desc');
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
it("reads an integration template's keywords in search and build", async () => {
|
|
129
|
+
const pkgDir = installWidgets(tmpDir);
|
|
130
|
+
writeTemplate(pkgDir, 'observatory', {
|
|
131
|
+
kind: 'page',
|
|
132
|
+
body: "export default {type: 'page', name: 'Observatory', description: 'Live tiles over a sky view.', category: 'Dashboard - Observatory', keywords: ['telescope', 'star map']};\n",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const found = await search('telescope', {cwd: tmpDir, type: 'template'});
|
|
136
|
+
expect(found.data.results.map(r => r.name)).toContain('observatory');
|
|
137
|
+
const kit = await build('telescope star map page', {cwd: tmpDir});
|
|
138
|
+
if (kit.type !== 'build.kit') throw new Error(kit.type);
|
|
139
|
+
expect(kit.data.start?.name).toBe('observatory');
|
|
140
|
+
});
|
|
141
|
+
|
|
128
142
|
it('preserves integration block showcase metadata in list output', async () => {
|
|
129
143
|
const pkgDir = installWidgets(tmpDir);
|
|
130
144
|
writeTemplate(pkgDir, 'chart-showcase', {
|
|
@@ -41,4 +41,4 @@ export function template(name?: string, options?: {
|
|
|
41
41
|
export type DiscoveredTemplate = import("../../foundation/discovery/template-adapter.mjs").DiscoveredTemplate;
|
|
42
42
|
export type TemplateDiscoveryError = import("../../foundation/discovery/template-adapter.mjs").TemplateDiscoveryError;
|
|
43
43
|
export type TemplateDocModule = import("../../foundation/discovery/template-adapter.mjs").TemplateDocModule;
|
|
44
|
-
export { discoverAll, discoverAll as discoverTemplates, discoverAllWithErrors, discoverCoreTemplates, discoverIntegrationTemplatesForOne, stripTemplateAssetRefs, listTemplates, findRelatedBlocks, findShowcase, extractComponents } from "../../foundation/discovery/template-adapter.mjs";
|
|
44
|
+
export { discoverAll, discoverAll as discoverTemplates, discoverAllWithErrors, discoverCoreTemplates, discoverIntegrationTemplatesForOne, stripTemplateAssetRefs, replaceDemoMedia, listTemplates, findRelatedBlocks, findShowcase, extractComponents } from "../../foundation/discovery/template-adapter.mjs";
|
|
@@ -114,7 +114,7 @@ export const doc = {
|
|
|
114
114
|
{
|
|
115
115
|
type: 'template.show',
|
|
116
116
|
description:
|
|
117
|
-
"The resolved template's
|
|
117
|
+
"The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and `demoMediaReplaced` — how many Astryx demo media references (images, posters, videos) in the source were replaced with placeholders for you to swap for your own media.",
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
120
|
type: 'template.skeleton',
|
|
@@ -124,7 +124,7 @@ export const doc = {
|
|
|
124
124
|
{
|
|
125
125
|
type: 'template.copy',
|
|
126
126
|
description:
|
|
127
|
-
'A receipt after scaffolding the template into the project: the template id, output directory, written file name, and file
|
|
127
|
+
'A receipt after scaffolding the template into the project: the template id, output directory, written file name, file count, and `demoMediaReplaced` — how many Astryx demo media references (images, posters, videos) in the written file were replaced with placeholders for you to swap for your own media.',
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
130
|
type: 'template.cdn',
|
|
@@ -153,6 +153,10 @@ export const doc = {
|
|
|
153
153
|
code: 'ERR_FILE_EXISTS',
|
|
154
154
|
when: 'the copy target already exists and overwrite is not set',
|
|
155
155
|
},
|
|
156
|
+
{
|
|
157
|
+
code: 'ERR_WRITE_FAILED',
|
|
158
|
+
when: 'the copy target could not be written (no permission, read-only mount, full disk); nothing is written',
|
|
159
|
+
},
|
|
156
160
|
],
|
|
157
161
|
examples: [
|
|
158
162
|
{label: 'List templates', code: 'const {data} = await template();'},
|
|
@@ -67,6 +67,7 @@ export type TemplateShowResponse = {
|
|
|
67
67
|
type: "page" | "block";
|
|
68
68
|
components: string[];
|
|
69
69
|
source: string;
|
|
70
|
+
demoMediaReplaced: number;
|
|
70
71
|
};
|
|
71
72
|
};
|
|
72
73
|
/**
|
|
@@ -91,6 +92,7 @@ export type TemplateCopyResponse = {
|
|
|
91
92
|
outputDir: string;
|
|
92
93
|
fileName: string;
|
|
93
94
|
filesCopied: number;
|
|
95
|
+
demoMediaReplaced: number;
|
|
94
96
|
};
|
|
95
97
|
};
|
|
96
98
|
/**
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
* @property {'page' | 'block'} data.type
|
|
54
54
|
* @property {string[]} data.components
|
|
55
55
|
* @property {string} data.source
|
|
56
|
+
* @property {number} data.demoMediaReplaced Astryx demo media references (images, posters, videos) replaced in the returned source: images with a neutral placeholder, videos with an empty source. Swap in your own media at those points; no media is installed. 0 when the template carried none.
|
|
56
57
|
*/
|
|
57
58
|
|
|
58
59
|
/**
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
* @property {string} data.outputDir
|
|
76
77
|
* @property {string} data.fileName
|
|
77
78
|
* @property {number} data.filesCopied
|
|
79
|
+
* @property {number} data.demoMediaReplaced Astryx demo media references (images, posters, videos) replaced in the written file: images with a neutral placeholder, videos with an empty source. Swap in your own media at those points; no media is installed. 0 when the template carried none.
|
|
78
80
|
*/
|
|
79
81
|
|
|
80
82
|
/**
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Why `theme build` has no Core to generate with, and the fix for where it
|
|
6
|
+
* ran: the Astryx repository builds Core, an app installs it, and an installed
|
|
7
|
+
* Core that will not load is named.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} cwd
|
|
10
|
+
* @param {any} importError - Why the import failed, when it threw.
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export function coreUnavailableMessage(cwd: string, importError: any): string;
|
|
4
14
|
/**
|
|
5
15
|
* Import specifier for install/scaffold instructions. Drops a leading `src/`
|
|
6
16
|
* from the cwd-relative dir (most consumers import from a file under src/) but
|
|
@@ -106,3 +116,17 @@ export function themeBuildFamily(files: string[], options: {
|
|
|
106
116
|
* validateAdaptationEnrollment)
|
|
107
117
|
*/
|
|
108
118
|
export type ComponentValueClass = "builtin" | "enrollment" | "unresolved";
|
|
119
|
+
/**
|
|
120
|
+
* The bindings one Core provides: the namespaces interception spreads, the
|
|
121
|
+
* functions the build calls, and why the import failed, if it did.
|
|
122
|
+
*/
|
|
123
|
+
export type CoreBindings = {
|
|
124
|
+
themeModule: any;
|
|
125
|
+
rootModule: any;
|
|
126
|
+
importError: any;
|
|
127
|
+
defineTheme: any;
|
|
128
|
+
generateThemeRulesSplit: any;
|
|
129
|
+
generateOnMediaCSS: any;
|
|
130
|
+
generateAdaptationCSS: any;
|
|
131
|
+
dataTokenDefaults: any;
|
|
132
|
+
};
|