@cagov/ca-ds 1.0.0 → 1.1.0

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 (101) hide show
  1. package/README.md +4 -2
  2. package/THIRD-PARTY-LICENSES.txt +690 -0
  3. package/ca-ds.js +48337 -0
  4. package/package.json +5 -31
  5. package/bin/ca-ds.js +0 -5
  6. package/src/cli/add.js +0 -134
  7. package/src/cli/build.js +0 -15
  8. package/src/cli/diff.js +0 -39
  9. package/src/cli/eject.js +0 -112
  10. package/src/cli/exit.js +0 -22
  11. package/src/cli/format.js +0 -52
  12. package/src/cli/init.js +0 -148
  13. package/src/cli/install.js +0 -178
  14. package/src/cli/items.js +0 -10
  15. package/src/cli/login.js +0 -331
  16. package/src/cli/main.js +0 -108
  17. package/src/cli/new.js +0 -230
  18. package/src/cli/outdated.js +0 -74
  19. package/src/cli/pack.js +0 -75
  20. package/src/cli/preview.js +0 -31
  21. package/src/cli/publish.js +0 -295
  22. package/src/cli/pull.js +0 -208
  23. package/src/cli/remote.js +0 -52
  24. package/src/cli/remove.js +0 -69
  25. package/src/cli/update.js +0 -223
  26. package/src/cli/validate.js +0 -131
  27. package/src/lib/browser.js +0 -12
  28. package/src/lib/build.js +0 -249
  29. package/src/lib/bundle.js +0 -148
  30. package/src/lib/catalog.js +0 -44
  31. package/src/lib/checks.js +0 -31
  32. package/src/lib/collection.js +0 -65
  33. package/src/lib/emblem.js +0 -29
  34. package/src/lib/fixtures.js +0 -59
  35. package/src/lib/floor.js +0 -79
  36. package/src/lib/glyph.js +0 -148
  37. package/src/lib/image.js +0 -138
  38. package/src/lib/json-text.js +0 -213
  39. package/src/lib/keys.js +0 -322
  40. package/src/lib/links.js +0 -321
  41. package/src/lib/markdown.js +0 -408
  42. package/src/lib/merge.js +0 -93
  43. package/src/lib/pack.js +0 -30
  44. package/src/lib/page-schema.js +0 -368
  45. package/src/lib/page.js +0 -372
  46. package/src/lib/patch.js +0 -9
  47. package/src/lib/regions.js +0 -173
  48. package/src/lib/registry.js +0 -371
  49. package/src/lib/release.js +0 -119
  50. package/src/lib/repoints.js +0 -120
  51. package/src/lib/resolve.js +0 -32
  52. package/src/lib/schema.js +0 -28
  53. package/src/lib/serial.js +0 -4
  54. package/src/lib/serialize.js +0 -444
  55. package/src/lib/structured.js +0 -72
  56. package/src/lib/system.js +0 -13
  57. package/src/lib/targets.js +0 -85
  58. package/src/lib/terms.js +0 -11
  59. package/src/lib/token-view.js +0 -289
  60. package/src/lib/tokens.js +0 -247
  61. package/src/lib/version.js +0 -34
  62. package/src/preview/frame.js +0 -75
  63. package/src/preview/pages.js +0 -128
  64. package/src/preview/screenshots.js +0 -72
  65. package/src/preview/server.js +0 -378
  66. package/src/preview/shell.js +0 -153
  67. package/src/schema/a11y.schema.json +0 -56
  68. package/src/schema/collection.lock.schema.json +0 -58
  69. package/src/schema/collection.schema.json +0 -65
  70. package/src/schema/composition.schema.json +0 -98
  71. package/src/schema/contract.schema.json +0 -116
  72. package/src/schema/interface.schema.json +0 -257
  73. package/src/schema/item.schema.json +0 -362
  74. package/src/schema/release.schema.json +0 -39
  75. package/src/schema/system.schema.json +0 -75
  76. package/src/schema/variants.schema.json +0 -60
  77. package/src/validate/collection.js +0 -19
  78. package/src/validate/collisions.js +0 -124
  79. package/src/validate/context.js +0 -357
  80. package/src/validate/facts.js +0 -253
  81. package/src/validate/files.js +0 -103
  82. package/src/validate/findings.js +0 -19
  83. package/src/validate/glyphs.js +0 -126
  84. package/src/validate/html.js +0 -215
  85. package/src/validate/imports.js +0 -29
  86. package/src/validate/index.js +0 -75
  87. package/src/validate/item.js +0 -47
  88. package/src/validate/links.js +0 -113
  89. package/src/validate/manifest.js +0 -147
  90. package/src/validate/media.js +0 -65
  91. package/src/validate/page.js +0 -74
  92. package/src/validate/prefixes.js +0 -58
  93. package/src/validate/relations.js +0 -310
  94. package/src/validate/release.js +0 -109
  95. package/src/validate/skill.js +0 -122
  96. package/src/validate/structured.js +0 -335
  97. package/src/validate/tasc.js +0 -80
  98. package/src/validate/template.js +0 -129
  99. package/src/validate/tokens.js +0 -154
  100. package/src/validate/zip.js +0 -40
  101. /package/{src/preview/preview.css → preview.css} +0 -0
package/src/cli/new.js DELETED
@@ -1,230 +0,0 @@
1
- import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
2
- import { dirname, join, relative, resolve as resolvePath, sep } from 'node:path';
3
- import semver from 'semver';
4
- import { usageError } from './exit.js';
5
- import { itemNamed } from './items.js';
6
- import { formatPage } from '../lib/page.js';
7
- import { frontmatterFindings } from '../validate/skill.js';
8
-
9
- const NAME = /^([a-z0-9]+(?:-[a-z0-9]+)*)\/([a-z0-9]+(?:-[a-z0-9]+)*)$/;
10
- const json = (data) => `${JSON.stringify(data, null, 2)}\n`;
11
-
12
- const titleOf = (base) => base.charAt(0).toUpperCase() + base.slice(1).replace(/-/g, ' ');
13
-
14
- function component({ name, base, title }) {
15
- const tag = `ca-${base}`;
16
- const phrase = title.toLowerCase();
17
- return {
18
- manifest: {
19
- kind: 'component',
20
- description: `The ${phrase} component.`,
21
- doc: `${base}.md`,
22
- files: [
23
- { path: `${base}.md`, role: 'doc' },
24
- { path: `${base}.contract.json`, role: 'contract' },
25
- { path: `${base}.css`, role: 'css' },
26
- { path: 'examples/default.html', role: 'reference-html', title, description: `The ${phrase} in its default configuration, for a request that names no variant.` },
27
- ],
28
- tasks: [phrase],
29
- },
30
- files: {
31
- [`${base}.md`]: [
32
- `# ${title}`,
33
- '',
34
- `The ${phrase} is \`<${tag}>\`, a component of the \`${name.split('/')[0]}\` namespace. This paragraph says what it is and what it's for, in a sentence or two.`,
35
- '',
36
- `The first decision a consumer makes about it follows here, with its choices. [The contract](${name}#rules) holds the rules its output meets, and [the default example](${name}/examples/default.html) holds its default markup.`,
37
- '',
38
- ].join('\n'),
39
- [`${base}.contract.json`]: json({
40
- rules: [
41
- {
42
- id: 'has-content',
43
- rule: `Every \`<${tag}>\` holds content.`,
44
- why: 'An empty element renders nothing a reader can perceive.',
45
- severity: 'must',
46
- tags: ['content'],
47
- check: { each: tag, has: ':not(:empty)' },
48
- },
49
- ],
50
- }),
51
- [`${base}.css`]: [
52
- `/* <${tag}>: the reference stylesheet. Every selector sits inside`,
53
- ' * :where(), so a consumer\'s own rule always wins, and every value is a',
54
- ' * --ca-* custom property. */',
55
- '',
56
- `:where(${tag}) {`,
57
- ' display: block;',
58
- '}',
59
- '',
60
- ].join('\n'),
61
- 'examples/default.html': `<${tag}>${title}</${tag}>\n`,
62
- },
63
- };
64
- }
65
-
66
- function guidance({ base, title }) {
67
- return {
68
- manifest: {
69
- kind: 'guidance',
70
- description: `A guide to ${title.toLowerCase()}.`,
71
- doc: `${base}.md`,
72
- files: [{ path: `${base}.md`, role: 'doc' }],
73
- tasks: [title.toLowerCase()],
74
- },
75
- files: {
76
- [`${base}.md`]: [
77
- `# ${title}`,
78
- '',
79
- 'Say what this doc covers and when to read it, in a sentence or two.',
80
- '',
81
- '## Do the first task',
82
- '',
83
- 'Give the steps of one task per section, as a numbered list when their order matters. Head each section with a verb phrase.',
84
- '',
85
- ].join('\n'),
86
- },
87
- };
88
- }
89
-
90
- function template({ name, base, title }, collection) {
91
- const layout = itemNamed(collection, 'standard/layout');
92
- const version = semver.valid(layout?.manifest.version);
93
- const page = `examples/${base}.html`;
94
- return {
95
- manifest: {
96
- kind: 'template',
97
- description: `A ${title.toLowerCase()} page.`,
98
- doc: `${base}.md`,
99
- files: [
100
- { path: `${base}.md`, role: 'doc' },
101
- { path: `${base}.composition.json`, role: 'composition' },
102
- { path: page, role: 'reference-html', title, description: `A whole ${title.toLowerCase()} page in document order.` },
103
- ],
104
- ...(version ? { dependencies: { 'standard/layout': `^${semver.major(version)}.${semver.minor(version)}.0` } } : {}),
105
- tasks: [`${title.toLowerCase()} page`],
106
- },
107
- files: {
108
- [`${base}.md`]: [
109
- `# ${title}`,
110
- '',
111
- 'Say what page this template is and who it serves, in a sentence or two. Then name what the page holds, in document order, as a list.',
112
- '',
113
- `[The composition](${name}/${base}.composition.json) holds the intent of each region, and [the page](${name}/${page}) holds the whole page.`,
114
- '',
115
- ].join('\n'),
116
- [`${base}.composition.json`]: json({
117
- regions: [{ id: 'content', title: 'Content', contents: "What the page says, in place of the example's heading and paragraph." }],
118
- }),
119
- [page]: ['<ca-layout>', ' <main>', ' <section class="ca-prose">', ` <h1>${title}</h1>`, " <p>The page's opening paragraph.</p>", ' </section>', ' </main>', '</ca-layout>', ''].join('\n'),
120
- },
121
- };
122
- }
123
-
124
- function media({ base, title }) {
125
- const file = `${base}.svg`;
126
- const [width, height] = [960, 540];
127
- return {
128
- manifest: {
129
- kind: 'media',
130
- description: `A placeholder for the ${title.toLowerCase()} image.`,
131
- files: [{ path: file, role: 'image' }],
132
- tasks: [`${title.toLowerCase()} image`],
133
- media: {
134
- alt: `A gray rectangle standing in for the ${title.toLowerCase()} image.`,
135
- renditions: [{ file, width, height }],
136
- },
137
- },
138
- files: {
139
- [file]: `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img"><title>${title}</title><rect width="${width}" height="${height}" fill="#d4d4d4"/></svg>\n`,
140
- },
141
- };
142
- }
143
-
144
- function page({ base, title }) {
145
- const doc = `${base}.html`;
146
- return {
147
- manifest: {
148
- kind: 'page',
149
- description: `The ${title.toLowerCase()} page.`,
150
- doc,
151
- files: [{ path: doc, role: 'doc' }],
152
- slug: base,
153
- },
154
- files: {
155
- [doc]: formatPage(`<section class="ca-prose"><h1>${title.replace(/&/g, '&amp;').replace(/</g, '&lt;')}</h1><p>The page's opening paragraph.</p></section>`),
156
- },
157
- };
158
- }
159
-
160
- function skill({ base, skillName }) {
161
- const name = skillName ?? base.replace(/-skill$/, '');
162
- const phrase = name.replace(/-/g, ' ');
163
- const refused = frontmatterFindings({ name, description: 'A skill.' })[0];
164
- if (refused) throw usageError(`${refused.message} Name the skill with --skill-name.`);
165
- return {
166
- manifest: {
167
- kind: 'skill',
168
- description: `The ${phrase} skill.`,
169
- doc: 'SKILL.md',
170
- files: [{ path: 'SKILL.md', role: 'doc' }],
171
- tasks: [phrase],
172
- },
173
- files: {
174
- 'SKILL.md': [
175
- '---',
176
- `name: ${name}`,
177
- `description: Say what the ${name} skill does and when an agent uses it, in a sentence or two.`,
178
- '---',
179
- '',
180
- `# ${titleOf(name)}`,
181
- '',
182
- 'Give the steps an agent follows, as a numbered list when their order matters.',
183
- '',
184
- ].join('\n'),
185
- },
186
- };
187
- }
188
-
189
- export const KINDS = { component, guidance, template, media, page, skill };
190
-
191
- export function scaffold(collection, { kind, name, dir, title = null, skillName = null }) {
192
- const match = NAME.exec(name ?? '');
193
- if (!match) throw usageError(`${name} is not a scoped name, such as myteam/status-badge: lowercase letters and digits, in words joined by hyphens, a slash between the namespace and the name.`);
194
- const [, scope, base] = match;
195
- if (!Object.hasOwn(KINDS, kind)) throw usageError(`${kind} is not a kind new scaffolds. The kinds are ${Object.keys(KINDS).join(', ')}.`);
196
- const namespaces = collection.config?.namespaces ?? [];
197
- if (!namespaces.includes(scope)) throw usageError(`${scope} is not among the namespaces collection.json authors${namespaces.length ? `, ${namespaces.join(', ')}` : ''}. Add it there first.`);
198
- if (itemNamed(collection, name)) throw usageError(`The collection already holds ${name}.`);
199
- if (base === 'notes' && kind !== 'media') throw usageError("A doc named notes.md is a folder's notes, which never ship. Pick another name.");
200
- if (skillName !== null && kind !== 'skill') throw usageError('--skill-name names a skill, so it takes kind skill alone.');
201
- const source = relative(collection.root, dir).split(sep).join('/');
202
- if (!source || source.startsWith('..') || resolvePath(collection.root, source) !== dir) throw usageError(`${dir} is not a folder inside the collection.`);
203
- if (existsSync(dir) && readdirSync(dir).length) throw usageError(`${source} already exists and holds files.`);
204
-
205
- const shape = KINDS[kind]({ name, base, title: title ?? titleOf(base), skillName }, collection);
206
- const { kind: k, description, ...rest } = shape.manifest;
207
- const manifest = { name, kind: k, version: '0.1.0', title: title ?? titleOf(base), description, ...rest, source };
208
- const files = { 'item.json': json(manifest), ...shape.files };
209
- for (const [path, body] of Object.entries(files)) {
210
- mkdirSync(dirname(join(dir, path)), { recursive: true });
211
- writeFileSync(join(dir, path), body);
212
- }
213
- return { name, kind, dir: source, files: Object.keys(files).sort() };
214
- }
215
-
216
- export const command = {
217
- synopsis: 'new <kind> <scope>/<name>',
218
- summary: `scaffold an item folder that passes validate: ${Object.keys(KINDS).join(', ')}`,
219
- usage: [`ca-ds new ${Object.keys(KINDS).join('|')} <scope>/<name> [--dir <folder>] [--title <title>] [--skill-name <name>]`],
220
- options: { dir: { type: 'string' }, title: { type: 'string' }, 'skill-name': { type: 'string' } },
221
- async run({ values, positionals, io, collection }) {
222
- const [kind, name, ...extra] = positionals;
223
- if (!kind || !name || extra.length) throw usageError('Name one kind and one scoped name.');
224
- const c = collection();
225
- const dir = resolvePath(values.dir ?? NAME.exec(name)?.[2] ?? name);
226
- const result = scaffold(c, { kind, name, dir, title: values.title ?? null, skillName: values['skill-name'] ?? null });
227
- io.log(`Wrote ${name}, a ${kind}, to ${result.dir}/: ${result.files.join(', ')}`);
228
- return { result };
229
- },
230
- };
@@ -1,74 +0,0 @@
1
- import semver from 'semver';
2
- import { isSystemItem } from '../lib/system.js';
3
- import { CliError, EXIT, usageError } from './exit.js';
4
- import { liveVersions } from './add.js';
5
- import { connect, TOKEN } from './remote.js';
6
-
7
- export async function targets(collection, client) {
8
- const { config, lock } = collection;
9
- const release = config.release ?? null;
10
- let newest = null;
11
- if (release) {
12
- newest = await client.release('latest');
13
- if (!newest) throw new CliError(`collection.json names the release ${release}, and the registry at ${client.url} records none.`, EXIT.registry);
14
- }
15
- const pins = new Map((newest?.items ?? []).map((e) => [e.name, e.version]));
16
- const out = [];
17
- for (const [name, entry] of Object.entries(lock.items).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
18
- const record = await client.item(name);
19
- const latest = record?.latest ?? null;
20
- const range = config.items?.[name] ?? null;
21
- let wanted = latest;
22
- if (release && isSystemItem(name)) wanted = pins.get(name) ?? null;
23
- else if (range) wanted = semver.maxSatisfying(liveVersions(record), range);
24
- out.push({ name, current: entry.version, wanted, latest, requested: entry.requested });
25
- }
26
- return { items: out, release: newest };
27
- }
28
-
29
- const above = (v, current) => v !== null && semver.gt(v, current);
30
-
31
- // The entries above from and at or below to, newest first.
32
- export async function entriesBetween(client, name, from, to) {
33
- const answer = await client.changelog(name, from);
34
- return (answer?.versions ?? [])
35
- .filter((v) => semver.gt(v.version, from) && semver.lte(v.version, to))
36
- .map((v) => ({ version: v.version, yanked: v.yankedAt !== null, summary: v.changelog?.summary ?? null, entry: v.changelog?.entry ?? null, source: v.changelog?.source ?? null }));
37
- }
38
-
39
- const indented = (text) => text.split('\n').map((line) => (line ? ` ${line}` : '')).join('\n');
40
-
41
- export function logEntries(io, name, entries) {
42
- for (const e of entries) {
43
- io.log(` ${name} ${e.version}${e.yanked ? ', yanked' : ''}${e.source === 'generated' ? ', generated' : ''}`);
44
- if (e.summary) io.log(indented(e.summary));
45
- if (e.entry) io.log(indented(e.entry));
46
- if (!e.summary && !e.entry) io.log(' No changelog entry.');
47
- }
48
- }
49
-
50
- export const command = {
51
- synopsis: 'outdated',
52
- summary: 'list installed items with newer versions',
53
- usage: ['ca-ds outdated [--token <token>]'],
54
- options: { ...TOKEN },
55
- async run({ values, positionals, io, collection, env, fetch }) {
56
- if (positionals.length) throw usageError('ca-ds outdated takes no arguments.');
57
- const c = collection();
58
- const release = c.config.release ?? null;
59
- const client = Object.keys(c.lock.items).length ? connect(c, { values, env, fetch }) : null;
60
- const items = client ? await targets(c, client) : { items: [], release: null };
61
- const listed = items.items.filter((i) => above(i.wanted, i.current) || above(i.latest, i.current));
62
- for (const i of listed) i.changelog = await entriesBetween(client, i.name, i.current, [i.wanted, i.latest].filter(Boolean).sort(semver.rcompare)[0]);
63
- if (release) io.log(`Against the latest release, ${items.release.tag}. collection.json names ${release}.`);
64
- if (!listed.length) io.log('Every installed item is current.');
65
- else {
66
- const rows = [['name', 'current', 'wanted', 'latest'], ...listed.map((i) => [i.name, i.current, i.wanted ?? '-', i.latest ?? '-'])];
67
- const widths = rows[0].map((_, col) => Math.max(...rows.map((r) => r[col].length)));
68
- for (const r of rows) io.log(r.map((cell, col) => cell.padEnd(widths[col])).join(' ').trimEnd());
69
- if (listed.some((i) => i.changelog.length)) io.log('\nChanges since each installed version, newest first:');
70
- for (const i of listed) logEntries(io, i.name, i.changelog);
71
- }
72
- return { result: { release, latestRelease: items.release?.tag ?? null, items: listed } };
73
- },
74
- };
package/src/cli/pack.js DELETED
@@ -1,75 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
- import { join, relative, resolve as resolvePath, sep } from 'node:path';
3
- import { loadContext, itemAt } from '../validate/index.js';
4
- import { packItem, packRelease, ReleaseError } from '../lib/release.js';
5
- import { CliError, EXIT, usageError } from './exit.js';
6
- import { argPath } from './items.js';
7
-
8
- const where = (f) => [f.file, f.line].filter((x) => x != null).join(':');
9
- const rel = (root, p) => {
10
- const r = relative(root, p);
11
- return r.startsWith('..') ? p : r.split(sep).join('/');
12
- };
13
-
14
- function printRejections(io, result) {
15
- io.warn(`rejected ${result.name ?? '(unnamed)'} ${result.dir}`);
16
- for (const f of result.rejections) io.warn(` ${f.check}/${f.rule} ${where(f)} ${f.message}`);
17
- }
18
-
19
- async function release(c, values, io) {
20
- try {
21
- const out = values.out === undefined ? null : resolvePath(values.out);
22
- const { tag, dir, manifest, results, rejected } = await packRelease({ root: c.root, tag: values.tag ?? null, out });
23
- const warnings = results.reduce((n, r) => n + r.warnings.length, 0);
24
- if (!dir) {
25
- rejected.forEach((r) => printRejections(io, r));
26
- io.warn(`packed nothing: ${rejected.length} items rejected`);
27
- return { exit: EXIT.rejected, result: { tag, dir: null, items: 0, warnings, rejected } };
28
- }
29
- io.log(`packed release ${tag} ${rel(c.root, dir)} ${manifest.items.length} items, ${warnings} warnings`);
30
- return { result: { tag, dir: rel(c.root, dir), items: manifest.items.length, warnings, rejected: [] } };
31
- } catch (err) {
32
- if (err instanceof ReleaseError) throw new CliError(err.message, EXIT.rejected);
33
- throw err;
34
- }
35
- }
36
-
37
- export const command = {
38
- synopsis: 'pack [name...]',
39
- summary: 'write item ZIPs, with --release',
40
- usage: ['ca-ds pack [<name or folder> ...] [--out <folder>]', 'ca-ds pack --release [--tag v<semver>] [--out <folder>]'],
41
- options: { out: { type: 'string' }, release: { type: 'boolean' }, tag: { type: 'string' } },
42
- async run({ values, positionals, io, collection }) {
43
- const c = collection();
44
- if (values.release) {
45
- if (positionals.length) throw usageError('--release packs every item. Name no item with it.');
46
- return release(c, values, io);
47
- }
48
- if (values.tag !== undefined) throw usageError('--tag names a release. Use it with --release.');
49
- const out = values.out === undefined ? join(c.root, 'build/pack') : resolvePath(values.out);
50
- const ctx = await loadContext(c);
51
- const targets = positionals.length
52
- ? positionals.map((arg) => {
53
- const abs = argPath(c, arg);
54
- if (!existsSync(abs)) throw usageError(`${arg} is no item in the collection and no folder.`);
55
- return itemAt(ctx, abs, arg);
56
- })
57
- : c.items.filter((i) => i.authored !== false).map((i) => itemAt(ctx, join(c.root, i.dir)));
58
- const packed = [];
59
- const rejected = [];
60
- for (const item of targets) {
61
- const { result, file, bytes, count } = await packItem(item, ctx);
62
- if (!file) {
63
- printRejections(io, result);
64
- rejected.push(result);
65
- continue;
66
- }
67
- mkdirSync(out, { recursive: true });
68
- writeFileSync(join(out, file), bytes);
69
- const path = rel(c.root, join(out, file));
70
- io.log(`packed ${result.name} ${path} ${count} files, ${result.warnings.length} warnings`);
71
- packed.push({ name: result.name, version: item.manifest.version, file: path, files: count, warnings: result.warnings.length });
72
- }
73
- return { exit: rejected.length ? EXIT.rejected : EXIT.ok, result: { packed, rejected } };
74
- },
75
- };
@@ -1,31 +0,0 @@
1
- import { relative, sep } from 'node:path';
2
- import { usageError } from './exit.js';
3
-
4
- export const command = {
5
- synopsis: 'preview',
6
- summary: 'serve items and pages with live reload, with --screenshots',
7
- usage: ['ca-ds preview [--port <n>] [--open | --no-open]', 'ca-ds preview --screenshots [<scoped name> ...]'],
8
- options: {
9
- port: { type: 'string' },
10
- open: { type: 'boolean' },
11
- 'no-open': { type: 'boolean' },
12
- screenshots: { type: 'boolean' },
13
- },
14
- async run({ values, positionals, io, collection }) {
15
- const c = collection();
16
- if (values.screenshots) {
17
- const { screenshots } = await import('../preview/screenshots.js');
18
- const shots = await screenshots(c, { names: positionals, log: io.log });
19
- const written = shots.map((s) => ({ name: s.name, theme: s.theme, file: relative(c.root, s.out).split(sep).join('/') }));
20
- return { result: { written } };
21
- }
22
- if (positionals.length) throw usageError('ca-ds preview takes item names with --screenshots alone.');
23
- const named = values.port ?? process.env.PORT;
24
- const port = named === undefined ? 3000 : Number(named);
25
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw usageError(`The port ${named} is not a port number.`);
26
- const { startPreview } = await import('../preview/server.js');
27
- const openBrowser = values['no-open'] ? false : values.open ? true : io.json ? false : null;
28
- const { url, running } = await startPreview({ root: c.root, port, explicit: named !== undefined, openBrowser, log: io.log });
29
- return { result: { url, running } };
30
- },
31
- };