@cagov/ca-ds 1.0.0 → 1.2.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.
- package/README.md +43 -26
- package/THIRD-PARTY-LICENSES.txt +690 -0
- package/ca-ds.js +48390 -0
- package/package.json +5 -31
- package/bin/ca-ds.js +0 -5
- package/src/cli/add.js +0 -134
- package/src/cli/build.js +0 -15
- package/src/cli/diff.js +0 -39
- package/src/cli/eject.js +0 -112
- package/src/cli/exit.js +0 -22
- package/src/cli/format.js +0 -52
- package/src/cli/init.js +0 -148
- package/src/cli/install.js +0 -178
- package/src/cli/items.js +0 -10
- package/src/cli/login.js +0 -331
- package/src/cli/main.js +0 -108
- package/src/cli/new.js +0 -230
- package/src/cli/outdated.js +0 -74
- package/src/cli/pack.js +0 -75
- package/src/cli/preview.js +0 -31
- package/src/cli/publish.js +0 -295
- package/src/cli/pull.js +0 -208
- package/src/cli/remote.js +0 -52
- package/src/cli/remove.js +0 -69
- package/src/cli/update.js +0 -223
- package/src/cli/validate.js +0 -131
- package/src/lib/browser.js +0 -12
- package/src/lib/build.js +0 -249
- package/src/lib/bundle.js +0 -148
- package/src/lib/catalog.js +0 -44
- package/src/lib/checks.js +0 -31
- package/src/lib/collection.js +0 -65
- package/src/lib/emblem.js +0 -29
- package/src/lib/fixtures.js +0 -59
- package/src/lib/floor.js +0 -79
- package/src/lib/glyph.js +0 -148
- package/src/lib/image.js +0 -138
- package/src/lib/json-text.js +0 -213
- package/src/lib/keys.js +0 -322
- package/src/lib/links.js +0 -321
- package/src/lib/markdown.js +0 -408
- package/src/lib/merge.js +0 -93
- package/src/lib/pack.js +0 -30
- package/src/lib/page-schema.js +0 -368
- package/src/lib/page.js +0 -372
- package/src/lib/patch.js +0 -9
- package/src/lib/regions.js +0 -173
- package/src/lib/registry.js +0 -371
- package/src/lib/release.js +0 -119
- package/src/lib/repoints.js +0 -120
- package/src/lib/resolve.js +0 -32
- package/src/lib/schema.js +0 -28
- package/src/lib/serial.js +0 -4
- package/src/lib/serialize.js +0 -444
- package/src/lib/structured.js +0 -72
- package/src/lib/system.js +0 -13
- package/src/lib/targets.js +0 -85
- package/src/lib/terms.js +0 -11
- package/src/lib/token-view.js +0 -289
- package/src/lib/tokens.js +0 -247
- package/src/lib/version.js +0 -34
- package/src/preview/frame.js +0 -75
- package/src/preview/pages.js +0 -128
- package/src/preview/screenshots.js +0 -72
- package/src/preview/server.js +0 -378
- package/src/preview/shell.js +0 -153
- package/src/schema/a11y.schema.json +0 -56
- package/src/schema/collection.lock.schema.json +0 -58
- package/src/schema/collection.schema.json +0 -65
- package/src/schema/composition.schema.json +0 -98
- package/src/schema/contract.schema.json +0 -116
- package/src/schema/interface.schema.json +0 -257
- package/src/schema/item.schema.json +0 -362
- package/src/schema/release.schema.json +0 -39
- package/src/schema/system.schema.json +0 -75
- package/src/schema/variants.schema.json +0 -60
- package/src/validate/collection.js +0 -19
- package/src/validate/collisions.js +0 -124
- package/src/validate/context.js +0 -357
- package/src/validate/facts.js +0 -253
- package/src/validate/files.js +0 -103
- package/src/validate/findings.js +0 -19
- package/src/validate/glyphs.js +0 -126
- package/src/validate/html.js +0 -215
- package/src/validate/imports.js +0 -29
- package/src/validate/index.js +0 -75
- package/src/validate/item.js +0 -47
- package/src/validate/links.js +0 -113
- package/src/validate/manifest.js +0 -147
- package/src/validate/media.js +0 -65
- package/src/validate/page.js +0 -74
- package/src/validate/prefixes.js +0 -58
- package/src/validate/relations.js +0 -310
- package/src/validate/release.js +0 -109
- package/src/validate/skill.js +0 -122
- package/src/validate/structured.js +0 -335
- package/src/validate/tasc.js +0 -80
- package/src/validate/template.js +0 -129
- package/src/validate/tokens.js +0 -154
- package/src/validate/zip.js +0 -40
- /package/{src/preview/preview.css → preview.css} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cagov/ca-ds",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "The California Design System's toolbelt: validate, build, pack, preview, and publish a collection of items",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -18,22 +18,14 @@
|
|
|
18
18
|
"node": ">=24"
|
|
19
19
|
},
|
|
20
20
|
"bin": {
|
|
21
|
-
"ca-ds": "
|
|
21
|
+
"ca-ds": "ca-ds.js"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
|
-
"./lib/*": "./src/lib/*",
|
|
25
|
-
"./validate/*": "./src/validate/*",
|
|
26
|
-
"./schema/*": "./src/schema/*",
|
|
27
|
-
"./preview/*": "./src/preview/*",
|
|
28
|
-
"./cli/*": "./src/cli/*",
|
|
29
24
|
"./package.json": "./package.json"
|
|
30
25
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
],
|
|
35
|
-
"scripts": {
|
|
36
|
-
"test": "node --test \"test/**/*.test.js\""
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"esbuild": "0.28.1",
|
|
28
|
+
"lightningcss": "1.32.0"
|
|
37
29
|
},
|
|
38
30
|
"peerDependencies": {
|
|
39
31
|
"playwright-core": "^1.64.1"
|
|
@@ -42,23 +34,5 @@
|
|
|
42
34
|
"playwright-core": {
|
|
43
35
|
"optional": true
|
|
44
36
|
}
|
|
45
|
-
},
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"ajv": "^8.20.0",
|
|
48
|
-
"css-select": "^7.0.0",
|
|
49
|
-
"diff": "^9.0.0",
|
|
50
|
-
"domhandler": "^6.0.1",
|
|
51
|
-
"esbuild": "^0.28.1",
|
|
52
|
-
"fflate": "^0.8.3",
|
|
53
|
-
"lightningcss": "^1.32.0",
|
|
54
|
-
"markdown-it": "^15.0.3",
|
|
55
|
-
"node-diff3": "^3.2.1",
|
|
56
|
-
"parse5": "^8.0.1",
|
|
57
|
-
"parse5-htmlparser2-tree-adapter": "^8.0.1",
|
|
58
|
-
"prosemirror-markdown": "^1.13.9",
|
|
59
|
-
"prosemirror-model": "^1.25.12",
|
|
60
|
-
"semver": "^7.8.5",
|
|
61
|
-
"style-dictionary": "^4.4.0",
|
|
62
|
-
"yaml": "^2.9.1"
|
|
63
37
|
}
|
|
64
38
|
}
|
package/bin/ca-ds.js
DELETED
package/src/cli/add.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import semver from 'semver';
|
|
4
|
-
import { shipsScripts } from '../lib/serialize.js';
|
|
5
|
-
import { isSystemItem } from '../lib/system.js';
|
|
6
|
-
import { CliError, EXIT, usageError } from './exit.js';
|
|
7
|
-
import { baselineOf, installedSkills, installPath, linkClash, linkSkill, parseSpec, rootsOf, saveRoots, scopeOf, skillNameOf, skillPath, writeFiles } from './install.js';
|
|
8
|
-
import { connect, TOKEN } from './remote.js';
|
|
9
|
-
|
|
10
|
-
export const liveVersions = (record) => (record?.versions ?? []).filter((v) => !v.yankedAt).map((v) => v.version);
|
|
11
|
-
|
|
12
|
-
export async function highestIn(client, name, range) {
|
|
13
|
-
const record = await client.item(name);
|
|
14
|
-
if (!record) throw new CliError(`The registry at ${client.url} holds no live version of ${name}.`, EXIT.registry);
|
|
15
|
-
const live = liveVersions(record);
|
|
16
|
-
const best = semver.maxSatisfying(live, range);
|
|
17
|
-
if (!best) throw new CliError(`No live version of ${name} satisfies ${range}. The registry holds ${live.join(', ')}.`);
|
|
18
|
-
return best;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// A resolve names these too, so the set keeps what authored items need.
|
|
22
|
-
export function authoredDependencies(collection) {
|
|
23
|
-
const names = new Set();
|
|
24
|
-
for (const item of collection.items) {
|
|
25
|
-
if (!item.authored) continue;
|
|
26
|
-
for (const dep of Object.keys(item.manifest.dependencies ?? {})) if (Object.hasOwn(collection.lock.items, dep)) names.add(dep);
|
|
27
|
-
}
|
|
28
|
-
return [...names];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function forks(collection) {
|
|
32
|
-
return new Map(collection.items.filter((i) => i.authored && typeof i.manifest.forkedFrom === 'string').map((i) => [i.manifest.forkedFrom.slice(0, i.manifest.forkedFrom.lastIndexOf('@')), i.manifest.name]));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const manifestOf = (files) => JSON.parse(new TextDecoder().decode(files.get('item.json')));
|
|
36
|
-
|
|
37
|
-
export async function fetchFresh(collection, client, config, fresh, taken = installedSkills(collection)) {
|
|
38
|
-
const forked = forks(collection);
|
|
39
|
-
const out = [];
|
|
40
|
-
for (const { name, version } of fresh) {
|
|
41
|
-
if (forked.has(name)) throw new CliError(`The set needs ${name}, which ${forked.get(name)} forks, and a collection holding both is a rejection. Point what needs it at ${forked.get(name)}.`, EXIT.conflict);
|
|
42
|
-
const { record, files } = await client.files(name, version);
|
|
43
|
-
const manifest = manifestOf(files);
|
|
44
|
-
const skill = manifest.kind === 'skill';
|
|
45
|
-
let path = installPath(config, name);
|
|
46
|
-
if (skill) {
|
|
47
|
-
const skillName = skillNameOf(files.get(manifest.doc)) ?? name.slice(name.indexOf('/') + 1);
|
|
48
|
-
if (taken.has(skillName)) throw new CliError(`${name} installs as the skill ${skillName}, the name ${taken.get(skillName)} already installs as. An agent loads a skill by that name, so a collection holds one of them.`, EXIT.conflict);
|
|
49
|
-
taken.set(skillName, name);
|
|
50
|
-
path = skillPath(config, skillName);
|
|
51
|
-
}
|
|
52
|
-
const abs = join(collection.root, path);
|
|
53
|
-
if (existsSync(abs) && readdirSync(abs).length) throw new CliError(`${path} already holds files, so ${name} can't install there. Move them, or set ${skill ? 'skills' : 'install'} in collection.json.`, EXIT.conflict);
|
|
54
|
-
const clash = skill ? linkClash(collection.root, config, path) : null;
|
|
55
|
-
if (clash) throw new CliError(`${clash} already holds a skill, so ${name} can't link it there. Move it, or set skills in collection.json.`, EXIT.conflict);
|
|
56
|
-
out.push({ name, version, path, files, baseline: baselineOf(record), skill, scripts: skill && shipsScripts(manifest.files ?? []) });
|
|
57
|
-
}
|
|
58
|
-
return out;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const lockEntry = (f, requested) => ({ version: f.version, path: f.path, requested, ...(f.skill ? { links: f.links } : {}), files: f.baseline });
|
|
62
|
-
|
|
63
|
-
export const scriptsWarning = (name, path) => ({ rule: 'skill-scripts', name, message: `${name} ships scripts an agent may run. Review them, in ${path}/scripts, before you run them.` });
|
|
64
|
-
|
|
65
|
-
// Writes each fetched item, links each skill, and answers the warnings.
|
|
66
|
-
export function placeFresh(collection, config, fetched) {
|
|
67
|
-
const warnings = [];
|
|
68
|
-
for (const f of fetched) {
|
|
69
|
-
writeFiles(join(collection.root, f.path), f.files);
|
|
70
|
-
if (!f.skill) continue;
|
|
71
|
-
f.links = linkSkill(collection.root, config, f.path);
|
|
72
|
-
if (f.scripts) warnings.push(scriptsWarning(f.name, f.path));
|
|
73
|
-
}
|
|
74
|
-
return warnings;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const command = {
|
|
78
|
-
synopsis: 'add <name>[@range]...',
|
|
79
|
-
summary: 'install items and their dependencies',
|
|
80
|
-
usage: ['ca-ds add <scope>/<name>[@<range>]... [--token <token>]'],
|
|
81
|
-
options: { ...TOKEN },
|
|
82
|
-
async run({ values, positionals, io, collection, env, fetch }) {
|
|
83
|
-
if (!positionals.length) throw usageError('Name an item to add, as <scope>/<name>.');
|
|
84
|
-
const c = collection();
|
|
85
|
-
const specs = positionals.map(parseSpec);
|
|
86
|
-
const namespaces = new Set(c.config.namespaces ?? []);
|
|
87
|
-
for (const { name } of specs) {
|
|
88
|
-
if (namespaces.has(scopeOf(name))) throw usageError(`${name} is in ${scopeOf(name)}, a namespace this collection authors, so it is never installed here.`);
|
|
89
|
-
}
|
|
90
|
-
const client = connect(c, { values, env, fetch });
|
|
91
|
-
const { config, lock } = rootsOf(c);
|
|
92
|
-
const release = config.release ?? null;
|
|
93
|
-
|
|
94
|
-
const asked = new Map(Object.entries(config.items ?? {}));
|
|
95
|
-
for (const { name, range } of specs) asked.set(name, range ?? asked.get(name) ?? null);
|
|
96
|
-
const versions = Object.fromEntries(Object.entries(lock.items).map(([name, entry]) => [name, entry.version]));
|
|
97
|
-
for (const [name, range] of asked) {
|
|
98
|
-
if (range === null || Object.hasOwn(versions, name) || (release && isSystemItem(name))) continue;
|
|
99
|
-
versions[name] = await highestIn(client, name, range);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const answer = await client.resolve({ items: [...new Set([...asked.keys(), ...authoredDependencies(c)])], release, versions });
|
|
103
|
-
const resolved = new Map(answer.items.map((i) => [i.name, i.version]));
|
|
104
|
-
for (const [name, range] of asked) {
|
|
105
|
-
const version = resolved.get(name);
|
|
106
|
-
if (range === null || semver.satisfies(version, range)) continue;
|
|
107
|
-
const why = lock.items[name] ? `it's installed at ${version}. ca-ds update moves it` : `the release ${release} pins ${version}`;
|
|
108
|
-
throw new CliError(`${name} is asked for at ${range}, and ${why}.`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const authored = new Set(c.items.filter((i) => i.authored).map((i) => i.manifest.name));
|
|
112
|
-
const fresh = answer.items.filter((i) => !lock.items[i.name] && !authored.has(i.name));
|
|
113
|
-
const fetched = await fetchFresh(c, client, config, fresh);
|
|
114
|
-
const warnings = placeFresh(c, config, fetched);
|
|
115
|
-
|
|
116
|
-
for (const f of fetched) lock.items[f.name] = lockEntry(f, asked.has(f.name));
|
|
117
|
-
config.items = { ...config.items };
|
|
118
|
-
for (const { name } of specs) {
|
|
119
|
-
lock.items[name].requested = true;
|
|
120
|
-
config.items[name] = asked.get(name) ?? `^${resolved.get(name)}`;
|
|
121
|
-
}
|
|
122
|
-
lock.release = release;
|
|
123
|
-
if (Array.isArray(answer.foundation)) lock.foundation = answer.foundation;
|
|
124
|
-
saveRoots(c, { config, lock });
|
|
125
|
-
|
|
126
|
-
const added = fetched.map((f) => ({ name: f.name, version: f.version, path: f.path, requested: asked.has(f.name), ...(f.skill ? { links: f.links } : {}) }));
|
|
127
|
-
for (const a of added) io.log(`added ${a.name} ${a.version} at ${a.path}${a.links?.length ? `, linked from ${a.links.join(', ')}` : ''}${a.requested ? '' : ', a dependency'}`);
|
|
128
|
-
const requested = specs.map(({ name }) => ({ name, range: config.items[name], version: resolved.get(name) }));
|
|
129
|
-
for (const r of requested) if (!added.some((a) => a.name === r.name)) io.log(`installed ${r.name} ${r.version}, asked for at ${r.range}`);
|
|
130
|
-
io.log(`${added.length} added${release ? `, against the release ${release}` : ''}`);
|
|
131
|
-
for (const w of warnings) io.warn(`warning: ${w.message}`);
|
|
132
|
-
return { result: { release, added, requested, warnings } };
|
|
133
|
-
},
|
|
134
|
-
};
|
package/src/cli/build.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { buildDist } from '../lib/build.js';
|
|
2
|
-
|
|
3
|
-
export const command = {
|
|
4
|
-
synopsis: 'build',
|
|
5
|
-
summary: 'write tokens, CSS, and JS to dist/, with --preset',
|
|
6
|
-
usage: ['ca-ds build [--preset <name>]'],
|
|
7
|
-
options: { preset: { type: 'string' } },
|
|
8
|
-
async run({ values, positionals, io, collection }) {
|
|
9
|
-
if (positionals.length) throw Object.assign(new Error('ca-ds build takes no arguments. Name a preset with --preset.'), { usage: true });
|
|
10
|
-
const result = await buildDist(collection(), { preset: values.preset ?? null });
|
|
11
|
-
for (const w of result.warnings) io.warn(`warning: ${w.message}`);
|
|
12
|
-
io.log(`Built ${result.from}, ${result.order.length} items, into ${result.dist}/: ${result.files.length} files`);
|
|
13
|
-
return { result };
|
|
14
|
-
},
|
|
15
|
-
};
|
package/src/cli/diff.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { isBinary } from '../lib/merge.js';
|
|
3
|
-
import { patchOf } from '../lib/patch.js';
|
|
4
|
-
import { usageError } from './exit.js';
|
|
5
|
-
import { hashesOf, localFiles, parseSpec } from './install.js';
|
|
6
|
-
import { connect, TOKEN } from './remote.js';
|
|
7
|
-
|
|
8
|
-
export const command = {
|
|
9
|
-
synopsis: 'diff <name>',
|
|
10
|
-
summary: 'show local edits against the installed version',
|
|
11
|
-
usage: ['ca-ds diff <scope>/<name> [--token <token>]'],
|
|
12
|
-
options: { ...TOKEN },
|
|
13
|
-
async run({ values, positionals, io, collection, env, fetch }) {
|
|
14
|
-
if (positionals.length !== 1) throw usageError('Name one installed item.');
|
|
15
|
-
const { name, range } = parseSpec(positionals[0]);
|
|
16
|
-
if (range !== null) throw usageError(`diff takes a name, with no range: ${name}.`);
|
|
17
|
-
const c = collection();
|
|
18
|
-
const entry = c.lock.items[name];
|
|
19
|
-
if (!entry) throw usageError(`${name} is not installed, so it has no baseline.`);
|
|
20
|
-
|
|
21
|
-
const local = localFiles(join(c.root, entry.path));
|
|
22
|
-
const ours = hashesOf(local);
|
|
23
|
-
const paths = [...new Set([...Object.keys(entry.files), ...Object.keys(ours)])].sort();
|
|
24
|
-
const changed = paths.filter((p) => entry.files[p] !== ours[p]);
|
|
25
|
-
const client = changed.length ? connect(c, { values, env, fetch }) : null;
|
|
26
|
-
const files = [];
|
|
27
|
-
for (const path of changed) {
|
|
28
|
-
const before = entry.files[path] ? await client.file(name, entry.version, path, entry.files[path]) : null;
|
|
29
|
-
const after = local.get(path) ?? null;
|
|
30
|
-
const status = before === null ? 'added' : after === null ? 'deleted' : 'modified';
|
|
31
|
-
const binary = [before, after].some((b) => b !== null && isBinary(b));
|
|
32
|
-
files.push({ path, status, binary, patch: binary ? null : patchOf(`${entry.path}/${path}`, before, after) });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!files.length) io.log(`${name} ${entry.version} has no local edits.`);
|
|
36
|
-
for (const f of files) io.log(f.binary ? `Binary file ${entry.path}/${f.path} ${f.status}` : f.patch.trimEnd());
|
|
37
|
-
return { result: { name, version: entry.version, path: entry.path, edited: files.length > 0, files } };
|
|
38
|
-
},
|
|
39
|
-
};
|
package/src/cli/eject.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
4
|
-
import { CliError, EXIT, usageError } from './exit.js';
|
|
5
|
-
import { installPath, parseSpec, pruneEmpty, rootsOf, saveRoots, scopeOf, unlinkSkill } from './install.js';
|
|
6
|
-
|
|
7
|
-
const NAMESPACE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
8
|
-
const VERSION = '0.1.0';
|
|
9
|
-
|
|
10
|
-
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
11
|
-
|
|
12
|
-
// Patches keep the file's bytes; when they miss value, it's rewritten whole at text's indent.
|
|
13
|
-
export function rewriteJson(text, value, patches) {
|
|
14
|
-
let out = text;
|
|
15
|
-
for (const [pattern, replacement] of patches) out = out.replace(pattern, replacement);
|
|
16
|
-
try {
|
|
17
|
-
if (isDeepStrictEqual(JSON.parse(out), value)) return out;
|
|
18
|
-
} catch {
|
|
19
|
-
// Falls through to a whole rewrite.
|
|
20
|
-
}
|
|
21
|
-
const indent = /^([ \t]+)\S/m.exec(text)?.[1] ?? 2;
|
|
22
|
-
return `${JSON.stringify(value, null, indent)}\n`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function renamed(manifest, from, to, range) {
|
|
26
|
-
const out = structuredClone(manifest);
|
|
27
|
-
if (out.dependencies && Object.hasOwn(out.dependencies, from)) {
|
|
28
|
-
out.dependencies = Object.fromEntries(Object.entries(out.dependencies).map(([k, v]) => (k === from ? [to, range] : [k, v])));
|
|
29
|
-
}
|
|
30
|
-
for (const r of out.related ?? []) for (const load of r.load ?? []) if (load.item === from) load.item = to;
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const command = {
|
|
35
|
-
synopsis: 'eject <name> --to <namespace>',
|
|
36
|
-
summary: 'turn an installed item into an authored one',
|
|
37
|
-
usage: ['ca-ds eject <scope>/<name> --to <namespace>'],
|
|
38
|
-
options: { to: { type: 'string' } },
|
|
39
|
-
async run({ values, positionals, io, collection }) {
|
|
40
|
-
if (positionals.length !== 1) throw usageError('Name one installed item.');
|
|
41
|
-
const ns = values.to;
|
|
42
|
-
if (!ns || !NAMESPACE.test(ns)) throw usageError('Name the namespace it moves to with --to, such as --to myteam.');
|
|
43
|
-
const { name, range } = parseSpec(positionals[0]);
|
|
44
|
-
if (range !== null) throw usageError(`eject takes a name, with no range: ${name}.`);
|
|
45
|
-
const c = collection();
|
|
46
|
-
const { config, lock } = rootsOf(c);
|
|
47
|
-
const entry = lock.items[name];
|
|
48
|
-
if (!entry) throw usageError(c.items.some((i) => i.authored && i.manifest.name === name) ? `${name} is already authored here.` : `${name} is not installed.`);
|
|
49
|
-
if (ns === scopeOf(name)) throw usageError(`${name} is already in ${ns}. Name another namespace.`);
|
|
50
|
-
const namespaces = config.namespaces ?? [];
|
|
51
|
-
const namespaceAdded = !namespaces.includes(ns);
|
|
52
|
-
if (namespaceAdded) {
|
|
53
|
-
const clash = Object.keys(lock.items).filter((n) => scopeOf(n) === ns);
|
|
54
|
-
if (clash.length) throw usageError(`${clash.join(', ')} ${clash.length === 1 ? 'is' : 'are'} installed in ${ns}, so the collection can't author ${ns}.`);
|
|
55
|
-
}
|
|
56
|
-
const fork = `${ns}/${name.slice(name.indexOf('/') + 1)}`;
|
|
57
|
-
if (c.items.some((i) => i.manifest.name === fork)) throw new CliError(`The collection already holds ${fork}.`, EXIT.conflict);
|
|
58
|
-
const path = installPath(config, fork);
|
|
59
|
-
const target = join(c.root, path);
|
|
60
|
-
if (existsSync(target)) throw new CliError(`${path} already exists, so ${name} can't move there.`, EXIT.conflict);
|
|
61
|
-
|
|
62
|
-
const source = join(c.root, entry.path);
|
|
63
|
-
const file = join(source, 'item.json');
|
|
64
|
-
const text = readFileSync(file, 'utf8');
|
|
65
|
-
const manifest = JSON.parse(text);
|
|
66
|
-
const forkedFrom = `${name}@${entry.version}`;
|
|
67
|
-
const next = { ...renamed(manifest, name, fork, `^${VERSION}`), name: fork, version: VERSION, forkedFrom, source: path };
|
|
68
|
-
const keys = Object.keys(manifest);
|
|
69
|
-
if (!keys.includes('forkedFrom')) keys.splice(keys.indexOf('version') + 1, 0, 'forkedFrom');
|
|
70
|
-
const field = (key) => new RegExp(`("${key}"\\s*:\\s*")[^"\\\\]*(")`);
|
|
71
|
-
const own = rewriteJson(text, Object.fromEntries(keys.map((k) => [k, next[k]])), [
|
|
72
|
-
[field('name'), `$1${fork}$2`],
|
|
73
|
-
[field('source'), `$1${path}$2`],
|
|
74
|
-
Object.hasOwn(manifest, 'forkedFrom')
|
|
75
|
-
? [field('forkedFrom'), `$1${forkedFrom}$2`]
|
|
76
|
-
: [/^([ \t]*)"version"(\s*:\s*)"[^"\\]*"/m, `$1"version"$2"${VERSION}",\n$1"forkedFrom"$2"${forkedFrom}"`],
|
|
77
|
-
[field('version'), `$1${VERSION}$2`],
|
|
78
|
-
]);
|
|
79
|
-
|
|
80
|
-
const depPattern = new RegExp(`"${escape(name)}"(\\s*:\\s*)"[^"\\\\]*"`, 'g');
|
|
81
|
-
const loadPattern = new RegExp(`("item"\\s*:\\s*)"${escape(name)}"`, 'g');
|
|
82
|
-
const edits = [];
|
|
83
|
-
for (const item of c.items) {
|
|
84
|
-
if (!item.manifest || item.manifest.name === name) continue;
|
|
85
|
-
const changed = renamed(item.manifest, name, fork, `^${VERSION}`);
|
|
86
|
-
if (isDeepStrictEqual(changed, item.manifest)) continue;
|
|
87
|
-
const at = join(c.root, item.dir, 'item.json');
|
|
88
|
-
edits.push({ name: item.manifest.name, file: at, text: rewriteJson(readFileSync(at, 'utf8'), changed, [[depPattern, `"${fork}"$1"^${VERSION}"`], [loadPattern, `$1"${fork}"`]]) });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// An authored skill is never linked into the skills folders.
|
|
92
|
-
const warnings = unlinkSkill(c.root, entry.links, entry.path, name);
|
|
93
|
-
writeFileSync(file, own);
|
|
94
|
-
mkdirSync(dirname(target), { recursive: true });
|
|
95
|
-
renameSync(source, target);
|
|
96
|
-
pruneEmpty(dirname(source), c.root);
|
|
97
|
-
for (const e of edits) writeFileSync(e.file, e.text);
|
|
98
|
-
|
|
99
|
-
delete lock.items[name];
|
|
100
|
-
if (config.items) delete config.items[name];
|
|
101
|
-
if (lock.foundation) lock.foundation = lock.foundation.map((n) => (n === name ? fork : n));
|
|
102
|
-
if (namespaceAdded) config.namespaces = [...namespaces, ns];
|
|
103
|
-
saveRoots(c, { config, lock });
|
|
104
|
-
|
|
105
|
-
const rewritten = edits.map((e) => e.name).sort();
|
|
106
|
-
io.log(`ejected ${forkedFrom} as ${fork} ${VERSION} at ${path}`);
|
|
107
|
-
for (const r of rewritten) io.log(`rewrote ${r}'s item.json to name ${fork}`);
|
|
108
|
-
if (namespaceAdded) io.log(`namespace ${ns} added to collection.json`);
|
|
109
|
-
for (const w of warnings) io.warn(`warning: ${w.message}`);
|
|
110
|
-
return { result: { from: forkedFrom, name: fork, version: VERSION, path, rewritten, namespaceAdded, warnings } };
|
|
111
|
-
},
|
|
112
|
-
};
|
package/src/cli/exit.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { RegistryFailure } from '../lib/registry.js';
|
|
2
|
-
|
|
3
|
-
// Stable: scripts and CI steps read these codes.
|
|
4
|
-
export const EXIT = Object.freeze({ ok: 0, rejected: 1, usage: 2, conflict: 3, auth: 4, registry: 5 });
|
|
5
|
-
|
|
6
|
-
export const exitName = (code) => Object.keys(EXIT).find((name) => EXIT[name] === code) ?? 'rejected';
|
|
7
|
-
|
|
8
|
-
export class CliError extends Error {
|
|
9
|
-
constructor(message, exit = EXIT.rejected) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.exit = exit;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const usageError = (message) => new CliError(message, EXIT.usage);
|
|
16
|
-
|
|
17
|
-
export function exitOf(err) {
|
|
18
|
-
if (err instanceof CliError) return err.exit;
|
|
19
|
-
if (err instanceof RegistryFailure) return err.auth ? EXIT.auth : EXIT.registry;
|
|
20
|
-
if (err?.usage === true || String(err?.code ?? '').startsWith('ERR_PARSE_ARGS')) return EXIT.usage;
|
|
21
|
-
return EXIT.rejected;
|
|
22
|
-
}
|
package/src/cli/format.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { normalizeMarkdown, firstDifference } from '../lib/markdown.js';
|
|
4
|
-
import { EXIT, CliError, usageError } from './exit.js';
|
|
5
|
-
import { argPath } from './items.js';
|
|
6
|
-
|
|
7
|
-
export const command = {
|
|
8
|
-
synopsis: 'format [name...]',
|
|
9
|
-
summary: "rewrite authored items' markdown in the serializer's form",
|
|
10
|
-
usage: ['ca-ds format [name or folder...] [--check]'],
|
|
11
|
-
options: { check: { type: 'boolean' } },
|
|
12
|
-
async run({ values, positionals, io, collection }) {
|
|
13
|
-
const c = collection();
|
|
14
|
-
let items = c.items.filter((i) => i.authored !== false && !i.installed && i.manifest);
|
|
15
|
-
if (positionals.length > 0) {
|
|
16
|
-
items = positionals.map((arg) => {
|
|
17
|
-
const abs = argPath(c, arg);
|
|
18
|
-
const item = c.items.find((i) => join(c.root, i.dir) === abs);
|
|
19
|
-
if (!item?.manifest) throw usageError(`${arg} is no item in the collection.`);
|
|
20
|
-
if (item.installed || item.authored === false) throw usageError(`${item.manifest.name} isn't authored here, so its publisher formats it.`);
|
|
21
|
-
return item;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const files = [];
|
|
25
|
-
for (const item of items) {
|
|
26
|
-
for (const file of item.manifest.files ?? []) {
|
|
27
|
-
if (typeof file?.path !== 'string' || !file.path.endsWith('.md')) continue;
|
|
28
|
-
const abs = join(c.root, item.dir, file.path);
|
|
29
|
-
let text;
|
|
30
|
-
try {
|
|
31
|
-
text = readFileSync(abs, 'utf8');
|
|
32
|
-
} catch {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
let normalized;
|
|
36
|
-
try {
|
|
37
|
-
normalized = normalizeMarkdown(text);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
throw new CliError(`${item.dir}/${file.path} doesn't parse as the docs' markdown: ${err.message}`);
|
|
40
|
-
}
|
|
41
|
-
if (normalized === text) continue;
|
|
42
|
-
files.push({ item: item.manifest.name, path: `${item.dir}/${file.path}`, line: firstDifference(text, normalized).line });
|
|
43
|
-
if (!values.check) writeFileSync(abs, normalized);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const verb = values.check ? 'Would format' : 'Formatted';
|
|
47
|
-
for (const f of files) io.log(`${verb} ${f.path}, from line ${f.line}`);
|
|
48
|
-
if (files.length === 0) io.log('Every markdown file is in the serializer\'s form.');
|
|
49
|
-
else if (!values.check) io.log('Bump each item whose files changed.');
|
|
50
|
-
return { exit: values.check && files.length > 0 ? EXIT.rejected : EXIT.ok, result: { files, written: !values.check && files.length > 0 } };
|
|
51
|
-
},
|
|
52
|
-
};
|
package/src/cli/init.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { COLLECTION } from '../lib/collection.js';
|
|
4
|
-
import { DEFAULT_REGISTRY, registryUrl } from '../lib/registry.js';
|
|
5
|
-
import { validateCollection } from '../lib/schema.js';
|
|
6
|
-
import { PACKAGE, VERSION } from '../lib/version.js';
|
|
7
|
-
import { CliError, EXIT, usageError } from './exit.js';
|
|
8
|
-
|
|
9
|
-
export const WORKFLOW_PATH = '.github/workflows/ca-ds.yml';
|
|
10
|
-
|
|
11
|
-
const BRANCH = /^[A-Za-z0-9._/-]+$/;
|
|
12
|
-
|
|
13
|
-
export function workflow(branch, registry) {
|
|
14
|
-
const npx = `npx --yes ${PACKAGE}@^${VERSION}`;
|
|
15
|
-
return `# Validates the collection and runs the registry's dry run on every pull
|
|
16
|
-
# request, publishes its changed authored items on a push to ${branch}, and
|
|
17
|
-
# pulls the versions the registry minted back to ${branch} hourly on
|
|
18
|
-
# weekdays. ca-ds init --ci github wrote it.
|
|
19
|
-
#
|
|
20
|
-
# Each step runs ${PACKAGE} from npm through npx.
|
|
21
|
-
#
|
|
22
|
-
# The jobs read the CA_DS_TOKEN repository secret, a token whose publish
|
|
23
|
-
# list names the collection's namespaces, from
|
|
24
|
-
# ${registry}/settings/api-keys. Without it, as on a fork's pull request,
|
|
25
|
-
# the dry run skips. A protected ${branch} refuses the pull job's push.
|
|
26
|
-
|
|
27
|
-
name: ca-ds
|
|
28
|
-
|
|
29
|
-
on:
|
|
30
|
-
pull_request:
|
|
31
|
-
push:
|
|
32
|
-
branches: [${branch}]
|
|
33
|
-
schedule:
|
|
34
|
-
- cron: '17 * * * 1-5'
|
|
35
|
-
workflow_dispatch:
|
|
36
|
-
|
|
37
|
-
jobs:
|
|
38
|
-
validate:
|
|
39
|
-
if: github.event_name == 'pull_request'
|
|
40
|
-
runs-on: ubuntu-latest
|
|
41
|
-
steps:
|
|
42
|
-
- uses: actions/checkout@v7
|
|
43
|
-
# The steps install nothing, so nothing caches, even where
|
|
44
|
-
# package.json names a packageManager.
|
|
45
|
-
- uses: actions/setup-node@v7
|
|
46
|
-
with:
|
|
47
|
-
node-version: 24
|
|
48
|
-
package-manager-cache: false
|
|
49
|
-
- run: ${npx} validate
|
|
50
|
-
- if: env.CA_DS_TOKEN != ''
|
|
51
|
-
run: ${npx} publish --dry-run
|
|
52
|
-
env:
|
|
53
|
-
CA_DS_TOKEN: \${{ secrets.CA_DS_TOKEN }}
|
|
54
|
-
|
|
55
|
-
publish:
|
|
56
|
-
if: github.event_name == 'push'
|
|
57
|
-
runs-on: ubuntu-latest
|
|
58
|
-
# One publish at a time, and a publish in flight finishes.
|
|
59
|
-
concurrency:
|
|
60
|
-
group: ca-ds-publish
|
|
61
|
-
cancel-in-progress: false
|
|
62
|
-
steps:
|
|
63
|
-
- uses: actions/checkout@v7
|
|
64
|
-
- uses: actions/setup-node@v7
|
|
65
|
-
with:
|
|
66
|
-
node-version: 24
|
|
67
|
-
package-manager-cache: false
|
|
68
|
-
# The registry records the commit's subject as each version's summary.
|
|
69
|
-
- run: echo "SUBJECT=$(git log -1 --format=%s)" >> "$GITHUB_ENV"
|
|
70
|
-
- run: ${npx} publish --summary "$SUBJECT"
|
|
71
|
-
env:
|
|
72
|
-
CA_DS_TOKEN: \${{ secrets.CA_DS_TOKEN }}
|
|
73
|
-
|
|
74
|
-
# Commits the versions the registry minted straight to ${branch}. A
|
|
75
|
-
# conflict fails the run, committing nothing, for a person to settle with
|
|
76
|
-
# ca-ds pull.
|
|
77
|
-
pull:
|
|
78
|
-
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
|
|
79
|
-
runs-on: ubuntu-latest
|
|
80
|
-
permissions:
|
|
81
|
-
contents: write
|
|
82
|
-
concurrency:
|
|
83
|
-
group: ca-ds-pull
|
|
84
|
-
cancel-in-progress: false
|
|
85
|
-
steps:
|
|
86
|
-
- uses: actions/checkout@v7
|
|
87
|
-
with:
|
|
88
|
-
ref: ${branch}
|
|
89
|
-
- uses: actions/setup-node@v7
|
|
90
|
-
with:
|
|
91
|
-
node-version: 24
|
|
92
|
-
package-manager-cache: false
|
|
93
|
-
- run: ${npx} pull
|
|
94
|
-
env:
|
|
95
|
-
CA_DS_TOKEN: \${{ secrets.CA_DS_TOKEN }}
|
|
96
|
-
- run: |
|
|
97
|
-
if [ -z "$(git status --porcelain)" ]; then exit 0; fi
|
|
98
|
-
git config user.name 'github-actions[bot]'
|
|
99
|
-
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
|
100
|
-
git add -A
|
|
101
|
-
git commit -q -m 'Pull from the registry'
|
|
102
|
-
git push -q origin HEAD:refs/heads/${branch}
|
|
103
|
-
`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const command = {
|
|
107
|
-
synopsis: 'init',
|
|
108
|
-
summary: 'write an empty collection.json, and with --ci github a workflow',
|
|
109
|
-
usage: ['ca-ds init [--registry <url>] [--namespace <namespace> ...] [--ci github] [--branch <branch>]'],
|
|
110
|
-
options: {
|
|
111
|
-
registry: { type: 'string' },
|
|
112
|
-
namespace: { type: 'string', multiple: true },
|
|
113
|
-
ci: { type: 'string' },
|
|
114
|
-
branch: { type: 'string' },
|
|
115
|
-
},
|
|
116
|
-
async run({ values, positionals, io, cwd, env }) {
|
|
117
|
-
if (positionals.length) throw usageError('ca-ds init writes in the working folder, and takes no arguments.');
|
|
118
|
-
if (values.ci !== undefined && values.ci !== 'github') throw usageError(`--ci takes github, the one CI ca-ds writes a workflow for, not ${values.ci}.`);
|
|
119
|
-
if (values.branch !== undefined && values.ci === undefined) throw usageError('--branch names the workflow\'s branch. Use it with --ci github.');
|
|
120
|
-
const branch = values.branch ?? 'main';
|
|
121
|
-
if (!BRANCH.test(branch)) throw usageError(`${branch} is not a branch name.`);
|
|
122
|
-
|
|
123
|
-
const collectionFile = join(cwd, COLLECTION);
|
|
124
|
-
const workflowFile = join(cwd, WORKFLOW_PATH);
|
|
125
|
-
const asks = values.registry !== undefined || values.namespace !== undefined;
|
|
126
|
-
const keep = existsSync(collectionFile);
|
|
127
|
-
if (keep && (asks || values.ci === undefined)) throw new CliError(`${collectionFile} exists already, and ca-ds init leaves it as it is.`, EXIT.conflict);
|
|
128
|
-
if (values.ci !== undefined && existsSync(workflowFile)) throw new CliError(`${workflowFile} exists already, and ca-ds init leaves it as it is.`, EXIT.conflict);
|
|
129
|
-
|
|
130
|
-
const registry = (values.registry ?? env.CA_DS_URL ?? DEFAULT_REGISTRY).replace(/\/+$/, '');
|
|
131
|
-
const config = { registry, namespaces: [...new Set(values.namespace ?? [])] };
|
|
132
|
-
if (!keep && !validateCollection(config)) {
|
|
133
|
-
const errors = validateCollection.errors.map((e) => `${e.instancePath || '(root)'} ${e.message}`);
|
|
134
|
-
throw usageError(`That collection.json would fail its schema: ${errors.join('; ')}.`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!keep) {
|
|
138
|
-
writeFileSync(collectionFile, `${JSON.stringify(config, null, 2)}\n`);
|
|
139
|
-
io.log(`wrote ${COLLECTION}, for ${registry}${config.namespaces.length ? `, authoring ${config.namespaces.join(', ')}` : ''}`);
|
|
140
|
-
}
|
|
141
|
-
if (values.ci !== undefined) {
|
|
142
|
-
mkdirSync(join(cwd, '.github/workflows'), { recursive: true });
|
|
143
|
-
writeFileSync(workflowFile, workflow(branch, keep ? registryUrl(JSON.parse(readFileSync(collectionFile, 'utf8')), env) : registry));
|
|
144
|
-
io.log(`wrote ${WORKFLOW_PATH}, which publishes on a push to ${branch} and pulls back to it, with the CA_DS_TOKEN secret`);
|
|
145
|
-
}
|
|
146
|
-
return { result: { collection: keep ? null : collectionFile, workflow: values.ci !== undefined ? workflowFile : null } };
|
|
147
|
-
},
|
|
148
|
-
};
|