@alea-design/cli 0.2.0 → 0.3.1
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 +1 -1
- package/bin/alea.mjs +67 -28
- package/package.json +8 -9
- package/registry-url.json +4 -0
- package/registry.json +1 -1
package/README.md
CHANGED
|
@@ -22,4 +22,4 @@ Replace `init` with `add button select`, `list` or any other command. `init` and
|
|
|
22
22
|
|
|
23
23
|
`init` installs the peers the components need, pinned to the ranges `@alea-design/ui` depends on (`react-aria-components`, `lucide-react@^0.525.0`, `@alea-design/motion`); with `--no-install` it prints the command instead. The copied components type-check with React 18 and React 19 types.
|
|
24
24
|
|
|
25
|
-
Docs: https://alea.alevasquez.dev/installation · MIT license
|
|
25
|
+
Docs: https://alea.alevasquez.dev/installation?utm_source=npm&utm_medium=readme&utm_campaign=alea-cli · MIT license
|
package/bin/alea.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// alea: copies Alea components into your project.
|
|
3
3
|
// alea init [--dir src/components/ui] [--no-install]
|
|
4
|
-
// alea add <component...> | --all [--overwrite] [--update] [--no-install]
|
|
4
|
+
// alea add <component...> | --all [--group] [--overwrite] [--update] [--no-install]
|
|
5
5
|
// alea list
|
|
6
|
-
//
|
|
6
|
+
// alea --version
|
|
7
|
+
// `alea add Button` copies Button.tsx and the files it really imports (not every file of its folders), plus the styles of
|
|
8
|
+
// those folders. A folder name copies the whole folder: alea add button --group.
|
|
9
|
+
// Alea Pro components need a license key: ALEA_LICENSE_KEY=... alea add data-grid (or alea add pro/media for a Pro folder
|
|
10
|
+
// that shares its name with a free one: the Pro media and work folders are media-pro and work-pro)
|
|
7
11
|
import fs from 'node:fs';
|
|
8
12
|
import path from 'node:path';
|
|
9
13
|
import { execSync } from 'node:child_process';
|
|
@@ -13,7 +17,8 @@ const here = path.dirname(fileURLToPath(import.meta.url));
|
|
|
13
17
|
const registry = JSON.parse(fs.readFileSync(path.resolve(here, '../registry.json'), 'utf8'));
|
|
14
18
|
const cwd = process.env.ALEA_CWD || process.cwd();
|
|
15
19
|
const CONFIG = path.join(cwd, 'alea.json');
|
|
16
|
-
|
|
20
|
+
// the one registry address lives in registry-url.json (the same file the docs and the publish script read)
|
|
21
|
+
const REGISTRY_URL = (process.env.ALEA_REGISTRY || JSON.parse(fs.readFileSync(path.resolve(here, '../registry-url.json'), 'utf8')).registry).replace(/\/$/, '');
|
|
17
22
|
const argv = process.argv.slice(2);
|
|
18
23
|
const flag = (name) => argv.includes(`--${name}`);
|
|
19
24
|
const opt = (name, fallback) => { const i = argv.findIndex(a => a === `--${name}` || a.startsWith(`--${name}=`)); if (i < 0) return fallback; return argv[i].includes('=') ? argv[i].split('=')[1] : argv[i + 1]; };
|
|
@@ -35,6 +40,10 @@ function packageManager() {
|
|
|
35
40
|
function install(pkgs) {
|
|
36
41
|
let have = {};
|
|
37
42
|
try { const pj = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')); have = { ...pj.dependencies, ...pj.devDependencies }; } catch { /* no package.json */ }
|
|
43
|
+
// package names and ranges end up in a shell command, and the Pro registry comes over the network: refuse anything that is not an npm name
|
|
44
|
+
const NAME = /^(@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/, RANGE = /^[A-Za-z0-9.^~<>=| *+-]+$/;
|
|
45
|
+
for (const p of pkgs) if (typeof p !== 'string' || !NAME.test(p)) die(`the registry listed a package name that is not valid (${JSON.stringify(String(p).slice(0, 60))}); nothing was installed`);
|
|
46
|
+
for (const r of Object.values(registry.peers || {})) if (typeof r !== 'string' || !RANGE.test(r)) die('registry.json has a version range that is not valid; nothing was installed');
|
|
38
47
|
const missing = [...new Set(pkgs)].filter(p => !have[p]);
|
|
39
48
|
if (!missing.length) return;
|
|
40
49
|
// pinned to the ranges @alea-design/ui depends on (a plain install of lucide-react would pull a newer major)
|
|
@@ -45,8 +54,15 @@ function install(pkgs) {
|
|
|
45
54
|
say(`→ ${cmdline}`);
|
|
46
55
|
try { execSync(cmdline, { cwd, stdio: 'inherit' }); } catch { die(`could not install; run it yourself: ${cmdline}`); }
|
|
47
56
|
}
|
|
57
|
+
// a file path from a registry (the Pro one comes over the network) must stay inside the target folder
|
|
58
|
+
function safePath(dir, rel) {
|
|
59
|
+
if (typeof rel !== 'string' || !rel || path.isAbsolute(rel) || rel.includes('\\') || rel.includes('\0') || /^[a-zA-Z]:/.test(rel) || rel.split('/').some(seg => seg === '..' || seg === '')) die(`the registry sent a file path outside the folder (${JSON.stringify(String(rel).slice(0, 80))}); nothing was written`);
|
|
60
|
+
const target = path.resolve(dir, rel);
|
|
61
|
+
if (!target.startsWith(path.resolve(dir) + path.sep)) die(`the registry sent a file path outside the folder (${JSON.stringify(rel.slice(0, 80))}); nothing was written`);
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
48
64
|
function write(dir, file, { overwrite, update }) {
|
|
49
|
-
const target =
|
|
65
|
+
const target = safePath(dir, file.path);
|
|
50
66
|
if (fs.existsSync(target) && !overwrite) {
|
|
51
67
|
// --update: keep yours, put the new version next to it (button.new.tsx) when it differs, so you can compare and merge
|
|
52
68
|
if (update && fs.readFileSync(target, 'utf8') !== file.content) { fs.writeFileSync(target.replace(/(\.[^.]+)$/, '.new$1'), file.content); return 'new'; }
|
|
@@ -58,22 +74,30 @@ function write(dir, file, { overwrite, update }) {
|
|
|
58
74
|
}
|
|
59
75
|
const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
60
76
|
const ALIAS = { input: 'field', textfield: 'field', modal: 'overlay', dialog: 'overlay', tooltip: 'overlay', popover: 'overlay', toast: 'feedback', alert: 'feedback', progress: 'feedback', skeleton: 'feedback', badge: 'display', tag: 'display', avatar: 'display', checkbox: 'choice', radio: 'choice', switch: 'choice', heading: 'typography', text: 'typography', link: 'typography', stack: 'layout', grid: 'layout', bento: 'layout', collapse: 'accordion', segmented: 'button', holdbutton: 'button', charts: 'chart', kanban: 'dnd', sortable: 'dnd', markdown: 'editor', calendarview: 'calendar', glass: 'effects', gooey: 'effects' };
|
|
61
|
-
// Names people type:
|
|
77
|
+
// Names people type: a component (Button, IconButton, icon-button), a folder (button, field) or a few aliases.
|
|
78
|
+
// Returns { group, pro, name } where name is the component export, or null for a whole folder.
|
|
62
79
|
function resolve(name) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
80
|
+
let n = norm(name), proOnly = false;
|
|
81
|
+
if (/^pro\//i.test(name)) { proOnly = true; n = norm(name.slice(4)); }
|
|
82
|
+
const proGroup = () => Object.keys(registry.pro || {}).find(g => norm(g) === n || norm(g) === n + 'pro');
|
|
83
|
+
const exp = (groups, pro) => { for (const [g, def] of Object.entries(groups)) { const e = (pro ? def : def.exports).find(e => norm(e) === n); if (e) return { group: g, pro, name: e }; } return null; };
|
|
84
|
+
if (!proOnly && !flag('group')) { const hit = exp(registry.groups, false); if (hit) return hit; }
|
|
85
|
+
if (!proOnly) { const g = Object.keys(registry.groups).find(g => norm(g) === n); if (g) return { group: g, pro: false, name: null }; }
|
|
86
|
+
const pg = proGroup();
|
|
87
|
+
if (pg && (proOnly || !flag('group'))) return { group: pg, pro: true, name: null };
|
|
88
|
+
if (!flag('group')) { const hit = exp(registry.pro || {}, true); if (hit) return hit; }
|
|
89
|
+
if (!proOnly && ALIAS[n]) return { group: ALIAS[n], pro: !registry.groups[ALIAS[n]], name: null };
|
|
68
90
|
return null;
|
|
69
91
|
}
|
|
92
|
+
// the components worth listing: PascalCase components and public hooks, not the helpers a folder also exports
|
|
93
|
+
const listed = e => /^[A-Z][a-z0-9]/.test(e) || /^use[A-Z]/.test(e);
|
|
70
94
|
async function proRegistry() {
|
|
71
95
|
if (process.env.ALEA_PRO_REGISTRY_FILE) return JSON.parse(fs.readFileSync(process.env.ALEA_PRO_REGISTRY_FILE, 'utf8'));
|
|
72
96
|
const key = opt('license') || process.env.ALEA_LICENSE_KEY;
|
|
73
|
-
if (!key) die('that is part of Alea Pro. Get a license at https://alea.alevasquez.dev/pro, then run with ALEA_LICENSE_KEY=<your key> (or --license <key>).');
|
|
97
|
+
if (!key) die('that is part of Alea Pro. Get a license at https://alea.alevasquez.dev/pro?utm_source=npm&utm_medium=cli&utm_campaign=alea-pro&utm_content=no-key, then run with ALEA_LICENSE_KEY=<your key> (or --license <key>).');
|
|
74
98
|
let res;
|
|
75
99
|
try { res = await fetch(`${REGISTRY_URL}/cli/pro-registry.json`, { headers: { authorization: `Bearer ${key}` } }); } catch (e) { die(`could not reach ${REGISTRY_URL} (${e.message})`); }
|
|
76
|
-
if (res.status === 401 || res.status === 403) die('that license key is not valid (or no longer active). Check it at https://alea.alevasquez.dev/pro');
|
|
100
|
+
if (res.status === 401 || res.status === 403) die('that license key is not valid (or no longer active). Check it at https://alea.alevasquez.dev/pro?utm_source=npm&utm_medium=cli&utm_campaign=alea-pro&utm_content=bad-key');
|
|
77
101
|
if (!res.ok) die(`the Pro registry answered ${res.status}`);
|
|
78
102
|
return res.json();
|
|
79
103
|
}
|
|
@@ -115,8 +139,10 @@ function writeCssTypes(dir) {
|
|
|
115
139
|
}
|
|
116
140
|
|
|
117
141
|
const [cmd, ...rest] = argv.filter((a, i) => !a.startsWith('--') && !VALUE_FLAGS.test(argv[i - 1] || ''));
|
|
118
|
-
if (
|
|
119
|
-
say(
|
|
142
|
+
if (flag('version') || argv.includes('-v') || cmd === 'version') {
|
|
143
|
+
say(JSON.parse(fs.readFileSync(path.resolve(here, '../package.json'), 'utf8')).version);
|
|
144
|
+
} else if (!cmd || cmd === 'help' || flag('help')) {
|
|
145
|
+
say(`Alea ${registry.version}\n\n alea init [--dir src/components/ui] [--no-install] set up alea.json, tokens and base styles\n alea add <component...> [--all] [--group] [--overwrite] [--update]\n copy a component and the files it uses; --group copies a whole folder;\n --update puts new versions next to yours\n alea add pro/media a Pro folder that shares its name with a free one (media-pro, work-pro)\n alea list what you can add (Pro needs ALEA_LICENSE_KEY)\n alea --version the CLI version\n`);
|
|
120
146
|
} else if (cmd === 'init') {
|
|
121
147
|
const dir = opt('dir', 'src/components/ui');
|
|
122
148
|
const conf = { $schema: 'https://alea.alevasquez.dev/alea.schema.json', dir, version: registry.version };
|
|
@@ -130,25 +156,38 @@ if (!cmd || cmd === 'help' || flag('help')) {
|
|
|
130
156
|
} else if (cmd === 'add') {
|
|
131
157
|
const conf = config();
|
|
132
158
|
const dir = path.join(cwd, conf.dir);
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
159
|
+
const picked = flag('all') ? Object.keys(registry.groups).map(g => ({ group: g, pro: false, name: null })) : rest.map(n => resolve(n) || die(`no component called "${n}". See: alea list`));
|
|
160
|
+
if (!picked.length) die('say which components, e.g. alea add button select');
|
|
135
161
|
const groups = { ...registry.groups };
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
162
|
+
if (picked.some(p => p.pro)) Object.assign(groups, (await proRegistry()).groups);
|
|
163
|
+
for (const p of picked) if (!groups[p.group]) die(`no component called "${p.group}". See: alea list`);
|
|
164
|
+
// every file of the registry by path; a component's files are walked through their imports
|
|
165
|
+
const byPath = new Map();
|
|
166
|
+
for (const [g, def] of Object.entries(groups)) for (const f of def.files) byPath.set(f.path, { f, g });
|
|
167
|
+
const roots = [];
|
|
168
|
+
for (const p of picked) {
|
|
169
|
+
const files = groups[p.group].files.filter(f => !f.extra && (!p.name || (f.exports || []).some(e => e === p.name)));
|
|
170
|
+
if (!files.length) die(`no component called "${p.name || p.group}". See: alea list`);
|
|
171
|
+
roots.push(...files.map(f => f.path));
|
|
172
|
+
}
|
|
173
|
+
const closure = new Set();
|
|
174
|
+
const visit = pth => { if (closure.has(pth)) return; closure.add(pth); for (const i of byPath.get(pth)?.f.imports || []) visit(i); };
|
|
175
|
+
roots.forEach(visit);
|
|
176
|
+
// styles and declarations are shared by a whole folder: the folders touched bring theirs
|
|
177
|
+
const touched = new Set([...closure].map(pth => byPath.get(pth).g));
|
|
178
|
+
const toWrite = new Set(closure);
|
|
179
|
+
for (const g of touched) for (const f of groups[g].files) if (f.extra) toWrite.add(f.path);
|
|
142
180
|
for (const f of registry.base) if (!fs.existsSync(path.join(dir, f.path))) write(dir, f, { overwrite: false });
|
|
143
181
|
let wrote = 0, kept = 0, fresh = 0;
|
|
144
|
-
for (const
|
|
182
|
+
for (const pth of [...toWrite].sort()) { const r = write(dir, byPath.get(pth).f, { overwrite: flag('overwrite'), update: flag('update') }); r === 'new' ? fresh++ : r ? wrote++ : kept++; }
|
|
145
183
|
writeIndex(dir);
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
const names = picked.map(p => p.name || p.group);
|
|
185
|
+
const withCount = [...closure].filter(pth => !roots.includes(pth)).length;
|
|
186
|
+
say(`✓ ${names.join(', ')}${withCount ? ` (with ${withCount} file${withCount === 1 ? '' : 's'} it uses)` : ''}: ${wrote} file${wrote === 1 ? '' : 's'} written${fresh ? `, ${fresh} new version${fresh === 1 ? '' : 's'} written as .new files next to yours` : ''}${kept ? `, ${kept} kept (use --overwrite to replace, --update to get the new version next to yours)` : ''}`);
|
|
187
|
+
install(['react-aria-components', 'lucide-react', '@alea-design/motion', ...[...closure].flatMap(pth => byPath.get(pth).f.npm || [])]);
|
|
149
188
|
} else if (cmd === 'list') {
|
|
150
|
-
for (const [g, def] of Object.entries(registry.groups)) say(`${g.padEnd(12)} ${def.exports.join(', ')}`);
|
|
151
|
-
for (const [g, exports] of Object.entries(registry.pro || {})) say(`${(g + ' (Pro)').padEnd(12)} ${exports.join(', ')}`);
|
|
189
|
+
for (const [g, def] of Object.entries(registry.groups)) say(`${g.padEnd(12)} ${def.exports.filter(listed).join(', ')}`);
|
|
190
|
+
for (const [g, exports] of Object.entries(registry.pro || {})) say(`${(g + ' (Pro)').padEnd(12)} ${exports.filter(listed).join(', ')}`);
|
|
152
191
|
} else {
|
|
153
192
|
die(`unknown command "${cmd}". Try: alea help`);
|
|
154
193
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alea-design/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Copy Alea components into your project: alea init, add, list.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"design system",
|
|
10
10
|
"alea"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://alea.alevasquez.dev/installation",
|
|
12
|
+
"homepage": "https://alea.alevasquez.dev/installation?utm_source=npm&utm_medium=package&utm_campaign=alea-cli",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/alevascha/alea-design.git",
|
|
15
|
+
"url": "git+https://github.com/alevascha/alea-design.git",
|
|
16
16
|
"directory": "packages/cli"
|
|
17
17
|
},
|
|
18
18
|
"bugs": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"alea": "bin/alea.mjs"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
+
"registry-url.json",
|
|
28
29
|
"bin",
|
|
29
30
|
"registry.json",
|
|
30
31
|
"LICENSE",
|
|
@@ -37,14 +38,12 @@
|
|
|
37
38
|
"registry": "node scripts/build-registry.mjs",
|
|
38
39
|
"test": "node scripts/build-registry.mjs && node --test test/*.test.mjs"
|
|
39
40
|
},
|
|
40
|
-
"
|
|
41
|
-
"@alea-design/motion": "^0.
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@alea-design/motion": "^0.3.1",
|
|
43
|
+
"@types/react-18": "npm:@types/react@^18.3.31",
|
|
44
|
+
"@types/react-dom-18": "npm:@types/react-dom@^18.3.7",
|
|
42
45
|
"lucide-react": "^0.525.0",
|
|
43
46
|
"qrcode-generator": "^1.5.2",
|
|
44
47
|
"react-aria-components": "^1.22.1"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@types/react-18": "npm:@types/react@^18.3.31",
|
|
48
|
-
"@types/react-dom-18": "npm:@types/react-dom@^18.3.7"
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{
|
|
2
|
+
"registry": "https://alea-registry.aledvascha.workers.dev",
|
|
3
|
+
"note": "The ONE address of the Alea Pro registry. Read by bin/alea.mjs (overridable with ALEA_REGISTRY), infra/registry/scripts/publish.mjs and apps/docs/src/pages/Pro.tsx; packages/pro/package.json publishConfig.registry must equal it plus a trailing slash (a CLI test checks). Moving to registry.alevasquez.dev: change it here and in pro/package.json, and keep the old workers.dev Worker alive, because published CLI versions and customers' .npmrc files still point at it."
|
|
4
|
+
}
|