@reqvire-org/ads 0.3.43 → 0.3.45

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 (165) hide show
  1. package/README.md +32 -10
  2. package/dist/assets.mjs +49 -3
  3. package/dist/brand-assets.mjs +174 -7
  4. package/dist/check.mjs +4 -2
  5. package/dist/cli.mjs +21 -9
  6. package/dist/config.mjs +60 -3
  7. package/dist/create.mjs +48 -0
  8. package/dist/image-size.mjs +28 -0
  9. package/dist/index.mjs +1 -0
  10. package/dist/init.mjs +2 -2
  11. package/dist/mcp/server.mjs +3 -1
  12. package/dist/mcp/skills.mjs +1 -1
  13. package/dist/preview-bun.mjs +4 -2
  14. package/dist/scenario-groups.mjs +2 -2
  15. package/dist/scenario-registry.mjs +3 -3
  16. package/dist/scenarios-compiler.mjs +1 -1
  17. package/dist/scenarios.mjs +4 -2
  18. package/dist/showcase/client.bundle.js +22 -22
  19. package/dist/showcase/draft-navigation.js +1 -1
  20. package/dist/showcase/index.html +1 -0
  21. package/dist/skills/ads-break-ui/SKILL.md +1 -1
  22. package/dist/skills/ads-designer/README.md +2 -2
  23. package/dist/skills/ads-designer/SKILL.md +44 -54
  24. package/dist/skills/ads-designer/references/branding.md +104 -0
  25. package/dist/skills/ads-designer/references/cli.md +5 -4
  26. package/dist/skills/ads-import/SKILL.md +1 -1
  27. package/dist/skills/ads-import/references/branding.md +13 -5
  28. package/dist/skills/ads-import/references/cli.md +5 -4
  29. package/dist/skills/ads-motion/SKILL.md +1 -1
  30. package/dist/skills/ads-port/SKILL.md +1 -1
  31. package/dist/skills/ads-port/references/cli.md +5 -4
  32. package/dist/{bootstrap-ds-preact → starters/preact}/ds.config.json +2 -1
  33. package/dist/{bootstrap-ds → starters/react}/ADS.md +2 -2
  34. package/dist/{bootstrap-ds → starters/react}/README.md +18 -22
  35. package/dist/starters/react/design-system/assets/brand/README.md +36 -0
  36. package/dist/starters/react/design-system/assets/brand/app-icon.svg +4 -0
  37. package/dist/starters/react/design-system/assets/brand/logo.dark.svg +6 -0
  38. package/dist/starters/react/design-system/assets/brand/logo.svg +6 -0
  39. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +7 -0
  40. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +4 -0
  41. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +7 -0
  42. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +4 -0
  43. package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.fixture.ts +1 -0
  44. package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.scenario.tsx +12 -0
  45. package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +41 -0
  46. package/dist/starters/react/design-system/components/Content/Logo/README.md +10 -0
  47. package/dist/{bootstrap-ds → starters/react}/design-system/index.ts +1 -0
  48. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +115 -0
  49. package/dist/{bootstrap-ds → starters/react}/design-system/review/index.ts +1 -0
  50. package/dist/{skills/ads-designer/assets/bootstrap-ds → starters/react}/ds.config.json +2 -1
  51. package/dist/{bootstrap-ds → starters/react}/tsconfig.build.json +2 -1
  52. package/dist/task-cache.mjs +1 -1
  53. package/dist/token-fixtures.mjs +1 -1
  54. package/dist/units.mjs +6 -6
  55. package/dist/validation.mjs +1 -1
  56. package/docs/ADS.md +9 -6
  57. package/docs/ARCHITECTURE.md +1 -1
  58. package/docs/CHANGELOG.md +59 -12
  59. package/docs/GUIDE.md +61 -18
  60. package/package.json +3 -5
  61. package/dist/bootstrap-ds/design-system/assets/brand/README.md +0 -29
  62. package/dist/bootstrap-ds/ds.config.json +0 -19
  63. package/dist/skills/ads-designer/assets/bootstrap-ds/ADS.md +0 -258
  64. package/dist/skills/ads-designer/assets/bootstrap-ds/README.md +0 -120
  65. package/dist/skills/ads-designer/assets/bootstrap-ds/biome.css.json +0 -21
  66. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/assets/brand/README.md +0 -29
  67. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/assets/fonts/.gitkeep +0 -0
  68. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Actions/Button/Button.ads.fixture.ts +0 -1
  69. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Actions/Button/Button.ads.scenario.tsx +0 -13
  70. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Actions/Button/Button.tsx +0 -49
  71. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Actions/Button/README.md +0 -12
  72. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Forms/TextField/README.md +0 -14
  73. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Forms/TextField/TextField.ads.fixture.ts +0 -6
  74. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Forms/TextField/TextField.ads.scenario.tsx +0 -13
  75. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Forms/TextField/TextField.tsx +0 -57
  76. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/composition/Search/SearchPage/README.md +0 -4
  77. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/composition/Search/SearchPage/SearchPage.ads.fixture.ts +0 -7
  78. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/composition/Search/SearchPage/SearchPage.ads.scenario.tsx +0 -16
  79. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/controllers/.gitkeep +0 -0
  80. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/index.ts +0 -7
  81. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/patterns/Search/SearchBar/README.md +0 -12
  82. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/patterns/Search/SearchBar/SearchBar.ads.fixture.ts +0 -1
  83. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/patterns/Search/SearchBar/SearchBar.ads.scenario.tsx +0 -11
  84. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/patterns/Search/SearchBar/SearchBar.tsx +0 -41
  85. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/demo-frame/DemoFrame.tsx +0 -29
  86. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/index.ts +0 -3
  87. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
  88. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/token-preview/TokenPreview.tsx +0 -119
  89. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/showcase/mcp/index.html +0 -1
  90. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/showcase/mcp/main.tsx +0 -8
  91. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/styles.css +0 -5
  92. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/Color.ads.fixture.ts +0 -18
  93. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/Color.ads.scenario.tsx +0 -4
  94. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/SpaceTypeMotion.ads.fixture.ts +0 -36
  95. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/SpaceTypeMotion.ads.scenario.tsx +0 -4
  96. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/base.css +0 -30
  97. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/colors.css +0 -29
  98. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/elevation.css +0 -15
  99. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/spacing.css +0 -15
  100. package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/typography.css +0 -13
  101. package/dist/skills/ads-designer/assets/bootstrap-ds/gitignore.template +0 -8
  102. package/dist/skills/ads-designer/assets/bootstrap-ds/package-lock.json +0 -4660
  103. package/dist/skills/ads-designer/assets/bootstrap-ds/package.json +0 -42
  104. package/dist/skills/ads-designer/assets/bootstrap-ds/scripts/build-mcp-previews.mjs +0 -3
  105. package/dist/skills/ads-designer/assets/bootstrap-ds/src/vite-env.d.ts +0 -7
  106. package/dist/skills/ads-designer/assets/bootstrap-ds/tsconfig.build.json +0 -19
  107. package/dist/skills/ads-designer/assets/bootstrap-ds/tsconfig.json +0 -35
  108. package/dist/skills/ads-designer/assets/bootstrap-ds/vite.config.ts +0 -23
  109. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
  110. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
  111. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/design-system/review/token-preview/TokenPreview.tsx +0 -119
  112. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/design-system/showcase/mcp/main.tsx +0 -6
  113. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/ds.config.json +0 -19
  114. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/package.json +0 -38
  115. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/src/vite-env.d.ts +0 -7
  116. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/tsconfig.json +0 -36
  117. package/dist/skills/ads-designer/assets/bootstrap-ds-preact/vite.config.ts +0 -23
  118. /package/dist/{bootstrap-ds-preact → starters/preact}/design-system/review/demo-frame/DemoFrame.tsx +0 -0
  119. /package/dist/{bootstrap-ds-preact → starters/preact}/design-system/review/screen-frame/ScreenFrame.tsx +0 -0
  120. /package/dist/{bootstrap-ds-preact → starters/preact}/design-system/review/token-preview/TokenPreview.tsx +0 -0
  121. /package/dist/{bootstrap-ds-preact → starters/preact}/design-system/showcase/mcp/main.tsx +0 -0
  122. /package/dist/{bootstrap-ds-preact → starters/preact}/package.json +0 -0
  123. /package/dist/{bootstrap-ds-preact → starters/preact}/src/vite-env.d.ts +0 -0
  124. /package/dist/{bootstrap-ds-preact → starters/preact}/tsconfig.json +0 -0
  125. /package/dist/{bootstrap-ds-preact → starters/preact}/vite.config.ts +0 -0
  126. /package/dist/{bootstrap-ds → starters/react}/biome.css.json +0 -0
  127. /package/dist/{bootstrap-ds → starters/react}/design-system/assets/fonts/.gitkeep +0 -0
  128. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Actions/Button/Button.ads.fixture.ts +0 -0
  129. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Actions/Button/Button.ads.scenario.tsx +0 -0
  130. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Actions/Button/Button.tsx +0 -0
  131. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Actions/Button/README.md +0 -0
  132. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Forms/TextField/README.md +0 -0
  133. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Forms/TextField/TextField.ads.fixture.ts +0 -0
  134. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Forms/TextField/TextField.ads.scenario.tsx +0 -0
  135. /package/dist/{bootstrap-ds → starters/react}/design-system/components/Forms/TextField/TextField.tsx +0 -0
  136. /package/dist/{bootstrap-ds → starters/react}/design-system/composition/Search/SearchPage/README.md +0 -0
  137. /package/dist/{bootstrap-ds → starters/react}/design-system/composition/Search/SearchPage/SearchPage.ads.fixture.ts +0 -0
  138. /package/dist/{bootstrap-ds → starters/react}/design-system/composition/Search/SearchPage/SearchPage.ads.scenario.tsx +0 -0
  139. /package/dist/{bootstrap-ds → starters/react}/design-system/controllers/.gitkeep +0 -0
  140. /package/dist/{bootstrap-ds → starters/react}/design-system/patterns/Search/SearchBar/README.md +0 -0
  141. /package/dist/{bootstrap-ds → starters/react}/design-system/patterns/Search/SearchBar/SearchBar.ads.fixture.ts +0 -0
  142. /package/dist/{bootstrap-ds → starters/react}/design-system/patterns/Search/SearchBar/SearchBar.ads.scenario.tsx +0 -0
  143. /package/dist/{bootstrap-ds → starters/react}/design-system/patterns/Search/SearchBar/SearchBar.tsx +0 -0
  144. /package/dist/{bootstrap-ds → starters/react}/design-system/review/demo-frame/DemoFrame.tsx +0 -0
  145. /package/dist/{bootstrap-ds → starters/react}/design-system/review/screen-frame/ScreenFrame.tsx +0 -0
  146. /package/dist/{bootstrap-ds → starters/react}/design-system/review/token-preview/TokenPreview.tsx +0 -0
  147. /package/dist/{bootstrap-ds → starters/react}/design-system/showcase/mcp/index.html +0 -0
  148. /package/dist/{bootstrap-ds → starters/react}/design-system/showcase/mcp/main.tsx +0 -0
  149. /package/dist/{bootstrap-ds → starters/react}/design-system/styles.css +0 -0
  150. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/Color.ads.fixture.ts +0 -0
  151. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/Color.ads.scenario.tsx +0 -0
  152. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/SpaceTypeMotion.ads.fixture.ts +0 -0
  153. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/SpaceTypeMotion.ads.scenario.tsx +0 -0
  154. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/base.css +0 -0
  155. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/colors.css +0 -0
  156. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/elevation.css +0 -0
  157. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/spacing.css +0 -0
  158. /package/dist/{bootstrap-ds → starters/react}/design-system/tokens/typography.css +0 -0
  159. /package/dist/{bootstrap-ds → starters/react}/gitignore.template +0 -0
  160. /package/dist/{bootstrap-ds → starters/react}/package-lock.json +0 -0
  161. /package/dist/{bootstrap-ds → starters/react}/package.json +0 -0
  162. /package/dist/{bootstrap-ds → starters/react}/scripts/build-mcp-previews.mjs +0 -0
  163. /package/dist/{bootstrap-ds → starters/react}/src/vite-env.d.ts +0 -0
  164. /package/dist/{bootstrap-ds → starters/react}/tsconfig.json +0 -0
  165. /package/dist/{bootstrap-ds → starters/react}/vite.config.ts +0 -0
package/README.md CHANGED
@@ -64,7 +64,24 @@ and composition previews can use dependency drafts through normal `@ds` imports;
64
64
  accepting a dependency automatically switches dependent drafts to accepted source.
65
65
  Drafts survive restart and Git clone, but cannot enter production imports.
66
66
 
67
- ## Set up your project
67
+ ## Create a new design system
68
+
69
+ `create` copies the starter shipped in this ADS version into a new folder and sets
70
+ it up, so the project always matches the tool that checks it:
71
+
72
+ ```sh
73
+ npx @reqvire-org/ads create my-design-system --framework react # or preact
74
+ cd my-design-system
75
+ npm install
76
+ npm run build
77
+ npm run dev:showcase
78
+ ```
79
+
80
+ With Bun: `bunx @reqvire-org/ads create my-design-system --framework preact
81
+ --package-manager bun`, then `bun install` and `bun --bun run build`. `--name` sets
82
+ the package name (default: the folder name).
83
+
84
+ ## Set up an existing project
68
85
 
69
86
  Run **inside your project**, where `package.json` lives. Install Bun 1.4.1+ for
70
87
  ADS tooling and previews. Your application can continue using Node/npm or Bun.
@@ -76,8 +93,7 @@ npm run build
76
93
  ```
77
94
 
78
95
  Use `--framework preact` for native Preact. Init saves the choice in
79
- `ds.config.json`; later runs can use plain `ads init`. A copied starter that
80
- already declares its framework can also omit the flag.
96
+ `ds.config.json`; later runs can use plain `ads init`.
81
97
 
82
98
  For a Bun project, Node is unnecessary:
83
99
 
@@ -233,7 +249,7 @@ happens automatically; no separate project showcase rebuild is needed.
233
249
 
234
250
  For an existing app, `init` adds the showcase launch script; it does not install
235
251
  a preview compiler. Integrate the [starter compiler and mount adapter](docs/GUIDE.md#showcase)
236
- with your build. The copied starter already includes that setup.
252
+ with your build. Projects from `ads create` already include that setup.
237
253
 
238
254
  There are no required showcase page files. Add a colocated scenario and fixture
239
255
  for tokens and each public UI owner; larger entries live under `composition/`.
@@ -249,7 +265,11 @@ Change values in `design-system/tokens/`, keeping the
249
265
  [shared token names](docs/ADS.md#shared-token-contract), such as `--accent` and
250
266
  `--font-sans`.
251
267
 
252
- Keep original artwork and its usage/credits in `design-system/assets/brand/`.
268
+ Keep original artwork, with its use, credits and license in a README, in
269
+ `design-system/assets/brand/`; `ads check` warns about undescribed, unlicensed,
270
+ unpreviewed or unused artwork. Name dark-theme variants `<name>.dark.svg`.
271
+ Committed native and export icons (`assets.targets`: SVG, PNG, ICO, ICNS) and UI
272
+ icon sets (`assets.glyphs`) are generated by `ads assets` and checked for freshness.
253
273
  To generate web icons, add this to `ds.config.json`:
254
274
 
255
275
  ```json
@@ -336,11 +356,13 @@ The [dummy project](tests/fixtures/guard-project/README.md) tests the generic gu
336
356
 
337
357
  There are two different starting points in this checkout:
338
358
 
339
- - [bootstrap-ds/](bootstrap-ds/README.md) is the React application starter, and
340
- [bootstrap-ds-preact/](bootstrap-ds-preact/) the files that make it Preact:
341
- token defaults in two groups, build setup, one example component in each of two groups,
342
- a pattern and a composition, development-only review renderers, and a project preview compiler adapter. It is bundled with `ads-designer` so an agent can copy it when starting
343
- from zero. `ads init` uses its empty foundation files when a project has no ADS.
359
+ - [starters/react/](starters/react/README.md) is the React application starter, and
360
+ [starters/preact/](starters/preact/) the files that replace it for Preact:
361
+ token defaults in two groups, a brand preview with placeholder artwork, build
362
+ setup, example components, a pattern and a composition, development-only review
363
+ renderers, and a project preview compiler adapter. They ship in the npm package;
364
+ `ads create` copies them into a new project, and `ads init` uses their foundation
365
+ files when a project has no ADS.
344
366
  - [design-system/](design-system/README.md) is this repository's working example,
345
367
  with real components, patterns, and scenarios inspected through the built-in showcase. It demonstrates the architecture
346
368
  and helps us develop the tooling. Its UI source is excluded from the npm package
package/dist/assets.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { existsSync, lstatSync, readdirSync } from "node:fs";
1
+ import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
2
2
  import { spawnSync } from "node:child_process";
3
3
  import path from "node:path";
4
- import { isInside } from "./config.mjs";
5
- import { brandFiles, brandSourceDiagnostic } from "./brand-assets.mjs";
4
+ import { brandFormats, isInside } from "./config.mjs";
5
+ import { brandFiles, brandSourceDiagnostic, staleBrandOutputs } from "./brand-assets.mjs";
6
6
 
7
7
  function assetFiles(directory, prefix = "") {
8
8
  const stat = lstatSync(directory, { throwIfNoEntry: false });
@@ -17,10 +17,56 @@ function assetFiles(directory, prefix = "") {
17
17
  return files.sort();
18
18
  }
19
19
 
20
+ const sourceExtensions = /\.(?:[cm]?[jt]sx?|css|html|svg)$/;
21
+ const previewFile = /(?:\.ads)?\.(?:scenario\.tsx?|fixture\.ts)$/;
22
+ /** Text of the project's own source files, for finding which brand artwork is referenced. */
23
+ function sourceTexts(directories, skipped) {
24
+ const texts = [];
25
+ const visit = directory => {
26
+ const stat = lstatSync(directory, { throwIfNoEntry: false });
27
+ if (!stat || stat.isSymbolicLink() || !stat.isDirectory() || skipped.some(skip => directory === skip || isInside(skip, directory))) return;
28
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
29
+ const file = path.join(directory, entry.name);
30
+ if (entry.isDirectory()) { if (!["node_modules", ".git"].includes(entry.name)) visit(file); }
31
+ else if (entry.isFile() && sourceExtensions.test(entry.name)) texts.push({ file, text: readFileSync(file, "utf8") });
32
+ }
33
+ };
34
+ for (const directory of directories) visit(directory);
35
+ return texts;
36
+ }
37
+
38
+ /** Brand artwork is documented, licensed, previewed and used. Generated outputs match their masters. */
39
+ function inspectBrand({ root, dsRoot, config }) {
40
+ const diagnostics = [];
41
+ const relative = file => path.relative(root, file).replaceAll("\\", "/") || ".";
42
+ for (const { file, message } of staleBrandOutputs({ root, dsRoot, config })) diagnostics.push({ rule: "brand-output-stale", file, line: 1, column: 1, message });
43
+ const brand = path.join(dsRoot, "assets/brand");
44
+ const artwork = assetFiles(brand).filter(file => brandFormats.includes(path.extname(file).toLowerCase()));
45
+ if (!artwork.length) return diagnostics;
46
+ const warn = (rule, file, message) => diagnostics.push({ rule, severity: "warning", file: relative(file), line: 1, column: 1, guidanceUri: "ads://guides/branding", message });
47
+ const readmeFile = path.join(brand, "README.md");
48
+ const readme = existsSync(readmeFile) ? readFileSync(readmeFile, "utf8") : null;
49
+ if (readme === null) warn("brand-readme", brand, "Describe each artwork in assets/brand/README.md: its use, suitable backgrounds, credits and license.");
50
+ else if (!/licen[cs]e/i.test(readme)) warn("brand-license", readmeFile, "State the license (or ownership) of the brand artwork in assets/brand/README.md.");
51
+ const generated = [...config.assets.generatedPaths.map(entry => path.resolve(root, entry)), path.join(root, ".ds")];
52
+ const sources = sourceTexts([dsRoot, path.join(root, config.sourceDir ?? "src")], [path.join(dsRoot, "assets"), ...generated]);
53
+ const configured = new Set([config.assets.iconSource, ...config.assets.targets.map(target => target.from)].filter(Boolean).map(file => path.join(dsRoot, file)));
54
+ const previews = path.join(dsRoot, "brand");
55
+ for (const name of artwork) {
56
+ const file = path.join(brand, name), base = path.basename(name);
57
+ if (readme !== null && !readme.includes(base)) warn("brand-readme", file, `Describe ${base} in assets/brand/README.md: its use, suitable backgrounds, credits and license.`);
58
+ const referencing = sources.filter(source => source.text.includes(base));
59
+ if (!referencing.some(source => isInside(previews, source.file) && previewFile.test(source.file))) warn("brand-preview", file, `Show ${base} in a brand/ scenario, so it can be reviewed in the showcase's Brand section.`);
60
+ if (!configured.has(file) && !referencing.some(source => !previewFile.test(source.file))) warn("brand-unused", file, `${base} is not used by any component, assets.iconSource or assets.targets. Use it or remove it.`);
61
+ }
62
+ return diagnostics;
63
+ }
64
+
20
65
  export function inspectAssets({ root, dsRoot, config, trackingRoot = root }) {
21
66
  const diagnostics = [];
22
67
  const sourceDiagnostic = brandSourceDiagnostic({ root, dsRoot, config });
23
68
  if (sourceDiagnostic) diagnostics.push(sourceDiagnostic);
69
+ diagnostics.push(...inspectBrand({ root, dsRoot, config }));
24
70
  function report(rule, file, message) { diagnostics.push({ rule, file: path.relative(root, file).replaceAll("\\", "/") || ".", line: 1, column: 1, message }); }
25
71
  const assetRoot = path.join(dsRoot, "assets");
26
72
  // Every mount is compared with the canonical ADS assets. Public mounts are
@@ -1,6 +1,8 @@
1
- import { lstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
3
  import path from "node:path";
3
4
  import { isInside, loadConfig } from "./config.mjs";
5
+ import { imageSize } from "./image-size.mjs";
4
6
 
5
7
  export const brandFiles = ["favicon.svg", "favicon.ico", "apple-touch-icon.png", "icon-192.png", "icon-512.png"];
6
8
 
@@ -13,8 +15,15 @@ export function brandSourceDiagnostic({ root, dsRoot, config }) {
13
15
  if (!stat || stat.isSymbolicLink() || (current === file ? !stat.isFile() : !stat.isDirectory())) valid = false;
14
16
  if (current === root) break;
15
17
  }
18
+ const relative = path.relative(root, file).replaceAll("\\", "/");
19
+ if (valid && !file.toLowerCase().endsWith(".svg")) {
20
+ // A finished image is a master only when it is square and big enough for the largest icon.
21
+ const size = imageSize(readFileSync(file));
22
+ if (size && size.width === size.height && size.width >= 512) return null;
23
+ return { rule: "asset-source", file: relative, line: 1, column: 1, message: `assets.iconSource ${size ? `is ${size.width}×${size.height}; it` : "is not a readable PNG, JPEG or WebP; it"} must be a square image of at least 512×512, or an SVG.` };
24
+ }
16
25
  if (valid && /<svg\b[\s\S]*<\/svg\s*>|<svg\b[^>]*\/>/i.test(readFileSync(file, "utf8"))) return null;
17
- return { rule: "asset-source", file: path.relative(root, file).replaceAll("\\", "/"), line: 1, column: 1, message: "assets.iconSource must be an existing SVG master inside assets/brand/, without symlinked paths." };
26
+ return { rule: "asset-source", file: relative, line: 1, column: 1, message: "assets.iconSource must be an existing SVG master inside assets/brand/, without symlinked paths." };
18
27
  }
19
28
 
20
29
  function assertOutput(root, file, { directory = false } = {}) {
@@ -45,11 +54,164 @@ function ico(entries) {
45
54
  return result;
46
55
  }
47
56
 
57
+ const sha256 = bytes => createHash("sha256").update(bytes).digest("hex");
58
+ // Bump when rendering changes, so committed outputs are regenerated.
59
+ const renderer = "ads-brand-targets-1";
60
+ /** The committed record of rendered targets: what each output was made from. */
61
+ export const targetsManifest = "assets/generated.json";
62
+
63
+ /** A target's identity: its master's bytes and its settings, never the rendered pixels. */
64
+ function fingerprint(dsRoot, target) {
65
+ const { from, to, ...settings } = target;
66
+ return sha256(JSON.stringify({ renderer, to, settings, source: sha256(readFileSync(path.join(dsRoot, from))) }));
67
+ }
68
+
69
+ function readManifest(dsRoot) {
70
+ try { const value = JSON.parse(readFileSync(path.join(dsRoot, targetsManifest), "utf8")); return value?.outputs && typeof value.outputs === "object" ? value.outputs : {}; }
71
+ catch { return {}; }
72
+ }
73
+
74
+ // PNG-encoded ICNS entries by pixel size (a 1024 image is the 512@2x slot).
75
+ const icnsTypes = { 16: "icp4", 32: "icp5", 64: "icp6", 128: "ic07", 256: "ic08", 512: "ic09", 1024: "ic10" };
76
+ function icns(entries) {
77
+ const chunks = entries.map(({ size, buffer }) => {
78
+ const header = Buffer.alloc(8);
79
+ header.write(icnsTypes[size], 0, "ascii");
80
+ header.writeUInt32BE(buffer.length + 8, 4);
81
+ return Buffer.concat([header, buffer]);
82
+ });
83
+ const header = Buffer.alloc(8);
84
+ header.write("icns", 0, "ascii");
85
+ header.writeUInt32BE(8 + chunks.reduce((total, chunk) => total + chunk.length, 0), 4);
86
+ return Buffer.concat([header, ...chunks]);
87
+ }
88
+
89
+ const sized = target => ["size", "width", "height", "sizes", "background"].some(key => key in target);
90
+ /** A copy of the supplied file: the same format, no sizes. */
91
+ export const copiesTarget = target => !sized(target) && path.extname(target.to).toLowerCase() === path.extname(target.from).toLowerCase();
92
+
93
+ /** Why a raster master cannot make this target: ADS never enlarges a finished image. */
94
+ export function targetUpscale(source, target) {
95
+ if (copiesTarget(target) || target.from.toLowerCase().endsWith(".svg")) return null;
96
+ const size = imageSize(source);
97
+ if (!size) return `${target.from} is not a readable PNG, JPEG or WebP.`;
98
+ const sizes = target.sizes ?? [];
99
+ const width = target.width ?? target.size ?? Math.max(...sizes), height = target.height ?? target.size ?? Math.max(...sizes);
100
+ return Math.min(width / size.width, height / size.height) > 1 ? `${target.to} would enlarge ${target.from} (${size.width}×${size.height}) to ${width}×${height}. Supply a larger image or an SVG master.` : null;
101
+ }
102
+
103
+ async function renderTarget(sharp, source, target) {
104
+ const format = path.extname(target.to).toLowerCase();
105
+ if (copiesTarget(target)) return source;
106
+ const upscale = targetUpscale(source, target);
107
+ if (upscale) throw new Error(upscale);
108
+ const vector = target.from.toLowerCase().endsWith(".svg");
109
+ const background = target.background;
110
+ const png = async (width, height) => {
111
+ let image = sharp(source, vector ? { density: Math.max(72, Math.ceil(Math.max(width, height) * 1.5)) } : {})
112
+ .resize(width, height, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } });
113
+ if (background) image = image.flatten({ background });
114
+ return image.png().toBuffer();
115
+ };
116
+ if (format === ".png") return png(target.width ?? target.size, target.height ?? target.size);
117
+ const sizes = [...target.sizes].sort((a, b) => a - b);
118
+ const entries = [];
119
+ for (const size of sizes) entries.push({ size, buffer: await png(size, size) });
120
+ return format === ".ico" ? ico(entries.map(entry => ({ ...entry, size: entry.size === 256 ? 0 : entry.size }))) : icns(entries);
121
+ }
122
+
123
+ /** The glyph set as its generated module, or null without one. */
124
+ export function glyphModule({ dsRoot, config }) {
125
+ const glyphs = config.assets.glyphs;
126
+ if (!glyphs) return null;
127
+ const directory = path.join(dsRoot, glyphs.source);
128
+ const aliasFile = path.join(directory, "aliases.json");
129
+ const aliases = existsSync(aliasFile) ? JSON.parse(readFileSync(aliasFile, "utf8")) : {};
130
+ const attributes = glyphs.attributes ?? {};
131
+ const map = {};
132
+ for (const name of readdirSync(directory).filter(name => name.endsWith(".svg")).sort()) {
133
+ const id = name.slice(0, -4);
134
+ if (Object.hasOwn(aliases, id)) continue;
135
+ const svg = readFileSync(path.join(directory, name), "utf8").replace(/<\?xml[\s\S]*?\?>/g, "").trim()
136
+ .replace(/<svg\b([^>]*)>/, (_match, own) => {
137
+ const missing = Object.entries(attributes).filter(([key]) => !new RegExp(`(?:^|\\s)${key}=`).test(own)).map(([key, value]) => ` ${key}="${value}"`).join("");
138
+ return `<svg${missing}${own}>`;
139
+ });
140
+ map[id] = svg;
141
+ }
142
+ for (const [alias, target] of Object.entries(aliases)) if (!Object.hasOwn(map, target)) throw new Error(`${path.join(glyphs.source, "aliases.json")}: ${alias} names a missing glyph ${target}.`);
143
+ return `// Generated by \`ads assets\` from ${glyphs.source}/. Edit the SVGs, not this file.\n`
144
+ + `export const glyphs = ${JSON.stringify(map, null, 2)} as const;\n`
145
+ + `export const glyphAliases = ${JSON.stringify(aliases, null, 2)} as const;\n`;
146
+ }
147
+
148
+ /** Committed outputs that no longer match their masters, settings or rendered bytes. */
149
+ export function staleBrandOutputs(options) {
150
+ const { root, dsRoot, config } = options;
151
+ const stale = [];
152
+ const recorded = readManifest(dsRoot);
153
+ for (const target of config.assets.targets) {
154
+ const file = path.join(root, target.to);
155
+ const entry = recorded[target.to];
156
+ let reason = null;
157
+ if (!existsSync(path.join(dsRoot, target.from))) { stale.push({ file: target.to, message: `${target.to} names a missing master ${target.from}.` }); continue; }
158
+ const upscale = targetUpscale(readFileSync(path.join(dsRoot, target.from)), target);
159
+ if (upscale) { stale.push({ file: target.to, message: upscale }); continue; }
160
+ if (!existsSync(file)) reason = "is missing";
161
+ else if (!entry || entry.fingerprint !== fingerprint(dsRoot, target)) reason = `no longer matches ${target.from} or its settings`;
162
+ else if (entry.sha256 !== sha256(readFileSync(file))) reason = "was changed by hand";
163
+ if (reason) stale.push({ file: target.to, message: `${target.to} ${reason}. Run ads assets.` });
164
+ }
165
+ const glyphs = config.assets.glyphs;
166
+ if (glyphs) {
167
+ const file = path.join(dsRoot, glyphs.output);
168
+ let expected;
169
+ try { expected = glyphModule(options); } catch (error) { stale.push({ file: path.relative(root, file), message: error.message }); }
170
+ if (expected !== undefined && (!existsSync(file) || readFileSync(file, "utf8") !== expected)) stale.push({ file: path.relative(root, file).replaceAll("\\", "/"), message: `${glyphs.output} is out of date with ${glyphs.source}/. Run ads assets.` });
171
+ }
172
+ return stale;
173
+ }
174
+
175
+ /** Renders committed targets and the glyph module; unchanged outputs are left alone. */
176
+ async function generateCommitted(options) {
177
+ const { root, dsRoot, config } = options;
178
+ const written = [];
179
+ const recorded = readManifest(dsRoot), next = {};
180
+ let sharp;
181
+ for (const target of config.assets.targets) {
182
+ const file = path.join(root, target.to);
183
+ if (!existsSync(path.join(dsRoot, target.from))) throw new Error(`${target.to} names a missing master ${target.from}.`);
184
+ const print = fingerprint(dsRoot, target);
185
+ const entry = recorded[target.to];
186
+ if (entry?.fingerprint === print && existsSync(file) && entry.sha256 === sha256(readFileSync(file))) { next[target.to] = entry; continue; }
187
+ sharp ??= (await import("sharp")).default;
188
+ const bytes = await renderTarget(sharp, readFileSync(path.join(dsRoot, target.from)), target);
189
+ assertOutput(root, file);
190
+ mkdirSync(path.dirname(file), { recursive: true });
191
+ writeFileSync(file, bytes);
192
+ written.push(file);
193
+ next[target.to] = { from: target.from, fingerprint: print, sha256: sha256(bytes) };
194
+ }
195
+ const manifest = path.join(dsRoot, targetsManifest);
196
+ if (config.assets.targets.length) {
197
+ const sorted = Object.fromEntries(Object.entries(next).sort(([a], [b]) => a.localeCompare(b)));
198
+ const text = `${JSON.stringify({ schemaVersion: 1, outputs: sorted }, null, 2)}\n`;
199
+ if (!existsSync(manifest) || readFileSync(manifest, "utf8") !== text) { writeFileSync(manifest, text); written.push(manifest); }
200
+ } else if (existsSync(manifest)) { rmSync(manifest); written.push(manifest); }
201
+ const glyphs = glyphModule(options);
202
+ if (glyphs !== null) {
203
+ const file = path.join(dsRoot, config.assets.glyphs.output);
204
+ if (!existsSync(file) || readFileSync(file, "utf8") !== glyphs) { assertOutput(root, file); mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, glyphs); written.push(file); }
205
+ }
206
+ return written;
207
+ }
208
+
48
209
  export async function generateBrandAssets(directory = process.cwd()) {
49
210
  const options = loadConfig(directory);
50
211
  const { root, dsRoot, config } = options;
51
212
  const output = path.join(root, ".ds/assets");
52
- if (!config.assets.iconSource) return { directory: output, files: [], skipped: true };
213
+ const committed = await generateCommitted(options);
214
+ if (!config.assets.iconSource) return { directory: output, files: [], committed, skipped: !committed.length && !config.assets.targets.length && !config.assets.glyphs };
53
215
  const diagnostic = brandSourceDiagnostic(options);
54
216
  if (diagnostic) throw new Error(`${diagnostic.file} [${diagnostic.rule}] ${diagnostic.message}`);
55
217
  assertOutput(root, output, { directory: true });
@@ -63,10 +225,12 @@ export async function generateBrandAssets(directory = process.cwd()) {
63
225
  // before writing, so invalid SVG cannot replace the last successful outputs.
64
226
  const { default: sharp } = await import("sharp");
65
227
  const source = readFileSync(path.join(dsRoot, config.assets.iconSource));
66
- const outputs = new Map([["favicon.svg", source]]);
228
+ const vector = config.assets.iconSource.toLowerCase().endsWith(".svg");
229
+ // Only an SVG master is also the SVG favicon; a finished image makes the rest.
230
+ const outputs = new Map(vector ? [["favicon.svg", source]] : []);
67
231
  const sizes = [16, 32, 48, 180, 192, 512];
68
232
  const rendered = new Map();
69
- for (const size of sizes) rendered.set(size, await sharp(source, { density: 512 }).resize(size, size, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } }).png().toBuffer());
233
+ for (const size of sizes) rendered.set(size, await sharp(source, vector ? { density: 512 } : {}).resize(size, size, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } }).png().toBuffer());
70
234
  outputs.set("favicon.ico", ico([16, 32, 48].map((size) => ({ size, buffer: rendered.get(size) }))));
71
235
  outputs.set("apple-touch-icon.png", rendered.get(180));
72
236
  outputs.set("icon-192.png", rendered.get(192));
@@ -76,7 +240,10 @@ export async function generateBrandAssets(directory = process.cwd()) {
76
240
  try {
77
241
  for (const [name, buffer] of outputs) writeFileSync(path.join(staging, name), buffer);
78
242
  mkdirSync(output, { recursive: true });
79
- for (const name of brandFiles) renameSync(path.join(staging, name), path.join(output, name));
243
+ for (const name of brandFiles) {
244
+ if (outputs.has(name)) renameSync(path.join(staging, name), path.join(output, name));
245
+ else rmSync(path.join(output, name), { force: true });
246
+ }
80
247
  } finally { rmSync(staging, { recursive: true, force: true }); }
81
- return { directory: output, files: brandFiles.map((name) => path.join(output, name)), skipped: false };
248
+ return { directory: output, files: [...outputs.keys()].map((name) => path.join(output, name)), committed, skipped: false };
82
249
  }
package/dist/check.mjs CHANGED
@@ -54,7 +54,9 @@ export function checkProject(directory, { trackingRoot } = {}) {
54
54
  const tokenInventory = inspectTokens(root, options);
55
55
  const declaredTokens = new Set(tokenInventory.tokens.map((token) => token.name));
56
56
  diagnostics.push(...tokenInventory.diagnostics);
57
- diagnostics.push(...inspectAssets(options));
57
+ const assetFindings = inspectAssets(options);
58
+ diagnostics.push(...assetFindings.filter(finding => finding.severity !== "warning"));
59
+ const assetAdvisories = assetFindings.filter(finding => finding.severity === "warning");
58
60
  const resolveImport = importResolver(options);
59
61
  const units = inspectUnits(options);
60
62
  options.testOwner = file => units.owner(units.relative(path.relative(root,file)));
@@ -336,7 +338,7 @@ export function checkProject(directory, { trackingRoot } = {}) {
336
338
  inspectDesignAliases(layerStyles,options,report);
337
339
  // Bounded clients should see actionable warnings before source-analysis limits.
338
340
  for (const { file, css, offset } of layerStyles) layers.inspectStyles(file, css, offset);
339
- advisories.push(...(tokenInventory.advisories??[]));
341
+ advisories.push(...(tokenInventory.advisories??[]), ...assetAdvisories);
340
342
  advisories.sort((first, second) => Number(first.severity === "info") - Number(second.severity === "info"));
341
343
  const uniqueDiagnostics=[...new Map(diagnostics.map(diagnostic=>[JSON.stringify([diagnostic.file,diagnostic.rule,diagnostic.line,diagnostic.column,diagnostic.message]),diagnostic])).values()];
342
344
  return architectureEvidence({ ok: uniqueDiagnostics.length === 0, diagnostics:uniqueDiagnostics, ...(advisories.length ? { advisories } : {}) });
package/dist/cli.mjs CHANGED
@@ -8,9 +8,11 @@ import { assertBunRuntime } from "./runtime-requirements.mjs";
8
8
  const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
9
9
  const help = `ADS ${pkg.version} — tooling for a project's local design system
10
10
 
11
- Usage: ads init [options] Run inside your project
11
+ Usage: ads create <directory> --framework react|preact New design-system project
12
+ ads init [options] Run inside your project
12
13
  ads <command> [directory] [--json]
13
14
 
15
+ create <directory> Create a project from this version's starter, then init it
14
16
  init Set up ADS in the current project (requires package.json)
15
17
  check [directory] Check tokens, ownership, imports, and showcase coverage
16
18
  compile [directory] Build ADS previews with Bun (--watch for incremental previews)
@@ -26,9 +28,10 @@ Usage: ads init [options] Run inside your project
26
28
 
27
29
  --help Show this help
28
30
  --version Show the tool version
29
- --framework name Init only: react or preact (required until saved in config)
30
- --tool-package spec Init only: tool version or local tarball for devDependency
31
- --package-manager pm Init only: npm or bun (auto-detected from the project)
31
+ --framework name Create/init: react or preact (required until saved in config)
32
+ --name name Create only: package name (default: the folder name)
33
+ --tool-package spec Create/init: tool version or local tarball for devDependency
34
+ --package-manager pm Create/init: npm or bun (create default npm; init detects it)
32
35
  --port number MCP/showcase only: loopback website port (default: automatic)
33
36
  --no-showcase MCP only: disable the local website
34
37
  --mutations MCP only: enable guarded ADS source editing
@@ -49,6 +52,7 @@ async function main(args) {
49
52
  let toolPackage;
50
53
  let packageManager;
51
54
  let framework;
55
+ let name;
52
56
  let port;
53
57
  let unit;
54
58
  const selectedChecks = [];
@@ -82,6 +86,9 @@ async function main(args) {
82
86
  } else if (argument === "--package-manager") {
83
87
  if (packageManager !== undefined || !args[index + 1] || args[index + 1].startsWith("-")) throw new Error("Specify one package manager after --package-manager: npm or bun.");
84
88
  packageManager = args[++index];
89
+ } else if (argument === "--name") {
90
+ if (name !== undefined || !args[index + 1] || args[index + 1].startsWith("-")) throw new Error("Specify one package name after --name.");
91
+ name = args[++index];
85
92
  } else if (argument === "--framework") {
86
93
  if (framework !== undefined || !args[index + 1] || args[index + 1].startsWith("-")) throw new Error("Specify one framework after --framework: react or preact.");
87
94
  framework = args[++index];
@@ -90,7 +97,7 @@ async function main(args) {
90
97
  }
91
98
  if (positional.length > 2) throw new Error("Extra argument. Run ads --help.");
92
99
  const [command, directory] = positional;
93
- if(command!=="init"){
100
+ if(command!=="init"&&command!=="create"){
94
101
  const exitCode=await enterMemoryBudget(loadConfig(path.resolve(directory??process.cwd())).config,args);
95
102
  if(exitCode!==null){process.exitCode=exitCode;return;}
96
103
  }
@@ -103,9 +110,12 @@ async function main(args) {
103
110
  if ((port !== undefined || !showcase) && !["mcp", "showcase"].includes(command)) throw new Error("Website options are supported only by mcp/showcase.");
104
111
  if (!showcase && command !== "mcp") throw new Error("--no-showcase is supported only by mcp.");
105
112
  if (mutations && command !== "mcp") throw new Error("--mutations is supported only by mcp.");
106
- if (toolPackage !== undefined && command !== "init") throw new Error("--tool-package is supported only by init.");
107
- if (packageManager !== undefined && command !== "init") throw new Error("--package-manager is supported only by init.");
108
- if (framework !== undefined && command !== "init") throw new Error("--framework is supported only by init.");
113
+ const setup = command === "init" || command === "create";
114
+ if (toolPackage !== undefined && !setup) throw new Error("--tool-package is supported only by create and init.");
115
+ if (packageManager !== undefined && !setup) throw new Error("--package-manager is supported only by create and init.");
116
+ if (framework !== undefined && !setup) throw new Error("--framework is supported only by create and init.");
117
+ if (name !== undefined && command !== "create") throw new Error("--name is supported only by create.");
118
+ if (command === "create" && !directory) throw new Error("Name the new project's folder: ads create <directory> --framework react|preact.");
109
119
  if (command === "init" && directory) throw new Error("Run ads init inside the project, without a directory argument.");
110
120
  if ((unit || selectedChecks.length) && command !== "verify") throw new Error("--unit and --check are supported only by verify.");
111
121
  const target = path.resolve(directory ?? process.cwd());
@@ -116,7 +126,8 @@ async function main(args) {
116
126
  return;
117
127
  }
118
128
  let result;
119
- if (command === "init") result = initProject(target, { toolPackage, packageManager, framework });
129
+ if (command === "create") { const { createProject } = await import("./create.mjs"); result = createProject(target, { framework, packageManager, name, toolPackage }); }
130
+ else if (command === "init") result = initProject(target, { toolPackage, packageManager, framework });
120
131
  else if (command === "check") {const {checkCandidate}=await import("./validation-checks.mjs");result=await checkCandidate(target,undefined,target,{fresh});}
121
132
  else if (command === "validate") {
122
133
  const {createValidationController}=await import("./validation.mjs");
@@ -132,6 +143,7 @@ async function main(args) {
132
143
  else if (command === "lint-config") result = generateLintConfig(target);
133
144
  else throw new Error(`Unknown command: ${command}. Run ads --help.`);
134
145
  if (json) console.log(JSON.stringify(result, null, 2));
146
+ else if (command === "create") console.log(`Created ${result.name} in ${target}\nFramework: ${result.framework}\nNext: cd ${((folder) => /[\s'"$`\\]/.test(folder) ? JSON.stringify(folder) : folder)(path.relative(process.cwd(), target) || ".")} && ${result.packageManager} install && ${result.packageManager} run build && ${result.packageManager} run dev:showcase`);
135
147
  else if (command === "init") console.log(`Initialized ${target}\nFramework: ${result.framework}\nAdded ${result.toolDependency.name} (${result.toolDependency.spec}) as a development dependency.\nRun ${result.packageManager} install and ${result.packageManager} run build; the build runs ADS checks and generates configured brand assets automatically.`);
136
148
  else if (command === "assets") console.log(result.skipped ? "No assets.iconSource configured; brand generation skipped." : `Generated ${result.files.length} brand assets in ${result.directory}.`);
137
149
  else if (command === "lint-config") console.log(`Generated ${result.file}\nUse this optional configuration only in the project linter you choose to run.`);
package/dist/config.mjs CHANGED
@@ -20,7 +20,7 @@ export const defaultConfig = {
20
20
  tokenDir: "tokens",
21
21
  inlineStyleFiles: [],
22
22
  boundaries: { styleWrites: [], componentVariables: [] },
23
- assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null },
23
+ assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null, targets: [], glyphs: null },
24
24
  oxlint: { plugins: [], rules: {}, overrides: [] },
25
25
  acceptance: { checks: [], behaviorChecks: false },
26
26
  validation: { checks: [], behaviorChecks: true, inputs: [] },
@@ -33,6 +33,59 @@ export function isInside(parent, file) {
33
33
  return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative));
34
34
  }
35
35
 
36
+ const iconSizes = [16, 32, 64, 128, 256, 512, 1024];
37
+ /** Brand artwork formats: SVG masters, finished images, and finished icon files. */
38
+ export const brandFormats = [".svg", ".png", ".jpg", ".jpeg", ".webp", ".ico", ".icns"];
39
+ /** Formats a target can render from; finished .ico/.icns files are only copied. */
40
+ export const renderableFormats = [".svg", ".png", ".jpg", ".jpeg", ".webp"];
41
+ const sizeKeys = ["size", "width", "height", "sizes", "background"];
42
+ /** Committed brand outputs: each copies or renders one master in assets/brand/ to a project path. */
43
+ function validateBrandTargets(targets, { root, dsRoot }) {
44
+ if (!Array.isArray(targets)) throw new Error("assets.targets must be an array.");
45
+ const outputs = new Set();
46
+ for (const [index, target] of targets.entries()) {
47
+ const field = `assets.targets[${index}]`;
48
+ if (!target || typeof target !== "object" || Array.isArray(target)) throw new Error(`${field} must be an object.`);
49
+ const unknown = Object.keys(target).filter(key => !["from", "to", ...sizeKeys].includes(key));
50
+ if (unknown.length) throw new Error(`${field} has unknown keys: ${unknown.join(", ")}.`);
51
+ const source = projectPath(dsRoot, target.from, `${field}.from`);
52
+ const sourceFormat = path.extname(source).toLowerCase();
53
+ if (!isInside(path.join(dsRoot, "assets/brand"), source) || !brandFormats.includes(sourceFormat)) throw new Error(`${field}.from must name brand artwork inside the ADS's assets/brand/ folder (${brandFormats.join(", ")}).`);
54
+ const output = projectPath(root, target.to, `${field}.to`);
55
+ if (isInside(path.join(dsRoot, "assets"), output) || isInside(path.join(root, ".ds"), output)) throw new Error(`${field}.to must be outside the ADS assets/ folder and .ds/.`);
56
+ if (outputs.has(output)) throw new Error(`${field}.to repeats an earlier target's output.`);
57
+ outputs.add(output);
58
+ const format = path.extname(output).toLowerCase();
59
+ const sized = sizeKeys.some(key => key in target);
60
+ // The same format without sizes is a copy of the supplied file.
61
+ if (!sized && format === sourceFormat) continue;
62
+ if (format === ".svg") throw new Error(`${field} copies an SVG master to .svg; it takes no sizes.`);
63
+ if (!renderableFormats.includes(sourceFormat)) throw new Error(`${field} copies the finished ${sourceFormat} file; give it the same extension and no sizes.`);
64
+ const pixels = value => Number.isInteger(value) && value >= 1 && value <= 4096;
65
+ if (target.background !== undefined && (typeof target.background !== "string" || !/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(target.background))) throw new Error(`${field}.background must be a #RGB, #RRGGBB or #RRGGBBAA colour on a PNG, ICO or ICNS target.`);
66
+ if (format === ".png") {
67
+ const square = target.size !== undefined, rectangle = target.width !== undefined || target.height !== undefined;
68
+ if (square === rectangle || target.sizes !== undefined || (square ? !pixels(target.size) : !pixels(target.width) || !pixels(target.height))) throw new Error(`${field} renders a PNG at one size (1–4096) or one width and height.`);
69
+ } else if (format === ".ico" || format === ".icns") {
70
+ const allowed = format === ".ico" ? [16, 24, 32, 48, 64, 128, 256] : iconSizes;
71
+ if (["size", "width", "height"].some(key => key in target) || !Array.isArray(target.sizes) || !target.sizes.length || new Set(target.sizes).size !== target.sizes.length || target.sizes.some(size => !allowed.includes(size))) throw new Error(`${field}.sizes must list distinct ${format.slice(1).toUpperCase()} sizes from ${allowed.join(", ")}.`);
72
+ } else throw new Error(`${field}.to must end in .svg, .png, .ico or .icns, or keep the supplied file's extension.`);
73
+ }
74
+ }
75
+ /** A glyph set: SVGs in one assets/ folder become one generated TypeScript map. */
76
+ function validateGlyphs(glyphs, { dsRoot }) {
77
+ if (glyphs === null) return;
78
+ if (!glyphs || typeof glyphs !== "object" || Array.isArray(glyphs)) throw new Error("assets.glyphs must be an object or null.");
79
+ const unknown = Object.keys(glyphs).filter(key => !["source", "output", "attributes"].includes(key));
80
+ if (unknown.length) throw new Error(`assets.glyphs has unknown keys: ${unknown.join(", ")}.`);
81
+ const source = projectPath(dsRoot, glyphs.source, "assets.glyphs.source");
82
+ if (!isInside(path.join(dsRoot, "assets"), source) || source === path.join(dsRoot, "assets")) throw new Error("assets.glyphs.source must be a folder inside the ADS's assets/ folder.");
83
+ const output = projectPath(dsRoot, glyphs.output, "assets.glyphs.output");
84
+ if (isInside(path.join(dsRoot, "assets"), output) || path.extname(output) !== ".ts") throw new Error("assets.glyphs.output must be a .ts module in the ADS, outside assets/.");
85
+ const attributes = glyphs.attributes ?? {};
86
+ if (!attributes || typeof attributes !== "object" || Array.isArray(attributes) || Object.entries(attributes).some(([name, value]) => !/^[a-z][a-z0-9-]*$/.test(name) || typeof value !== "string" || /["<>]/.test(value))) throw new Error("assets.glyphs.attributes maps SVG attribute names to plain string values.");
87
+ }
88
+
36
89
  export function projectPath(root, value, field) {
37
90
  if (typeof value !== "string" || !value.trim() || path.isAbsolute(value)) {
38
91
  throw new Error(`${field} must be a non-empty relative path.`);
@@ -122,8 +175,10 @@ export function loadConfig(directory = process.cwd()) {
122
175
  }
123
176
  if (config.assets.iconSource !== null) {
124
177
  const source = projectPath(dsRoot, config.assets.iconSource, "assets.iconSource");
125
- if (!isInside(path.join(dsRoot, "assets/brand"), source) || path.extname(source).toLowerCase() !== ".svg") throw new Error("assets.iconSource must name an SVG inside the ADS's assets/brand/ folder.");
178
+ if (!isInside(path.join(dsRoot, "assets/brand"), source) || !renderableFormats.includes(path.extname(source).toLowerCase())) throw new Error("assets.iconSource must name an SVG, or a square PNG, JPEG or WebP of at least 512 px, inside the ADS's assets/brand/ folder.");
126
179
  }
180
+ validateBrandTargets(config.assets.targets, { root, dsRoot });
181
+ validateGlyphs(config.assets.glyphs, { dsRoot });
127
182
  for (const plugin of config.oxlint.plugins) {
128
183
  if (!plugin || Object.keys(plugin).some((key) => !["name", "path"].includes(key)) || typeof plugin.name !== "string" || !plugin.name || typeof plugin.path !== "string") {
129
184
  throw new Error("Each project Oxlint plugin needs a name and a relative path.");
@@ -222,7 +277,7 @@ export function isDevelopmentFile(file, { dsRoot }) {
222
277
  if (!isInside(dsRoot, file)) return isTestFile(file) || adsFileRole(file) !== null;
223
278
  const relative = path.relative(dsRoot, file).replaceAll("\\", "/");
224
279
  return adsFileRole(file) !== null || isTestFile(file) || isScenarioFile(file) || isFixtureFile(file) || isBehaviorFile(file)
225
- || /^(?:showcase|composition|review)\//.test(relative)
280
+ || /^(?:showcase|composition|review|brand)\//.test(relative)
226
281
  || /(?:^|\/)(?:scenario|fixtures)(?:\/|$)/.test(relative)
227
282
  || /\.scenario(?:-adapter)?\.[cm]?[jt]sx?$/.test(relative);
228
283
  }
@@ -259,6 +314,8 @@ export function importViolation(specifier, filename, options, resolve) {
259
314
  : specifier.startsWith(`${config.dsDir}/`) ? [path.resolve(root, specifier)] : [];
260
315
  return imported.some((file) => {
261
316
  if (!isInside(dsRoot, file)) return false;
317
+ // Previews may show the ADS's own artwork and fonts: asset files are data, not implementation.
318
+ if (isDevelopmentFile(filename, options) && isInside(path.join(dsRoot, "assets"), file.replace(/\?[^/\\]*$/, ""))) return false;
262
319
  // Review implementations can reuse local foundation helpers. Resolved public
263
320
  // UI/controller contracts are enforced by the layer inspector, as for patterns.
264
321
  if (isReviewFile(filename, options)) return false;
@@ -0,0 +1,48 @@
1
+ import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { supportedFrameworks } from "./config.mjs";
5
+ import { initProject } from "./init.mjs";
6
+
7
+ // The starters ship in this package: the React starter, and per framework the files that
8
+ // replace it. A created project therefore always matches the tool that checks it.
9
+ const starters = fileURLToPath(new URL("./starters/", import.meta.url));
10
+
11
+ /** An npm package name from a folder name. */
12
+ function packageName(value) {
13
+ const name = value.toLowerCase().replace(/[^a-z0-9._~-]+/g, "-").replace(/^[._-]+|[-.]+$/g, "");
14
+ return name || "design-system";
15
+ }
16
+
17
+ /** Creates a new design-system project in `directory` from this version's starter, then
18
+ * initializes ADS in it. The directory must be missing or empty. */
19
+ export function createProject(directory, { framework, packageManager = "npm", name, toolPackage } = {}) {
20
+ if (!supportedFrameworks.includes(framework)) throw new Error("Specify --framework react or --framework preact.");
21
+ if (!["npm", "bun"].includes(packageManager)) throw new Error("packageManager must be npm or bun.");
22
+ if (name !== undefined && (typeof name !== "string" || !name.trim())) throw new Error("Specify a package name after --name.");
23
+ const root = path.resolve(directory);
24
+ const stat = lstatSync(root, { throwIfNoEntry: false });
25
+ if (stat && (!stat.isDirectory() || stat.isSymbolicLink())) throw new Error(`${root} exists and is not a folder.`);
26
+ if (stat && readdirSync(root).length) throw new Error(`${root} is not empty. Create a project in a new or empty folder; run ads init inside an existing app.`);
27
+ mkdirSync(root, { recursive: true });
28
+ try {
29
+ cpSync(path.join(starters, "react"), root, { recursive: true });
30
+ // npm drops .gitignore files from packages, so the starter carries a template.
31
+ if (existsSync(path.join(root, "gitignore.template"))) renameSync(path.join(root, "gitignore.template"), path.join(root, ".gitignore"));
32
+ if (framework !== "react") cpSync(path.join(starters, framework), root, { recursive: true });
33
+ const packageFile = path.join(root, "package.json");
34
+ const pkg = JSON.parse(readFileSync(packageFile, "utf8"));
35
+ pkg.name = name?.trim() ?? packageName(path.basename(root));
36
+ // The starter's lockfile is React's npm lock; other frameworks and Bun create their own.
37
+ if (framework !== "react" || packageManager === "bun") rmSync(path.join(root, "package-lock.json"), { force: true });
38
+ if (packageManager === "bun") for (const [script, command] of Object.entries(pkg.scripts ?? {})) pkg.scripts[script] = command.replaceAll("npm run ", "bun run ");
39
+ writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`);
40
+ const initialized = initProject(root, { framework, packageManager, toolPackage });
41
+ return { ...initialized, created: true, name: pkg.name };
42
+ } catch (error) {
43
+ // A failed creation leaves the folder as it was found.
44
+ if (!stat) rmSync(root, { recursive: true, force: true });
45
+ else for (const entry of readdirSync(root)) rmSync(path.join(root, entry), { recursive: true, force: true });
46
+ throw error;
47
+ }
48
+ }