@astryxdesign/cli 0.6.5-vanilla-poc.6e25cfc → 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.
Files changed (197) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +1 -34
  3. package/api/build/_adapter.d.mts +14 -0
  4. package/api/build/_adapter.mjs +58 -1
  5. package/api/build/build.test.mjs +74 -1
  6. package/api/build/kit/kit.mjs +39 -7
  7. package/api/build/kit/rank.d.mts +8 -0
  8. package/api/build/kit/rank.mjs +14 -0
  9. package/api/build/kit/weights.d.mts +82 -0
  10. package/api/build/kit/weights.json +1 -0
  11. package/api/build/kit/weights.mjs +305 -0
  12. package/api/build/kit/weights.test.mjs +190 -0
  13. package/api/component/_adapter.d.mts +1 -51
  14. package/api/component/_adapter.mjs +3 -110
  15. package/api/component/component.d.mts +1 -9
  16. package/api/component/component.doc.mjs +7 -52
  17. package/api/component/component.mjs +3 -276
  18. package/api/component/component.type.d.mts +1 -28
  19. package/api/component/component.type.mjs +1 -20
  20. package/api/docs/docs.d.mts +6 -0
  21. package/api/docs/docs.depth.test.mjs +132 -0
  22. package/api/docs/docs.doc.mjs +31 -2
  23. package/api/docs/docs.mjs +44 -1
  24. package/api/docs/docs.type.d.mts +38 -1
  25. package/api/docs/docs.type.mjs +18 -1
  26. package/api/docs/node/node.d.mts +28 -3
  27. package/api/docs/node/node.mjs +146 -23
  28. package/api/hook/list/list.d.mts +1 -1
  29. package/api/index.d.mts +0 -8
  30. package/api/index.mjs +0 -8
  31. package/api/integration/add-theme.mjs +93 -3
  32. package/api/integration/add-theme.test.mjs +100 -0
  33. package/api/integration/integrationAddTheme.doc.mjs +1 -1
  34. package/api/search/search.d.mts +8 -1
  35. package/api/search/search.doc.mjs +3 -3
  36. package/api/search/search.mjs +58 -73
  37. package/api/search/search.test.mjs +122 -21
  38. package/api/search/search.type.d.mts +0 -10
  39. package/api/search/search.type.mjs +0 -1
  40. package/api/template/cdn/cdn.test.mjs +2 -50
  41. package/api/template/template.d.mts +0 -6
  42. package/api/template/template.doc.mjs +4 -56
  43. package/api/template/template.mjs +0 -82
  44. package/api/template/template.type.d.mts +0 -12
  45. package/api/template/template.type.mjs +0 -7
  46. package/assets/cdn.template.html +5 -19
  47. package/assets/docs/tokens.doc.mjs +3 -3
  48. package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
  49. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  50. package/clients/cli/commands/component/index.mjs +9 -66
  51. package/clients/cli/commands/component.doc.mjs +4 -26
  52. package/clients/cli/commands/docs.depth.test.mjs +219 -0
  53. package/clients/cli/commands/docs.doc.mjs +15 -2
  54. package/clients/cli/commands/docs.mjs +222 -5
  55. package/clients/cli/commands/integration-add.doc.mjs +1 -1
  56. package/clients/cli/commands/search.doc.mjs +2 -3
  57. package/clients/cli/commands/search.mjs +11 -8
  58. package/clients/cli/commands/search.test.mjs +35 -40
  59. package/clients/cli/commands/template.doc.mjs +3 -31
  60. package/clients/cli/commands/template.mjs +2 -37
  61. package/foundation/discovery/theme-discovery.d.mts +6 -0
  62. package/foundation/discovery/theme-discovery.mjs +9 -0
  63. package/foundation/response/response-types.doc.mjs +0 -38
  64. package/package.json +5 -9
  65. package/api/_vanilla-assets.d.mts +0 -10
  66. package/api/_vanilla-assets.mjs +0 -59
  67. package/api/component/html/html.d.mts +0 -12
  68. package/api/component/html/html.doc.d.mts +0 -5
  69. package/api/component/html/html.doc.mjs +0 -66
  70. package/api/component/html/html.mjs +0 -25
  71. package/api/component/html/html.test.mjs +0 -61
  72. package/api/component/html/html.type.d.mts +0 -23
  73. package/api/component/html/html.type.mjs +0 -27
  74. package/api/component/web-components/web-components.d.mts +0 -12
  75. package/api/component/web-components/web-components.doc.d.mts +0 -5
  76. package/api/component/web-components/web-components.doc.mjs +0 -70
  77. package/api/component/web-components/web-components.mjs +0 -32
  78. package/api/component/web-components/web-components.test.mjs +0 -50
  79. package/api/component/web-components/web-components.type.d.mts +0 -23
  80. package/api/component/web-components/web-components.type.mjs +0 -27
  81. package/api/template/_adapter.d.mts +0 -38
  82. package/api/template/_adapter.mjs +0 -90
  83. package/api/template/html/html.d.mts +0 -17
  84. package/api/template/html/html.doc.d.mts +0 -5
  85. package/api/template/html/html.doc.mjs +0 -72
  86. package/api/template/html/html.mjs +0 -61
  87. package/api/template/html/html.test.mjs +0 -71
  88. package/api/template/html/html.type.d.mts +0 -26
  89. package/api/template/html/html.type.mjs +0 -28
  90. package/api/template/web-components/web-components.d.mts +0 -13
  91. package/api/template/web-components/web-components.doc.d.mts +0 -5
  92. package/api/template/web-components/web-components.doc.mjs +0 -69
  93. package/api/template/web-components/web-components.mjs +0 -51
  94. package/api/template/web-components/web-components.test.mjs +0 -73
  95. package/api/template/web-components/web-components.type.d.mts +0 -26
  96. package/api/template/web-components/web-components.type.mjs +0 -28
  97. package/assets/generated/core-component-docs.json +0 -1
  98. package/assets/vanilla/elements-markup/Avatar.html +0 -27
  99. package/assets/vanilla/elements-markup/Badge.html +0 -16
  100. package/assets/vanilla/elements-markup/Banner.html +0 -32
  101. package/assets/vanilla/elements-markup/Breadcrumbs.html +0 -23
  102. package/assets/vanilla/elements-markup/Button.html +0 -37
  103. package/assets/vanilla/elements-markup/Card.html +0 -24
  104. package/assets/vanilla/elements-markup/CheckboxInput.html +0 -28
  105. package/assets/vanilla/elements-markup/Collapsible.html +0 -26
  106. package/assets/vanilla/elements-markup/DateInput.html +0 -28
  107. package/assets/vanilla/elements-markup/Dialog.html +0 -33
  108. package/assets/vanilla/elements-markup/Divider.html +0 -20
  109. package/assets/vanilla/elements-markup/DropdownMenu.html +0 -26
  110. package/assets/vanilla/elements-markup/EmptyState.html +0 -27
  111. package/assets/vanilla/elements-markup/Heading.html +0 -18
  112. package/assets/vanilla/elements-markup/HoverCard.html +0 -39
  113. package/assets/vanilla/elements-markup/Layout.html +0 -28
  114. package/assets/vanilla/elements-markup/Lightbox.html +0 -33
  115. package/assets/vanilla/elements-markup/Link.html +0 -23
  116. package/assets/vanilla/elements-markup/NumberInput.html +0 -34
  117. package/assets/vanilla/elements-markup/ProgressBar.html +0 -47
  118. package/assets/vanilla/elements-markup/RadioList.html +0 -28
  119. package/assets/vanilla/elements-markup/Selector.html +0 -34
  120. package/assets/vanilla/elements-markup/SideNav.html +0 -32
  121. package/assets/vanilla/elements-markup/Skeleton.html +0 -18
  122. package/assets/vanilla/elements-markup/Slider.html +0 -31
  123. package/assets/vanilla/elements-markup/Stack.html +0 -33
  124. package/assets/vanilla/elements-markup/StatusDot.html +0 -19
  125. package/assets/vanilla/elements-markup/Switch.html +0 -28
  126. package/assets/vanilla/elements-markup/Tab.html +0 -18
  127. package/assets/vanilla/elements-markup/TabList.html +0 -31
  128. package/assets/vanilla/elements-markup/Table.html +0 -31
  129. package/assets/vanilla/elements-markup/Text.html +0 -24
  130. package/assets/vanilla/elements-markup/TextArea.html +0 -32
  131. package/assets/vanilla/elements-markup/TextInput.html +0 -92
  132. package/assets/vanilla/elements-markup/Theme.html +0 -16
  133. package/assets/vanilla/elements-markup/TimeInput.html +0 -29
  134. package/assets/vanilla/elements-markup/Toast.html +0 -22
  135. package/assets/vanilla/elements-markup/Tooltip.html +0 -30
  136. package/assets/vanilla/elements-markup/TopNav.html +0 -85
  137. package/assets/vanilla/elements-markup/Typeahead.html +0 -31
  138. package/assets/vanilla/elements-templates/dashboard.html +0 -167
  139. package/assets/vanilla/elements-templates/detail-page.html +0 -145
  140. package/assets/vanilla/elements-templates/form-two-column.html +0 -135
  141. package/assets/vanilla/elements-templates/kanban-board.html +0 -141
  142. package/assets/vanilla/elements-templates/login.html +0 -100
  143. package/assets/vanilla/elements-templates/product-detail.html +0 -128
  144. package/assets/vanilla/elements-templates/settings.html +0 -130
  145. package/assets/vanilla/elements-templates/shell-side-nav.html +0 -160
  146. package/assets/vanilla/elements-templates/table-filter.html +0 -154
  147. package/assets/vanilla/markup/Avatar.html +0 -24
  148. package/assets/vanilla/markup/Badge.html +0 -12
  149. package/assets/vanilla/markup/Banner.html +0 -49
  150. package/assets/vanilla/markup/Breadcrumbs.html +0 -38
  151. package/assets/vanilla/markup/Button.html +0 -37
  152. package/assets/vanilla/markup/Card.html +0 -16
  153. package/assets/vanilla/markup/CheckboxInput.html +0 -45
  154. package/assets/vanilla/markup/Collapsible.html +0 -9
  155. package/assets/vanilla/markup/DateInput.html +0 -42
  156. package/assets/vanilla/markup/Dialog.html +0 -45
  157. package/assets/vanilla/markup/Divider.html +0 -9
  158. package/assets/vanilla/markup/DropdownMenu.html +0 -30
  159. package/assets/vanilla/markup/EmptyState.html +0 -41
  160. package/assets/vanilla/markup/Heading.html +0 -9
  161. package/assets/vanilla/markup/HoverCard.html +0 -85
  162. package/assets/vanilla/markup/Layout.html +0 -35
  163. package/assets/vanilla/markup/Lightbox.html +0 -107
  164. package/assets/vanilla/markup/Link.html +0 -6
  165. package/assets/vanilla/markup/NumberInput.html +0 -55
  166. package/assets/vanilla/markup/ProgressBar.html +0 -101
  167. package/assets/vanilla/markup/RadioList.html +0 -90
  168. package/assets/vanilla/markup/Selector.html +0 -92
  169. package/assets/vanilla/markup/SideNav.html +0 -82
  170. package/assets/vanilla/markup/Skeleton.html +0 -26
  171. package/assets/vanilla/markup/Slider.html +0 -65
  172. package/assets/vanilla/markup/Stack.html +0 -13
  173. package/assets/vanilla/markup/StatusDot.html +0 -22
  174. package/assets/vanilla/markup/Switch.html +0 -47
  175. package/assets/vanilla/markup/TabList.html +0 -56
  176. package/assets/vanilla/markup/Table.html +0 -75
  177. package/assets/vanilla/markup/Text.html +0 -9
  178. package/assets/vanilla/markup/TextArea.html +0 -37
  179. package/assets/vanilla/markup/TextInput.html +0 -80
  180. package/assets/vanilla/markup/Theme.html +0 -48
  181. package/assets/vanilla/markup/TimeInput.html +0 -43
  182. package/assets/vanilla/markup/Toast.html +0 -42
  183. package/assets/vanilla/markup/Tooltip.html +0 -18
  184. package/assets/vanilla/markup/TopNav.html +0 -81
  185. package/assets/vanilla/markup/Typeahead.html +0 -60
  186. package/assets/vanilla/templates/dashboard.html +0 -462
  187. package/assets/vanilla/templates/detail-page.html +0 -536
  188. package/assets/vanilla/templates/form-two-column.html +0 -438
  189. package/assets/vanilla/templates/kanban-board.html +0 -443
  190. package/assets/vanilla/templates/login.html +0 -199
  191. package/assets/vanilla/templates/product-detail.html +0 -335
  192. package/assets/vanilla/templates/settings.html +0 -374
  193. package/assets/vanilla/templates/shell-side-nav.html +0 -440
  194. package/assets/vanilla/templates/table-filter.html +0 -514
  195. package/clients/cli/commands/vanilla-html.test.mjs +0 -245
  196. package/foundation/discovery/bundled-component-docs.d.mts +0 -39
  197. package/foundation/discovery/bundled-component-docs.mjs +0 -92
@@ -1,27 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @typedef {object} ComponentHtmlListEntry
5
- * @property {string} name
6
- * @property {string} file
7
- */
8
-
9
- /**
10
- * @typedef {object} ComponentHtmlListResponse
11
- * @property {'component.html.list'} type
12
- * @property {ComponentHtmlListEntry[]} data
13
- */
14
-
15
- /**
16
- * @typedef {object} ComponentHtmlResponse
17
- * @property {'component.html'} type
18
- * @property {{component: string, file: string, source: string}} data
19
- */
20
-
21
- /**
22
- * @typedef {object} ComponentHtmlOptions
23
- * @property {string} [cwd]
24
- * @property {boolean} [list]
25
- */
26
-
27
- export {};
@@ -1,12 +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
- * @param {string|undefined} name
6
- * @param {{cwd?: string, list?: boolean}} [options]
7
- * @returns {import('./web-components.type.mjs').ComponentWebComponentsResponse | import('./web-components.type.mjs').ComponentWebComponentsListResponse}
8
- */
9
- export function componentWebComponents(name: string | undefined, options?: {
10
- cwd?: string;
11
- list?: boolean;
12
- }): import("./web-components.type.mjs").ComponentWebComponentsResponse | import("./web-components.type.mjs").ComponentWebComponentsListResponse;
@@ -1,5 +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
- /** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
5
- export const doc: import("@astryxdesign/cli/authoring").FunctionDoc;
@@ -1,70 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
4
- export const doc = {
5
- type: 'function',
6
- kind: 'api',
7
- name: 'componentWebComponents',
8
- namespace: 'cli/api',
9
- displayName: 'componentWebComponents()',
10
- summary: 'List or read vanilla web-component markup.',
11
- description:
12
- 'Reads packages/vanilla/elements-markup in a source checkout and falls back to the bundled CLI copy after installation. List mode returns the available .html files; named mode returns one file verbatim.',
13
- importPath: '@astryxdesign/cli/api',
14
- signature:
15
- 'componentWebComponents(name?: string, options?: ComponentWebComponentsOptions): ComponentWebComponentsListResponse | ComponentWebComponentsResponse',
16
- keywords: ['component', 'web components', 'vanilla', 'markup'],
17
- params: [
18
- {
19
- name: 'name',
20
- type: 'string',
21
- description: 'Exact vanilla component name.',
22
- },
23
- {
24
- name: 'options.cwd',
25
- type: 'string',
26
- description:
27
- 'Directory to search upward for packages/vanilla before using the bundled CLI copy.',
28
- default: 'process.cwd()',
29
- },
30
- {
31
- name: 'options.list',
32
- type: 'boolean',
33
- description: 'List available markup files instead of reading one.',
34
- default: 'false',
35
- },
36
- ],
37
- returns: [
38
- {
39
- type: 'component.web-components.list',
40
- description: 'Sorted web-component markup files as {name, file}.',
41
- },
42
- {
43
- type: 'component.web-components',
44
- description:
45
- 'One web-component markup file as {component, file, source}.',
46
- },
47
- ],
48
- throws: [
49
- {
50
- code: 'ERR_FILE_NOT_FOUND',
51
- when: 'neither checkout nor bundled vanilla assets are available',
52
- },
53
- {
54
- code: 'ERR_INVALID_ARGUMENT',
55
- when: 'name is not a safe component identifier',
56
- },
57
- {code: 'ERR_UNKNOWN_COMPONENT', when: 'no matching markup file exists'},
58
- ],
59
- examples: [
60
- {
61
- label: 'Read Button markup',
62
- code: "componentWebComponents('Button', {cwd})",
63
- },
64
- {
65
- label: 'List markup files',
66
- code: 'componentWebComponents(undefined, {cwd, list: true})',
67
- },
68
- ],
69
- related: ['component', 'componentHtml', 'templateWebComponents'],
70
- };
@@ -1,32 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Vanilla web-component projection for the component command.
5
- * @position api/component/web-components — routed by component.mjs for the web-components framework
6
- */
7
-
8
- import {
9
- listVanillaComponentMarkup,
10
- readVanillaComponentMarkup,
11
- } from '../_adapter.mjs';
12
-
13
- /**
14
- * @param {string|undefined} name
15
- * @param {{cwd?: string, list?: boolean}} [options]
16
- * @returns {import('./web-components.type.mjs').ComponentWebComponentsResponse | import('./web-components.type.mjs').ComponentWebComponentsListResponse}
17
- */
18
- export function componentWebComponents(name, options = {}) {
19
- const {cwd = process.cwd(), list = false} = options;
20
- if (list) {
21
- return {
22
- type: 'component.web-components.list',
23
- data: listVanillaComponentMarkup(cwd, 'web-components'),
24
- };
25
- }
26
- const data = readVanillaComponentMarkup(
27
- /** @type {string} */ (name),
28
- cwd,
29
- 'web-components',
30
- );
31
- return {type: 'component.web-components', data};
32
- }
@@ -1,50 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, expect, it} from 'vitest';
4
- import * as fs from 'node:fs';
5
- import * as os from 'node:os';
6
- import * as path from 'node:path';
7
- import {componentWebComponents} from './web-components.mjs';
8
-
9
- const FIXTURE = path.resolve(
10
- import.meta.dirname,
11
- '../../../test/fixtures/vanilla-project',
12
- );
13
-
14
- describe('componentWebComponents()', () => {
15
- it('lists sorted web-component markup files', () => {
16
- expect(
17
- componentWebComponents(undefined, {cwd: FIXTURE, list: true}),
18
- ).toEqual({
19
- type: 'component.web-components.list',
20
- data: [{name: 'Button', file: 'Button.html'}],
21
- });
22
- });
23
-
24
- it('falls back to bundled web-component markup outside a checkout', () => {
25
- const outsideCheckout = fs.mkdtempSync(
26
- path.join(os.tmpdir(), 'astryx-cli-installed-web-components-'),
27
- );
28
- try {
29
- const result = componentWebComponents('Button', {cwd: outsideCheckout});
30
- expect(result.type).toBe('component.web-components');
31
- expect(result.data.source).toContain('<!-- attributes:');
32
- expect(result.data.source).toContain('<ax-button');
33
- } finally {
34
- fs.rmSync(outsideCheckout, {recursive: true, force: true});
35
- }
36
- });
37
-
38
- it('returns generated docs and ax-* markup verbatim', () => {
39
- const result = componentWebComponents('Button', {cwd: FIXTURE});
40
- expect(result.type).toBe('component.web-components');
41
- expect(result.data.source).toContain('<!-- attributes:');
42
- expect(result.data.source).toContain('<ax-button');
43
- });
44
-
45
- it('rejects traversal-shaped names', () => {
46
- expect(() => componentWebComponents('../Button', {cwd: FIXTURE})).toThrow(
47
- /Invalid vanilla component name/,
48
- );
49
- });
50
- });
@@ -1,23 +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 type ComponentWebComponentsListEntry = {
5
- name: string;
6
- file: string;
7
- };
8
- export type ComponentWebComponentsListResponse = {
9
- type: "component.web-components.list";
10
- data: ComponentWebComponentsListEntry[];
11
- };
12
- export type ComponentWebComponentsResponse = {
13
- type: "component.web-components";
14
- data: {
15
- component: string;
16
- file: string;
17
- source: string;
18
- };
19
- };
20
- export type ComponentWebComponentsOptions = {
21
- cwd?: string | undefined;
22
- list?: boolean | undefined;
23
- };
@@ -1,27 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @typedef {object} ComponentWebComponentsListEntry
5
- * @property {string} name
6
- * @property {string} file
7
- */
8
-
9
- /**
10
- * @typedef {object} ComponentWebComponentsListResponse
11
- * @property {'component.web-components.list'} type
12
- * @property {ComponentWebComponentsListEntry[]} data
13
- */
14
-
15
- /**
16
- * @typedef {object} ComponentWebComponentsResponse
17
- * @property {'component.web-components'} type
18
- * @property {{component: string, file: string, source: string}} data
19
- */
20
-
21
- /**
22
- * @typedef {object} ComponentWebComponentsOptions
23
- * @property {string} [cwd]
24
- * @property {boolean} [list]
25
- */
26
-
27
- export {};
@@ -1,38 +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
- * @param {string} cwd
6
- * @param {'html'|'web-components'} framework
7
- * @returns {{id: string, file: string}[]}
8
- */
9
- export function listVanillaTemplateMarkup(cwd: string, framework: "html" | "web-components"): {
10
- id: string;
11
- file: string;
12
- }[];
13
- /** @param {string} cwd @returns {{id: string, file: string}[]} */
14
- export function listVanillaTemplateHtml(cwd: string): {
15
- id: string;
16
- file: string;
17
- }[];
18
- /**
19
- * @param {string} id
20
- * @param {string} cwd
21
- * @param {'html'|'web-components'} framework
22
- * @returns {{template: string, file: string, source: string}}
23
- */
24
- export function readVanillaTemplateMarkup(id: string, cwd: string, framework: "html" | "web-components"): {
25
- template: string;
26
- file: string;
27
- source: string;
28
- };
29
- /**
30
- * @param {string} id
31
- * @param {string} cwd
32
- * @returns {{template: string, file: string, source: string}}
33
- */
34
- export function readVanillaTemplateHtml(id: string, cwd: string): {
35
- template: string;
36
- file: string;
37
- source: string;
38
- };
@@ -1,90 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Filesystem adapter for vanilla HTML and web-component templates.
5
- *
6
- * Environment access stays here so each template projection remains a pure
7
- * projection over one adapter result. Checkout assets are preferred; installed
8
- * packages fall back to the generated copy bundled under assets/vanilla.
9
- */
10
-
11
- import * as fs from 'node:fs';
12
- import * as path from 'node:path';
13
- import {AstryxError} from '../error.mjs';
14
- import {requireVanillaAssetsDir} from '../_vanilla-assets.mjs';
15
- import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
16
-
17
- /**
18
- * @param {string} cwd
19
- * @param {'html'|'web-components'} framework
20
- * @returns {{id: string, file: string}[]}
21
- */
22
- export function listVanillaTemplateMarkup(cwd, framework) {
23
- const assetDir =
24
- framework === 'web-components' ? 'elements-templates' : 'templates';
25
- const templatesDir = path.join(requireVanillaAssetsDir(cwd), assetDir);
26
- if (!fs.existsSync(templatesDir)) return [];
27
- return fs
28
- .readdirSync(templatesDir, {withFileTypes: true})
29
- .filter(entry => entry.isFile() && entry.name.endsWith('.html'))
30
- .map(entry => ({
31
- id: entry.name.slice(0, -'.html'.length),
32
- file: entry.name,
33
- }))
34
- .sort((a, b) => a.id.localeCompare(b.id));
35
- }
36
-
37
- /** @param {string} cwd @returns {{id: string, file: string}[]} */
38
- export function listVanillaTemplateHtml(cwd) {
39
- return listVanillaTemplateMarkup(cwd, 'html');
40
- }
41
-
42
- /**
43
- * @param {string} id
44
- * @param {string} cwd
45
- * @param {'html'|'web-components'} framework
46
- * @returns {{template: string, file: string, source: string}}
47
- */
48
- export function readVanillaTemplateMarkup(id, cwd, framework) {
49
- const entries = listVanillaTemplateMarkup(cwd, framework);
50
- if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id)) {
51
- throw new AstryxError(
52
- `Invalid vanilla template id "${id}"`,
53
- undefined,
54
- ERROR_CODES.ERR_INVALID_ARGUMENT,
55
- );
56
- }
57
- const match = entries.find(entry => entry.id === id);
58
- const label = framework === 'web-components' ? 'web-component' : 'HTML';
59
- if (!match) {
60
- throw new AstryxError(
61
- `Unknown vanilla ${label} template "${id}"`,
62
- entries.map(entry => ({
63
- name: entry.id,
64
- reason: `vanilla ${label} template`,
65
- })),
66
- ERROR_CODES.ERR_UNKNOWN_TEMPLATE,
67
- );
68
- }
69
- const assetDir =
70
- framework === 'web-components' ? 'elements-templates' : 'templates';
71
- const filePath = path.join(
72
- requireVanillaAssetsDir(cwd),
73
- assetDir,
74
- match.file,
75
- );
76
- return {
77
- template: id,
78
- file: match.file,
79
- source: fs.readFileSync(filePath, 'utf8'),
80
- };
81
- }
82
-
83
- /**
84
- * @param {string} id
85
- * @param {string} cwd
86
- * @returns {{template: string, file: string, source: string}}
87
- */
88
- export function readVanillaTemplateHtml(id, cwd) {
89
- return readVanillaTemplateMarkup(id, cwd, 'html');
90
- }
@@ -1,17 +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
- /** @param {string} ref @returns {string} */
5
- export function astryxVanillaCdnBase(ref: string): string;
6
- /**
7
- * @param {string|undefined} name
8
- * @param {{cwd?: string, list?: boolean, cdnRef?: string}} [options]
9
- * @returns {import('./html.type.mjs').TemplateHtmlResponse | import('./html.type.mjs').TemplateHtmlListResponse}
10
- */
11
- export function templateHtml(name: string | undefined, options?: {
12
- cwd?: string;
13
- list?: boolean;
14
- cdnRef?: string;
15
- }): import("./html.type.mjs").TemplateHtmlResponse | import("./html.type.mjs").TemplateHtmlListResponse;
16
- export const ASTRYX_VANILLA_CDN_REF: "3eb9597f53f557d20b34b3072d450d2bbdbfa1ac";
17
- export const ASTRYX_VANILLA_CDN_PLACEHOLDER: "__ASTRYX_VANILLA_CDN__";
@@ -1,5 +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
- /** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
5
- export const doc: import("@astryxdesign/cli/authoring").FunctionDoc;
@@ -1,72 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
4
- export const doc = {
5
- type: 'function',
6
- kind: 'api',
7
- name: 'templateHtml',
8
- namespace: 'cli/api',
9
- displayName: 'templateHtml()',
10
- summary: 'List or render vanilla standalone HTML templates.',
11
- description:
12
- 'Reads packages/vanilla/templates in a source checkout and falls back to the bundled CLI copy after installation. Named mode replaces __ASTRYX_VANILLA_CDN__ with a commit-pinned jsDelivr base URL.',
13
- importPath: '@astryxdesign/cli/api',
14
- signature:
15
- 'templateHtml(name?: string, options?: TemplateHtmlOptions): TemplateHtmlListResponse | TemplateHtmlResponse',
16
- keywords: ['template', 'html', 'vanilla', 'jsdelivr', 'cdn'],
17
- params: [
18
- {name: 'name', type: 'string', description: 'Exact vanilla template id.'},
19
- {
20
- name: 'options.cwd',
21
- type: 'string',
22
- description:
23
- 'Directory to search upward for packages/vanilla before using the bundled CLI copy.',
24
- default: 'process.cwd()',
25
- },
26
- {
27
- name: 'options.list',
28
- type: 'boolean',
29
- description: 'List available HTML template files instead of reading one.',
30
- default: 'false',
31
- },
32
- {
33
- name: 'options.cdnRef',
34
- type: 'string',
35
- description: 'Git ref inserted into the jsDelivr base URL.',
36
- default: 'ASTRYX_VANILLA_CDN_REF',
37
- },
38
- ],
39
- returns: [
40
- {
41
- type: 'template.html.list',
42
- description: 'Sorted vanilla HTML templates as {id, file}.',
43
- },
44
- {
45
- type: 'template.html',
46
- description:
47
- 'One substituted page as {template, file, cdnRef, cdnBase, source}.',
48
- },
49
- ],
50
- throws: [
51
- {
52
- code: 'ERR_FILE_NOT_FOUND',
53
- when: 'neither checkout nor bundled vanilla assets are available',
54
- },
55
- {
56
- code: 'ERR_INVALID_ARGUMENT',
57
- when: 'the template id or CDN ref is unsafe',
58
- },
59
- {
60
- code: 'ERR_UNKNOWN_TEMPLATE',
61
- when: 'no matching HTML template file exists',
62
- },
63
- ],
64
- examples: [
65
- {label: 'Render dashboard', code: "templateHtml('dashboard', {cwd})"},
66
- {
67
- label: 'Use another commit',
68
- code: "templateHtml('dashboard', {cwd, cdnRef: sha})",
69
- },
70
- ],
71
- related: ['template', 'componentHtml'],
72
- };
@@ -1,61 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Vanilla standalone HTML projection for the template command.
5
- * @position api/template/html — routed by template.mjs for framework=html or the --html alias
6
- */
7
-
8
- import {AstryxError} from '../../error.mjs';
9
- import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
10
- import {
11
- listVanillaTemplateHtml,
12
- readVanillaTemplateHtml,
13
- } from '../_adapter.mjs';
14
-
15
- export const ASTRYX_VANILLA_CDN_REF =
16
- '3eb9597f53f557d20b34b3072d450d2bbdbfa1ac';
17
- export const ASTRYX_VANILLA_CDN_PLACEHOLDER = '__ASTRYX_VANILLA_CDN__';
18
-
19
- /** @param {string} ref @returns {string} */
20
- export function astryxVanillaCdnBase(ref) {
21
- if (
22
- !/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(ref) ||
23
- ref.includes('..') ||
24
- ref.includes('//')
25
- ) {
26
- throw new AstryxError(
27
- `Invalid vanilla CDN ref "${ref}"`,
28
- undefined,
29
- ERROR_CODES.ERR_INVALID_ARGUMENT,
30
- );
31
- }
32
- return `https://cdn.jsdelivr.net/gh/facebook/astryx@${ref}/packages/vanilla/dist`;
33
- }
34
-
35
- /**
36
- * @param {string|undefined} name
37
- * @param {{cwd?: string, list?: boolean, cdnRef?: string}} [options]
38
- * @returns {import('./html.type.mjs').TemplateHtmlResponse | import('./html.type.mjs').TemplateHtmlListResponse}
39
- */
40
- export function templateHtml(name, options = {}) {
41
- const {
42
- cwd = process.cwd(),
43
- list = false,
44
- cdnRef = ASTRYX_VANILLA_CDN_REF,
45
- } = options;
46
- if (list) {
47
- return {type: 'template.html.list', data: listVanillaTemplateHtml(cwd)};
48
- }
49
- const raw = readVanillaTemplateHtml(/** @type {string} */ (name), cwd);
50
- const cdnBase = astryxVanillaCdnBase(cdnRef);
51
- return {
52
- type: 'template.html',
53
- data: {
54
- template: raw.template,
55
- file: raw.file,
56
- cdnRef,
57
- cdnBase,
58
- source: raw.source.replaceAll(ASTRYX_VANILLA_CDN_PLACEHOLDER, cdnBase),
59
- },
60
- };
61
- }
@@ -1,71 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, expect, it} from 'vitest';
4
- import * as fs from 'node:fs';
5
- import * as os from 'node:os';
6
- import * as path from 'node:path';
7
- import {
8
- ASTRYX_VANILLA_CDN_PLACEHOLDER,
9
- ASTRYX_VANILLA_CDN_REF,
10
- templateHtml,
11
- } from './html.mjs';
12
-
13
- const FIXTURE = path.resolve(
14
- import.meta.dirname,
15
- '../../../test/fixtures/vanilla-project',
16
- );
17
-
18
- describe('templateHtml()', () => {
19
- it('lists sorted vanilla HTML templates', () => {
20
- expect(templateHtml(undefined, {cwd: FIXTURE, list: true})).toEqual({
21
- type: 'template.html.list',
22
- data: [{id: 'dashboard', file: 'dashboard.html'}],
23
- });
24
- });
25
-
26
- it('falls back to the bundled templates outside a checkout', () => {
27
- const outsideCheckout = fs.mkdtempSync(
28
- path.join(os.tmpdir(), 'astryx-cli-installed-'),
29
- );
30
- try {
31
- const result = templateHtml('dashboard', {cwd: outsideCheckout});
32
- expect(result.type).toBe('template.html');
33
- expect(result.data.source).toContain('<!doctype html>');
34
- } finally {
35
- fs.rmSync(outsideCheckout, {recursive: true, force: true});
36
- }
37
- });
38
-
39
- it('substitutes every placeholder with the pinned default CDN base', () => {
40
- const result = templateHtml('dashboard', {cwd: FIXTURE});
41
- expect(result.type).toBe('template.html');
42
- expect(result.data.cdnRef).toBe(ASTRYX_VANILLA_CDN_REF);
43
- expect(result.data.source).not.toContain(ASTRYX_VANILLA_CDN_PLACEHOLDER);
44
- expect(
45
- result.data.source.match(new RegExp(result.data.cdnBase, 'g')),
46
- ).toHaveLength(2);
47
- });
48
-
49
- it('supports an explicit CDN ref', () => {
50
- const result = templateHtml('dashboard', {cwd: FIXTURE, cdnRef: 'abc1234'});
51
- expect(result.data.cdnBase).toContain('@abc1234/packages/vanilla/dist');
52
- expect(result.data.source).toContain(result.data.cdnBase);
53
- });
54
-
55
- it('rejects unsafe CDN refs', () => {
56
- expect(() =>
57
- templateHtml('dashboard', {cwd: FIXTURE, cdnRef: '../main'}),
58
- ).toThrow(/Invalid vanilla CDN ref/);
59
- });
60
-
61
- it('reports a missing page as an unknown template', () => {
62
- const error = (() => {
63
- try {
64
- templateHtml('missing', {cwd: FIXTURE});
65
- } catch (caught) {
66
- return caught;
67
- }
68
- })();
69
- expect(error.code).toBe('ERR_UNKNOWN_TEMPLATE');
70
- });
71
- });
@@ -1,26 +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 type TemplateHtmlListEntry = {
5
- id: string;
6
- file: string;
7
- };
8
- export type TemplateHtmlListResponse = {
9
- type: "template.html.list";
10
- data: TemplateHtmlListEntry[];
11
- };
12
- export type TemplateHtmlResponse = {
13
- type: "template.html";
14
- data: {
15
- template: string;
16
- file: string;
17
- cdnRef: string;
18
- cdnBase: string;
19
- source: string;
20
- };
21
- };
22
- export type TemplateHtmlOptions = {
23
- cwd?: string | undefined;
24
- list?: boolean | undefined;
25
- cdnRef?: string | undefined;
26
- };
@@ -1,28 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @typedef {object} TemplateHtmlListEntry
5
- * @property {string} id
6
- * @property {string} file
7
- */
8
-
9
- /**
10
- * @typedef {object} TemplateHtmlListResponse
11
- * @property {'template.html.list'} type
12
- * @property {TemplateHtmlListEntry[]} data
13
- */
14
-
15
- /**
16
- * @typedef {object} TemplateHtmlResponse
17
- * @property {'template.html'} type
18
- * @property {{template: string, file: string, cdnRef: string, cdnBase: string, source: string}} data
19
- */
20
-
21
- /**
22
- * @typedef {object} TemplateHtmlOptions
23
- * @property {string} [cwd]
24
- * @property {boolean} [list]
25
- * @property {string} [cdnRef]
26
- */
27
-
28
- export {};