@astryxdesign/cli 0.6.6-canary.6ea1fb7 → 0.6.6-canary.7c8ddf2
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 +83 -83
- package/api/build/_adapter.d.mts +15 -0
- package/api/build/_adapter.mjs +22 -0
- package/api/build/build.doc.mjs +1 -1
- package/api/build/build.type.d.mts +4 -0
- package/api/build/build.type.mjs +1 -0
- package/api/build/help/help.mjs +1 -1
- package/api/build/kit/kit.mjs +12 -1
- package/api/component/component-replacement.test.mjs +12 -0
- package/api/component/component.doc.mjs +5 -2
- package/api/docs/_adapter.mjs +48 -1
- package/api/docs/compiled-topics.test.mjs +1 -1
- package/api/docs/detail/section/section.d.mts +44 -0
- package/api/docs/detail/section/section.mjs +164 -13
- package/api/docs/detail/section/section.test.mjs +4 -4
- package/api/docs/docOverlays.test.mjs +28 -17
- package/api/docs/docs.doc.mjs +3 -3
- package/api/docs/docs.mjs +11 -16
- package/api/docs/docs.test.mjs +9 -10
- package/api/docs/integration-tree.test.mjs +26 -26
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/docs/namespace-section.test.mjs +260 -0
- package/api/docs/token-tables.test.mjs +93 -0
- package/api/doctor/doctor.d.mts +6 -0
- package/api/doctor/doctor.mjs +149 -40
- package/api/doctor/doctor.test.mjs +104 -0
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/gap-report/gap-report.doc.mjs +2 -1
- package/api/init/run/run.mjs +1 -0
- package/api/integration/validate-integration.mjs +20 -4
- package/api/integration/validate-integration.test.mjs +73 -0
- package/api/layout/check/check.d.mts +1 -0
- package/api/layout/check/check.mjs +1 -0
- package/api/layout/expand/expand.d.mts +1 -0
- package/api/layout/expand/expand.mjs +1 -0
- package/api/layout/grammar/grammar.d.mts +1 -0
- package/api/layout/grammar/grammar.mjs +1 -0
- package/api/layout/layoutCheck.doc.mjs +1 -1
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/layout/layoutGrammar.doc.mjs +1 -1
- package/api/search/search.d.mts +44 -0
- package/api/search/search.domain-priority.test.mjs +261 -0
- package/api/search/search.mjs +191 -29
- package/api/swizzle/swizzle.doc.mjs +5 -2
- package/api/template/copy/copy.mjs +12 -0
- package/api/template/template.doc.mjs +1 -1
- package/api/template/template.type.d.mts +3 -0
- package/api/template/template.type.mjs +3 -0
- package/api/theme/build/build.d.mts +70 -0
- package/api/theme/build/build.mjs +205 -41
- package/api/theme/build/font-warning.d.mts +11 -0
- package/api/theme/build/font-warning.mjs +28 -3
- package/assets/docs/author-a-theme.doc.mjs +16 -11
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/principles.doc.dense.mjs +3 -3
- package/assets/docs/principles.doc.mjs +4 -4
- package/assets/docs/principles.doc.zh.mjs +3 -3
- package/assets/docs/styling-overview.doc.mjs +6 -6
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/docs/tree/component-migration.doc.mjs +107 -0
- package/assets/docs/tree/css-and-stylex.doc.mjs +150 -0
- package/assets/docs/tree/font-setup.doc.mjs +122 -0
- package/assets/docs/tree/headers-and-footers.doc.mjs +0 -1
- package/assets/docs/tree/i18n-library-integration.doc.mjs +167 -0
- package/assets/docs/tree/i18n-quick-start.doc.mjs +101 -0
- package/assets/docs/{internationalization.doc.mjs → tree/i18n-rtl-and-testing.doc.mjs} +17 -223
- package/assets/docs/tree/internationalization.doc.mjs +29 -0
- package/assets/docs/tree/layout.doc.mjs +23 -0
- package/assets/docs/{migration.doc.mjs → tree/migration-setup.doc.mjs} +24 -129
- package/assets/docs/tree/migration-verification.doc.mjs +67 -0
- package/assets/docs/tree/migration.doc.mjs +28 -0
- package/assets/docs/tree/non-css-processing.doc.mjs +112 -0
- package/assets/docs/tree/other-libraries.doc.mjs +218 -0
- package/assets/docs/tree/responsive.doc.mjs +0 -4
- package/assets/docs/tree/scaffold.doc.mjs +0 -5
- package/assets/docs/tree/side-panels.doc.mjs +0 -1
- package/assets/docs/tree/structure.doc.mjs +0 -4
- package/assets/docs/tree/styling-advanced.doc.mjs +159 -0
- package/assets/docs/tree/styling-basics.doc.mjs +181 -0
- package/assets/docs/tree/styling-libraries.doc.mjs +30 -0
- package/assets/docs/tree/styling.doc.mjs +29 -0
- package/assets/docs/tree/tailwind.doc.mjs +65 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +128 -0
- package/assets/docs/tree/tokens-border.doc.mjs +46 -0
- package/assets/docs/tree/tokens-color.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-color.doc.mjs +438 -0
- package/assets/docs/tree/tokens-color.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-data.doc.mjs +323 -0
- package/assets/docs/tree/tokens-duration.doc.mjs +78 -0
- package/assets/docs/tree/tokens-ease.doc.mjs +46 -0
- package/assets/docs/tree/tokens-focus.doc.mjs +57 -0
- package/assets/docs/tree/tokens-font-weight.doc.mjs +58 -0
- package/assets/docs/tree/tokens-radius.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-radius.doc.mjs +70 -0
- package/assets/docs/tree/tokens-radius.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-shadow.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-shadow.doc.mjs +74 -0
- package/assets/docs/tree/tokens-shadow.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-size.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-size.doc.mjs +54 -0
- package/assets/docs/tree/tokens-size.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-spacing.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-spacing.doc.mjs +102 -0
- package/assets/docs/tree/tokens-spacing.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-syntax.doc.mjs +98 -0
- package/assets/docs/tree/tokens-text-size.doc.mjs +90 -0
- package/assets/docs/tree/tokens-type-scale.doc.mjs +210 -0
- package/assets/docs/tree/tokens-typography.doc.mjs +54 -0
- package/assets/docs/tree/tokens-usage.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-usage.doc.mjs +36 -0
- package/assets/docs/tree/tokens-usage.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens.doc.mjs +28 -0
- package/assets/docs/tree/type-scale.doc.mjs +147 -0
- package/assets/docs/tree/typography-best-practices.doc.mjs +55 -0
- package/assets/docs/tree/typography.doc.mjs +29 -0
- package/assets/docs/use-a-theme.doc.mjs +6 -3
- package/assets/templates/pages/incident-console/page.tsx +1 -1
- package/assets/theme.template.ts +4 -3
- package/clients/cli/commands/blog.mjs +3 -3
- package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
- package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
- package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
- package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
- package/clients/cli/commands/build-theme.mjs +68 -18
- package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
- package/clients/cli/commands/build.mjs +1 -0
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/component-replacement.text.test.mjs +45 -0
- package/clients/cli/commands/docs.doc.mjs +2 -1
- package/clients/cli/commands/docs.test.mjs +15 -12
- package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +50 -1
- package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
- package/clients/cli/commands/layout-check.doc.mjs +1 -0
- package/clients/cli/commands/layout-expand.doc.mjs +1 -0
- package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
- package/clients/cli/commands/layout.doc.mjs +1 -0
- package/clients/cli/commands/layout.mjs +6 -11
- package/clients/cli/commands/search.test.mjs +6 -2
- package/clients/cli/commands/swizzle.routing.test.mjs +2 -1
- package/clients/cli/commands/template.mjs +4 -3
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +9 -6
- package/clients/cli/commands/theme-build.doc.mjs +3 -1
- package/clients/cli/commands/upgrade.config-ordering.test.mjs +2 -1
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +13 -3
- package/clients/cli/lib/component-format.test.mjs +1 -1
- package/clients/cli/lib/define-command.mjs +4 -0
- package/foundation/agent-docs/agent-docs.mjs +18 -2
- package/foundation/agent-docs/agent-docs.test.mjs +18 -0
- package/foundation/config/project.test.mjs +1 -1
- package/foundation/discovery/docs-discovery.test.mjs +1 -1
- package/foundation/discovery/template-needs.d.mts +31 -0
- package/foundation/discovery/template-needs.mjs +156 -0
- package/foundation/discovery/template-needs.test.mjs +203 -0
- package/foundation/doc-compiler/bundle.mjs +52 -1
- package/foundation/doc-compiler/split-topic-keywords.test.mjs +73 -0
- package/foundation/doc-compiler/tree.d.mts +10 -0
- package/foundation/doc-compiler/tree.mjs +22 -0
- package/foundation/doc-compiler/tree.test.mjs +3 -2
- package/foundation/env/package-manager.d.mts +31 -8
- package/foundation/env/package-manager.mjs +120 -13
- package/foundation/env/package-manager.test.mjs +174 -1
- package/foundation/integrations/validate-contributions.d.mts +16 -0
- package/foundation/integrations/validate-contributions.mjs +56 -8
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +9 -9
- package/assets/docs/styling-libraries.doc.mjs +0 -469
- package/assets/docs/styling.doc.mjs +0 -412
- package/assets/docs/tokens.doc.dense.mjs +0 -15
- package/assets/docs/tokens.doc.mjs +0 -1491
- package/assets/docs/tokens.doc.zh.mjs +0 -15
- package/assets/docs/typography.doc.mjs +0 -286
|
@@ -26,6 +26,7 @@ import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
|
26
26
|
import {getCliInvocation} from '../env/package-manager.mjs';
|
|
27
27
|
import {discoverComponents} from '../discovery/component-discovery.mjs';
|
|
28
28
|
import {Project} from '../config/project.mjs';
|
|
29
|
+
import {cliRootNamespaceNames} from '../doc-compiler/tree.mjs';
|
|
29
30
|
import {humanLog} from '../response/json.mjs';
|
|
30
31
|
import {ERROR_CODES} from '../response/error-codes.mjs';
|
|
31
32
|
import {
|
|
@@ -335,6 +336,9 @@ export function detectStylingSystem(targetDir) {
|
|
|
335
336
|
// Key off a StyleX *compiler* plugin — the runtime alone won't render.
|
|
336
337
|
const stylexCompilers = [
|
|
337
338
|
'@stylexjs/babel-plugin',
|
|
339
|
+
'@stylexjs/rollup-plugin',
|
|
340
|
+
'@stylexjs/webpack-plugin',
|
|
341
|
+
'@stylexjs/nextjs-plugin',
|
|
338
342
|
'vite-plugin-stylex',
|
|
339
343
|
'unplugin-stylex',
|
|
340
344
|
'@stylexswc/unplugin',
|
|
@@ -452,7 +456,7 @@ export function generateCompressedIndex(
|
|
|
452
456
|
} else if (stylingSystem === 'tailwind') {
|
|
453
457
|
lines.push('- Style with component props first, then Tailwind utilities backed by tokens. No raw hex/px.');
|
|
454
458
|
} else {
|
|
455
|
-
lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes.");
|
|
459
|
+
lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes directly. Some templates use StyleX and need a compiler plugin; see `astryx docs styling-overview`.");
|
|
456
460
|
}
|
|
457
461
|
lines.push('- Palettes and custom colors go through the theme, never :root overrides. See `astryx docs theme`.');
|
|
458
462
|
// Self-check — post-generation pass. Validated via vibe tests (internal/vibe-tests/
|
|
@@ -484,6 +488,7 @@ export function generateCompressedIndex(
|
|
|
484
488
|
.map(f => f.match(/^([\w-]+)\.doc\.mjs$/))
|
|
485
489
|
.filter(/** @returns {m is RegExpMatchArray} */ (m) => m != null)
|
|
486
490
|
.map(m => m[1])
|
|
491
|
+
.concat(cliRootNamespaceNames())
|
|
487
492
|
.sort()
|
|
488
493
|
: []);
|
|
489
494
|
if (resolvedTopics.length > 0) {
|
|
@@ -552,7 +557,18 @@ export async function renderAgentDocsBlock(
|
|
|
552
557
|
`Cannot render agent docs because integration ${packageLabel} has invalid agentDocs: ${invalidAgentDocs.__agentDocsError}`,
|
|
553
558
|
);
|
|
554
559
|
}
|
|
555
|
-
const
|
|
560
|
+
const catalog = await project.docs();
|
|
561
|
+
// Every name `astryx docs <name>` opens: the flat topics, and each root
|
|
562
|
+
// namespace of the docs tree (a topic split into guides keeps its name).
|
|
563
|
+
const topics = [
|
|
564
|
+
...catalog.names(),
|
|
565
|
+
...cliRootNamespaceNames(),
|
|
566
|
+
...catalog.treeInputs.flatMap(inputs =>
|
|
567
|
+
inputs.namespaces
|
|
568
|
+
.filter(input => !input.doc?.placement?.parent)
|
|
569
|
+
.map(input => input.doc.name),
|
|
570
|
+
),
|
|
571
|
+
];
|
|
556
572
|
const agentDocs = project.loadedIntegrations.flatMap(integration => {
|
|
557
573
|
const append = integration.agentDocs?.append ?? [];
|
|
558
574
|
if (append.length === 0) return [];
|
|
@@ -89,6 +89,9 @@ describe('generateCompressedIndex', () => {
|
|
|
89
89
|
expect(result).not.toMatch(/xstyle prop/);
|
|
90
90
|
// Must warn that no compiler is present.
|
|
91
91
|
expect(result).toMatch(/No StyleX\/Tailwind compiler/);
|
|
92
|
+
// Must acknowledge that some templates use StyleX and point at the doc.
|
|
93
|
+
expect(result).toMatch(/templates.*StyleX/i);
|
|
94
|
+
expect(result).toMatch(/styling-overview/);
|
|
92
95
|
});
|
|
93
96
|
|
|
94
97
|
it('recommends xstyle when StyleX is configured', () => {
|
|
@@ -371,6 +374,21 @@ describe('detectStylingSystem', () => {
|
|
|
371
374
|
expect(detectStylingSystem(tmpDir)).toBe('stylex');
|
|
372
375
|
});
|
|
373
376
|
|
|
377
|
+
it('detects the official Rollup/Vite plugin', () => {
|
|
378
|
+
writePkg({'@stylexjs/rollup-plugin': '0.10.0'});
|
|
379
|
+
expect(detectStylingSystem(tmpDir)).toBe('stylex');
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('detects the official Webpack plugin', () => {
|
|
383
|
+
writePkg({'@stylexjs/webpack-plugin': '0.10.0'});
|
|
384
|
+
expect(detectStylingSystem(tmpDir)).toBe('stylex');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('detects the official Next.js plugin', () => {
|
|
388
|
+
writePkg({'@stylexjs/nextjs-plugin': '0.10.0'});
|
|
389
|
+
expect(detectStylingSystem(tmpDir)).toBe('stylex');
|
|
390
|
+
});
|
|
391
|
+
|
|
374
392
|
it('detects tailwind when tailwindcss is present', () => {
|
|
375
393
|
writePkg({tailwindcss: '4.0.0'});
|
|
376
394
|
expect(detectStylingSystem(tmpDir)).toBe('tailwind');
|
|
@@ -432,7 +432,7 @@ describe('Project discovery', () => {
|
|
|
432
432
|
package: '@acme/widgets',
|
|
433
433
|
});
|
|
434
434
|
// The CLI's own topics are still there.
|
|
435
|
-
expect(catalog.resolve('
|
|
435
|
+
expect(catalog.resolve('color').package).toBe('@astryxdesign/cli');
|
|
436
436
|
expect(await project.issues()).toEqual([]);
|
|
437
437
|
});
|
|
438
438
|
|
|
@@ -65,7 +65,7 @@ describe('discoverBuiltinTopics', () => {
|
|
|
65
65
|
it("finds the CLI's own topics and not their localization overlays", () => {
|
|
66
66
|
const topics = discoverBuiltinTopics();
|
|
67
67
|
expect(Object.keys(topics).length).toBeGreaterThan(0);
|
|
68
|
-
expect(topics.
|
|
68
|
+
expect(topics.color).toMatch(/assets[/\\]docs[/\\]color\.doc\.mjs$/);
|
|
69
69
|
for (const name of Object.keys(topics)) {
|
|
70
70
|
expect(name).not.toMatch(/\.(zh|dense)$/);
|
|
71
71
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extract bare (non-relative) package names from ES import statements.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} source Template source code
|
|
8
|
+
* @returns {Set<string>} Unique package names (scoped packages normalized to
|
|
9
|
+
* `@scope/name`, unscoped to the first path segment).
|
|
10
|
+
*/
|
|
11
|
+
export function extractImportedPackages(source: string): Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Analyze what a template source needs that the target project lacks.
|
|
14
|
+
*
|
|
15
|
+
* Returns a `notes` array of human-readable setup notes, a structured
|
|
16
|
+
* `missingPackages` list, and an `installCommand` string ready to print.
|
|
17
|
+
* Each note is one actionable line.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} source Template source code
|
|
20
|
+
* @param {string} cwd Target project directory
|
|
21
|
+
* @returns {{
|
|
22
|
+
* notes: string[],
|
|
23
|
+
* missingPackages: string[],
|
|
24
|
+
* installCommand: string | null,
|
|
25
|
+
* }}
|
|
26
|
+
*/
|
|
27
|
+
export function analyzeTemplateNeeds(source: string, cwd: string): {
|
|
28
|
+
notes: string[];
|
|
29
|
+
missingPackages: string[];
|
|
30
|
+
installCommand: string | null;
|
|
31
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Analyze what a scaffolded template needs that the target project lacks.
|
|
5
|
+
*
|
|
6
|
+
* Derives needs from the template's own source — its bare import specifiers —
|
|
7
|
+
* rather than from a hand-maintained list. Every import that is not an Astryx
|
|
8
|
+
* package, react/react-dom, or @stylexjs/stylex is external; the source is the
|
|
9
|
+
* only authority on what a template uses.
|
|
10
|
+
*
|
|
11
|
+
* Shared between `api/template/copy` (the scaffold receipt) and
|
|
12
|
+
* `api/build/kit` (the start recommendation).
|
|
13
|
+
*
|
|
14
|
+
* @position packages/cli/foundation/discovery — template discovery helpers;
|
|
15
|
+
* consumed by the template and build API leaves.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as fs from 'node:fs';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
import module from 'node:module';
|
|
21
|
+
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
22
|
+
import {detectStylingSystem} from '../agent-docs/agent-docs.mjs';
|
|
23
|
+
|
|
24
|
+
// ── Known packages that a template may import without the user installing them.
|
|
25
|
+
// react and react-dom are the framework; @astryxdesign/* is the design system
|
|
26
|
+
// the CLI already told the user to install; @stylexjs/stylex is a peer of Core.
|
|
27
|
+
const FRAMEWORK_PREFIXES = ['react', 'react-dom'];
|
|
28
|
+
const DESIGN_SYSTEM_SCOPE = '@astryxdesign/';
|
|
29
|
+
const STYLEX_RUNTIME = '@stylexjs/stylex';
|
|
30
|
+
|
|
31
|
+
// Node builtins: anything with a `node:` prefix or in builtinModules.
|
|
32
|
+
const NODE_BUILTINS = new Set(module.builtinModules);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extract bare (non-relative) package names from ES import statements.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} source Template source code
|
|
38
|
+
* @returns {Set<string>} Unique package names (scoped packages normalized to
|
|
39
|
+
* `@scope/name`, unscoped to the first path segment).
|
|
40
|
+
*/
|
|
41
|
+
export function extractImportedPackages(source) {
|
|
42
|
+
// Matches `import … from '<specifier>'`, `import '<specifier>'`, and
|
|
43
|
+
// dynamic `import('<specifier>')`. Only bare specifiers (not starting with
|
|
44
|
+
// `.` or `/`).
|
|
45
|
+
const re = /(?:from\s+|import\s*\(?)['"]((?:@[^/'"]+\/)?[^./'"@][^'"]*)['"]/g;
|
|
46
|
+
/** @type {Set<string>} */
|
|
47
|
+
const pkgs = new Set();
|
|
48
|
+
let m;
|
|
49
|
+
while ((m = re.exec(source)) !== null) {
|
|
50
|
+
const spec = m[1];
|
|
51
|
+
// Skip Node builtins: `node:fs`, `fs`, `fs/promises`, etc.
|
|
52
|
+
if (spec.startsWith('node:')) continue;
|
|
53
|
+
const name = spec.startsWith('@')
|
|
54
|
+
? spec.split('/').slice(0, 2).join('/')
|
|
55
|
+
: spec.split('/')[0];
|
|
56
|
+
if (NODE_BUILTINS.has(name)) continue;
|
|
57
|
+
pkgs.add(name);
|
|
58
|
+
}
|
|
59
|
+
return pkgs;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Detect which package manager the project uses, from its lockfile.
|
|
64
|
+
* @param {string} cwd Project root
|
|
65
|
+
* @returns {'pnpm add' | 'yarn add' | 'bun add' | 'npm install'}
|
|
66
|
+
*/
|
|
67
|
+
function detectInstallCommand(cwd) {
|
|
68
|
+
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm add';
|
|
69
|
+
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn add';
|
|
70
|
+
if (fs.existsSync(path.join(cwd, 'bun.lockb'))) return 'bun add';
|
|
71
|
+
return 'npm install';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Read the CLI package's own devDependencies for authoritative version ranges
|
|
76
|
+
* of external packages the templates use.
|
|
77
|
+
* @returns {Record<string, string>}
|
|
78
|
+
*/
|
|
79
|
+
function cliPackageRanges() {
|
|
80
|
+
try {
|
|
81
|
+
const pkgPath = path.join(CLI_ROOT, 'package.json');
|
|
82
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
83
|
+
return {...pkg.devDependencies};
|
|
84
|
+
} catch {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Analyze what a template source needs that the target project lacks.
|
|
91
|
+
*
|
|
92
|
+
* Returns a `notes` array of human-readable setup notes, a structured
|
|
93
|
+
* `missingPackages` list, and an `installCommand` string ready to print.
|
|
94
|
+
* Each note is one actionable line.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} source Template source code
|
|
97
|
+
* @param {string} cwd Target project directory
|
|
98
|
+
* @returns {{
|
|
99
|
+
* notes: string[],
|
|
100
|
+
* missingPackages: string[],
|
|
101
|
+
* installCommand: string | null,
|
|
102
|
+
* }}
|
|
103
|
+
*/
|
|
104
|
+
export function analyzeTemplateNeeds(source, cwd) {
|
|
105
|
+
const imported = extractImportedPackages(source);
|
|
106
|
+
|
|
107
|
+
// ── External packages (not framework / design system / stylex runtime) ──
|
|
108
|
+
const external = [...imported].filter(
|
|
109
|
+
name =>
|
|
110
|
+
!FRAMEWORK_PREFIXES.includes(name) &&
|
|
111
|
+
!name.startsWith(DESIGN_SYSTEM_SCOPE) &&
|
|
112
|
+
name !== STYLEX_RUNTIME,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Read the project's installed packages.
|
|
116
|
+
/** @type {Record<string, string>} */
|
|
117
|
+
let projectDeps = {};
|
|
118
|
+
try {
|
|
119
|
+
const pkg = JSON.parse(
|
|
120
|
+
fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'),
|
|
121
|
+
);
|
|
122
|
+
projectDeps = {...pkg.dependencies, ...pkg.devDependencies};
|
|
123
|
+
} catch {
|
|
124
|
+
// No package.json or unreadable — treat everything as missing.
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const missing = external.filter(p => !(p in projectDeps));
|
|
128
|
+
|
|
129
|
+
// Build the install command with version ranges from the CLI workspace.
|
|
130
|
+
let installCommand = null;
|
|
131
|
+
if (missing.length > 0) {
|
|
132
|
+
const pm = detectInstallCommand(cwd);
|
|
133
|
+
const ranges = cliPackageRanges();
|
|
134
|
+
const specs = missing.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
|
|
135
|
+
installCommand = `${pm} ${specs.join(' ')}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ── StyleX compiler ────────────────────────────────────────────────────
|
|
139
|
+
const usesStylex = imported.has(STYLEX_RUNTIME);
|
|
140
|
+
const stylexCompilerNeeded =
|
|
141
|
+
usesStylex && detectStylingSystem(cwd) !== 'stylex';
|
|
142
|
+
|
|
143
|
+
// ── Notes ──────────────────────────────────────────────────────────────
|
|
144
|
+
/** @type {string[]} */
|
|
145
|
+
const notes = [];
|
|
146
|
+
if (missing.length > 0) {
|
|
147
|
+
notes.push(`Install missing dependencies: ${installCommand}`);
|
|
148
|
+
}
|
|
149
|
+
if (stylexCompilerNeeded) {
|
|
150
|
+
notes.push(
|
|
151
|
+
'This template uses StyleX. Your project needs a StyleX compiler plugin \u2014 see `astryx docs styling-overview` for setup steps.',
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {notes, missingPackages: missing, installCommand};
|
|
156
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for template-needs analysis: external package detection, StyleX
|
|
5
|
+
* compiler warning, and install command generation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {describe, it, expect, beforeEach, afterEach} 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 {
|
|
13
|
+
extractImportedPackages,
|
|
14
|
+
analyzeTemplateNeeds,
|
|
15
|
+
} from './template-needs.mjs';
|
|
16
|
+
|
|
17
|
+
// ── extractImportedPackages ─────────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
describe('extractImportedPackages', () => {
|
|
20
|
+
it('extracts bare package names from static imports', () => {
|
|
21
|
+
const source = `
|
|
22
|
+
import {Button} from '@astryxdesign/core';
|
|
23
|
+
import {ArrowIcon} from '@heroicons/react/24/outline';
|
|
24
|
+
import * as stylex from '@stylexjs/stylex';
|
|
25
|
+
import {useState} from 'react';
|
|
26
|
+
import recharts from 'recharts';
|
|
27
|
+
`;
|
|
28
|
+
const pkgs = extractImportedPackages(source);
|
|
29
|
+
expect(pkgs).toEqual(
|
|
30
|
+
new Set([
|
|
31
|
+
'@astryxdesign/core',
|
|
32
|
+
'@heroicons/react',
|
|
33
|
+
'@stylexjs/stylex',
|
|
34
|
+
'react',
|
|
35
|
+
'recharts',
|
|
36
|
+
]),
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('ignores relative and absolute imports', () => {
|
|
41
|
+
const source = `
|
|
42
|
+
import {foo} from './bar';
|
|
43
|
+
import {baz} from '../qux';
|
|
44
|
+
import {thing} from '/absolute/path';
|
|
45
|
+
`;
|
|
46
|
+
expect(extractImportedPackages(source).size).toBe(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('ignores Node builtins with the node: prefix', () => {
|
|
50
|
+
const source = `
|
|
51
|
+
import * as fs from 'node:fs';
|
|
52
|
+
import * as path from 'node:path';
|
|
53
|
+
import {createRequire} from 'node:module';
|
|
54
|
+
`;
|
|
55
|
+
expect(extractImportedPackages(source).size).toBe(0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('ignores bare Node builtins and their subpaths', () => {
|
|
59
|
+
const source = `
|
|
60
|
+
import * as fs from 'fs';
|
|
61
|
+
import {join} from 'path';
|
|
62
|
+
import {createReadStream} from 'fs/promises';
|
|
63
|
+
`;
|
|
64
|
+
expect(extractImportedPackages(source).size).toBe(0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('handles type imports', () => {
|
|
68
|
+
const source = `import type {Props} from 'some-package';`;
|
|
69
|
+
expect(extractImportedPackages(source)).toEqual(new Set(['some-package']));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('deduplicates multiple imports from the same package', () => {
|
|
73
|
+
const source = `
|
|
74
|
+
import {A} from '@heroicons/react/24/outline';
|
|
75
|
+
import {B} from '@heroicons/react/24/solid';
|
|
76
|
+
`;
|
|
77
|
+
expect(extractImportedPackages(source)).toEqual(
|
|
78
|
+
new Set(['@heroicons/react']),
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('maps subpath imports to the package root', () => {
|
|
83
|
+
const source = `
|
|
84
|
+
import debounce from 'lodash/debounce';
|
|
85
|
+
import {Chart} from 'recharts/es6';
|
|
86
|
+
`;
|
|
87
|
+
const pkgs = extractImportedPackages(source);
|
|
88
|
+
expect(pkgs).toEqual(new Set(['lodash', 'recharts']));
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ── analyzeTemplateNeeds ────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
describe('analyzeTemplateNeeds', () => {
|
|
95
|
+
let dir;
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-needs-'));
|
|
98
|
+
});
|
|
99
|
+
afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
100
|
+
|
|
101
|
+
it('reports missing external packages with an install command', () => {
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
path.join(dir, 'package.json'),
|
|
104
|
+
JSON.stringify({dependencies: {'react': '^19.0.0', '@astryxdesign/core': '^0.6.0'}}),
|
|
105
|
+
);
|
|
106
|
+
const source = `
|
|
107
|
+
import {Button} from '@astryxdesign/core';
|
|
108
|
+
import {ArrowIcon} from '@heroicons/react/24/outline';
|
|
109
|
+
import {useState} from 'react';
|
|
110
|
+
`;
|
|
111
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
112
|
+
expect(result.missingPackages).toEqual(['@heroicons/react']);
|
|
113
|
+
expect(result.installCommand).toMatch(/npm install @heroicons\/react/);
|
|
114
|
+
expect(result.notes.length).toBeGreaterThanOrEqual(1);
|
|
115
|
+
expect(result.notes[0]).toMatch(/Install missing dependencies/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('reports nothing when all packages are installed', () => {
|
|
119
|
+
fs.writeFileSync(
|
|
120
|
+
path.join(dir, 'package.json'),
|
|
121
|
+
JSON.stringify({
|
|
122
|
+
dependencies: {
|
|
123
|
+
'react': '^19.0.0',
|
|
124
|
+
'@astryxdesign/core': '^0.6.0',
|
|
125
|
+
'@heroicons/react': '^2.2.0',
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
const source = `
|
|
130
|
+
import {Button} from '@astryxdesign/core';
|
|
131
|
+
import {ArrowIcon} from '@heroicons/react/24/outline';
|
|
132
|
+
`;
|
|
133
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
134
|
+
expect(result.missingPackages).toEqual([]);
|
|
135
|
+
expect(result.installCommand).toBeNull();
|
|
136
|
+
expect(result.notes).toEqual([]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('warns about StyleX compiler when template uses it and project lacks one', () => {
|
|
140
|
+
fs.writeFileSync(
|
|
141
|
+
path.join(dir, 'package.json'),
|
|
142
|
+
JSON.stringify({dependencies: {'@stylexjs/stylex': '^0.10.0'}}),
|
|
143
|
+
);
|
|
144
|
+
const source = `import * as stylex from '@stylexjs/stylex';`;
|
|
145
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
146
|
+
expect(result.notes).toEqual(
|
|
147
|
+
expect.arrayContaining([
|
|
148
|
+
expect.stringContaining('StyleX'),
|
|
149
|
+
expect.stringContaining('styling-overview'),
|
|
150
|
+
]),
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('does NOT warn about StyleX when the project has a compiler', () => {
|
|
155
|
+
fs.writeFileSync(
|
|
156
|
+
path.join(dir, 'package.json'),
|
|
157
|
+
JSON.stringify({
|
|
158
|
+
devDependencies: {
|
|
159
|
+
'@stylexjs/stylex': '^0.10.0',
|
|
160
|
+
'@stylexjs/rollup-plugin': '^0.10.0',
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
const source = `import * as stylex from '@stylexjs/stylex';`;
|
|
165
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
166
|
+
const stylexNotes = result.notes.filter(n => n.includes('StyleX'));
|
|
167
|
+
expect(stylexNotes).toEqual([]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('detects pnpm from lockfile', () => {
|
|
171
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
172
|
+
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
|
|
173
|
+
const source = `import {Chart} from 'recharts';`;
|
|
174
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
175
|
+
expect(result.installCommand).toMatch(/^pnpm add /);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('detects yarn from lockfile', () => {
|
|
179
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
180
|
+
fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
|
|
181
|
+
const source = `import {Chart} from 'recharts';`;
|
|
182
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
183
|
+
expect(result.installCommand).toMatch(/^yarn add /);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('excludes @stylexjs/stylex from missing packages (it is a Core peer)', () => {
|
|
187
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
188
|
+
const source = `import * as stylex from '@stylexjs/stylex';`;
|
|
189
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
190
|
+
expect(result.missingPackages).not.toContain('@stylexjs/stylex');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('handles a template with no external imports', () => {
|
|
194
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
195
|
+
const source = `
|
|
196
|
+
import {useState} from 'react';
|
|
197
|
+
import {Button} from '@astryxdesign/core';
|
|
198
|
+
`;
|
|
199
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
200
|
+
expect(result.notes).toEqual([]);
|
|
201
|
+
expect(result.missingPackages).toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -118,10 +118,61 @@ export async function compileDocs(project, {lang = null} = {}) {
|
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
// Guides placed in a namespace, lowered, so a token reference to the
|
|
122
|
+
// namespace (a flat topic split into guides, such as `tokens`) reads them
|
|
123
|
+
// in placement order as one topic, as the docs API does.
|
|
124
|
+
/** @type {Map<string, Array<{order: number, node: CompiledReferenceNode}>>} */
|
|
125
|
+
const placedGuides = new Map();
|
|
126
|
+
for (const input of inputs) {
|
|
127
|
+
if (
|
|
128
|
+
input.root !== 'tree' ||
|
|
129
|
+
(await treeDocType(input.file)) !== 'generic'
|
|
130
|
+
) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const topic = await loadTopicInput(
|
|
134
|
+
{
|
|
135
|
+
name: input.name,
|
|
136
|
+
package: input.owner,
|
|
137
|
+
path: input.file,
|
|
138
|
+
extensions: [],
|
|
139
|
+
tree: true,
|
|
140
|
+
},
|
|
141
|
+
lang,
|
|
142
|
+
);
|
|
143
|
+
if ('error' in topic.base || 'overlayError' in topic.base) continue;
|
|
144
|
+
const parent = /^namespace:(.+)$/u.exec(
|
|
145
|
+
topic.base.doc?.placement?.parent ?? '',
|
|
146
|
+
)?.[1];
|
|
147
|
+
if (!parent) continue;
|
|
148
|
+
try {
|
|
149
|
+
const node = lowerReferenceTopic(topic);
|
|
150
|
+
const list = placedGuides.get(parent.toLowerCase()) ?? [];
|
|
151
|
+
list.push({order: topic.base.doc.placement.order ?? 0, node});
|
|
152
|
+
placedGuides.set(parent.toLowerCase(), list);
|
|
153
|
+
} catch {
|
|
154
|
+
// Reported where the guide itself is compiled below.
|
|
155
|
+
}
|
|
156
|
+
}
|
|
121
157
|
/** @param {string} name */
|
|
122
158
|
const lowerTarget = async name => {
|
|
123
159
|
const target = catalog.resolve(name);
|
|
124
|
-
|
|
160
|
+
if (target) return topics.get(target.name.toLowerCase()) ?? null;
|
|
161
|
+
const guides = placedGuides.get(name.toLowerCase());
|
|
162
|
+
if (!guides) return null;
|
|
163
|
+
const ordered = [...guides].sort((a, b) => a.order - b.order);
|
|
164
|
+
/** @type {Record<string, string>} */
|
|
165
|
+
const sourceTitles = {};
|
|
166
|
+
for (const {node} of ordered) {
|
|
167
|
+
for (const [key, title] of Object.entries(node.sourceTitles)) {
|
|
168
|
+
sourceTitles[key] ??= title;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return /** @type {any} */ ({
|
|
172
|
+
id: name,
|
|
173
|
+
doc: {sections: ordered.flatMap(({node}) => node.doc.sections)},
|
|
174
|
+
sourceTitles,
|
|
175
|
+
});
|
|
125
176
|
};
|
|
126
177
|
|
|
127
178
|
/** @type {Array<CompiledDocNode | CompiledReferenceNode>} */
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A topic split into a namespace of guides indexes each term once, a
|
|
5
|
+
* policy of the docs split itself (no spec clause states it). Below the CLI's own
|
|
6
|
+
* root namespaces (every one but `cli`, its command and API reference), a
|
|
7
|
+
* guide's search keywords are its own: none repeats a keyword its namespace,
|
|
8
|
+
* a sibling, or a guide of another split topic declares. A term several
|
|
9
|
+
* guides share belongs to their namespace, or to none.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import {fileURLToPath} from 'node:url';
|
|
15
|
+
import {describe, expect, it} from 'vitest';
|
|
16
|
+
|
|
17
|
+
const TREE_DIR = path.resolve(
|
|
18
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
19
|
+
'../../assets/docs/tree',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/** @returns {Promise<Map<string, any>>} every CLI tree doc, by name */
|
|
23
|
+
async function treeDocs() {
|
|
24
|
+
/** @type {Map<string, any>} */
|
|
25
|
+
const docs = new Map();
|
|
26
|
+
for (const file of fs.readdirSync(TREE_DIR)) {
|
|
27
|
+
if (!/^[\w-]+\.doc\.mjs$/.test(file)) continue;
|
|
28
|
+
const {docs: doc} = await import(path.join(TREE_DIR, file));
|
|
29
|
+
docs.set(doc.name, doc);
|
|
30
|
+
}
|
|
31
|
+
return docs;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @param {any} doc @returns {string | null} */
|
|
35
|
+
const parentOf = doc =>
|
|
36
|
+
/^namespace:(.+)$/.exec(doc.placement?.parent ?? '')?.[1] ?? null;
|
|
37
|
+
|
|
38
|
+
describe('the keywords of a split topic', () => {
|
|
39
|
+
it("are each declared once, and a guide's are its own", async () => {
|
|
40
|
+
const docs = await treeDocs();
|
|
41
|
+
/** @param {string} name */
|
|
42
|
+
const rootOf = name => {
|
|
43
|
+
let doc = docs.get(name);
|
|
44
|
+
while (doc && parentOf(doc)) doc = docs.get(parentOf(doc));
|
|
45
|
+
return doc?.name;
|
|
46
|
+
};
|
|
47
|
+
const roots = [...docs.values()]
|
|
48
|
+
.filter(doc => doc.type === 'namespace' && !parentOf(doc) && doc.name !== 'cli')
|
|
49
|
+
.map(doc => doc.name);
|
|
50
|
+
expect(roots).toContain('layout');
|
|
51
|
+
|
|
52
|
+
/** @type {Map<string, any[]>} */
|
|
53
|
+
const owners = new Map();
|
|
54
|
+
for (const doc of docs.values()) {
|
|
55
|
+
if (!roots.includes(rootOf(doc.name))) continue;
|
|
56
|
+
const own = new Set((doc.keywords ?? []).map(k => String(k).toLowerCase()));
|
|
57
|
+
for (const keyword of own) {
|
|
58
|
+
owners.set(keyword, [...(owners.get(keyword) ?? []), doc]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const repeats = [...owners]
|
|
62
|
+
.filter(([, holders]) => holders.length > 1 && holders.some(d => d.type !== 'namespace'))
|
|
63
|
+
.map(([keyword, holders]) => `${keyword}: ${holders.map(d => d.name).join(', ')}`);
|
|
64
|
+
expect(repeats).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('are not repeated inside one doc', async () => {
|
|
68
|
+
for (const doc of (await treeDocs()).values()) {
|
|
69
|
+
const keywords = (doc.keywords ?? []).map(k => String(k).toLowerCase());
|
|
70
|
+
expect(new Set(keywords).size, doc.name).toBe(keywords.length);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -26,6 +26,16 @@ export function buildDocsTree({ namespaces, docs, topics }: {
|
|
|
26
26
|
* @returns {string[]}
|
|
27
27
|
*/
|
|
28
28
|
export function treeDocFiles(dir?: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* The names of the CLI's own root namespaces (spec:AST-046 FR7): each is read
|
|
31
|
+
* with `astryx docs <name>`, as a flat topic is, though no topic file has its
|
|
32
|
+
* name. Read from the namespace files' text, without loading them, so a
|
|
33
|
+
* synchronous caller (the agent docs block) lists them beside the flat topics.
|
|
34
|
+
* A topic split into a namespace keeps its name in every such list.
|
|
35
|
+
* @param {string} [dir]
|
|
36
|
+
* @returns {string[]}
|
|
37
|
+
*/
|
|
38
|
+
export function cliRootNamespaceNames(dir?: string): string[];
|
|
29
39
|
/**
|
|
30
40
|
* The CLI's own tree inputs: the namespace docs and guides under
|
|
31
41
|
* assets/docs/tree, and, unless left out, every typed self-doc with its
|
|
@@ -744,6 +744,28 @@ export function treeDocFiles(dir = TREE_DOCS_DIR) {
|
|
|
744
744
|
.map(file => path.join(dir, file));
|
|
745
745
|
}
|
|
746
746
|
|
|
747
|
+
/**
|
|
748
|
+
* The names of the CLI's own root namespaces (spec:AST-046 FR7): each is read
|
|
749
|
+
* with `astryx docs <name>`, as a flat topic is, though no topic file has its
|
|
750
|
+
* name. Read from the namespace files' text, without loading them, so a
|
|
751
|
+
* synchronous caller (the agent docs block) lists them beside the flat topics.
|
|
752
|
+
* A topic split into a namespace keeps its name in every such list.
|
|
753
|
+
* @param {string} [dir]
|
|
754
|
+
* @returns {string[]}
|
|
755
|
+
*/
|
|
756
|
+
export function cliRootNamespaceNames(dir = TREE_DOCS_DIR) {
|
|
757
|
+
/** @type {string[]} */
|
|
758
|
+
const names = [];
|
|
759
|
+
for (const file of treeDocFiles(dir)) {
|
|
760
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
761
|
+
if (!/["']?type["']?\s*:\s*["']namespace["']/u.test(text)) continue;
|
|
762
|
+
if (/["']?placement["']?\s*:/u.test(text)) continue;
|
|
763
|
+
const name = /["']?name["']?\s*:\s*["']([\w-]+)["']/u.exec(text)?.[1];
|
|
764
|
+
if (name) names.push(name);
|
|
765
|
+
}
|
|
766
|
+
return names.sort(byText);
|
|
767
|
+
}
|
|
768
|
+
|
|
747
769
|
/**
|
|
748
770
|
* The CLI's own tree inputs: the namespace docs and guides under
|
|
749
771
|
* assets/docs/tree, and, unless left out, every typed self-doc with its
|