@alea-design/cli 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/bin/alea.mjs +130 -0
- package/package.json +44 -4
- package/registry.json +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alejandro Vasquez (https://alevasquez.dev)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alea-design/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copy Alea components into your project and own the source.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @alea-design/cli init
|
|
7
|
+
npx @alea-design/cli add button select dialog
|
|
8
|
+
ALEA_LICENSE_KEY=... npx @alea-design/cli add data-grid # Alea Pro
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Docs: https://alea.alevasquez.dev/installation · MIT license
|
package/bin/alea.mjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// alea: copies Alea components into your project.
|
|
3
|
+
// alea init [--dir src/components/ui] [--no-install]
|
|
4
|
+
// alea add <component...> | --all [--overwrite] [--update] [--no-install]
|
|
5
|
+
// alea list
|
|
6
|
+
// Alea Pro components need a license key: ALEA_LICENSE_KEY=... alea add data-grid
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { execSync } from 'node:child_process';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
|
|
12
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const registry = JSON.parse(fs.readFileSync(path.resolve(here, '../registry.json'), 'utf8'));
|
|
14
|
+
const cwd = process.env.ALEA_CWD || process.cwd();
|
|
15
|
+
const CONFIG = path.join(cwd, 'alea.json');
|
|
16
|
+
const REGISTRY_URL = (process.env.ALEA_REGISTRY || 'https://alea-registry.aledvascha.workers.dev').replace(/\/$/, '');
|
|
17
|
+
const argv = process.argv.slice(2);
|
|
18
|
+
const flag = (name) => argv.includes(`--${name}`);
|
|
19
|
+
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]; };
|
|
20
|
+
const say = (s) => process.stdout.write(s + '\n');
|
|
21
|
+
const die = (s) => { process.stderr.write('alea: ' + s + '\n'); process.exit(1); };
|
|
22
|
+
const VALUE_FLAGS = /^--(dir|license)$/;
|
|
23
|
+
|
|
24
|
+
function config() {
|
|
25
|
+
if (!fs.existsSync(CONFIG)) die('no alea.json here. Run: npx @alea-design/cli init');
|
|
26
|
+
return JSON.parse(fs.readFileSync(CONFIG, 'utf8'));
|
|
27
|
+
}
|
|
28
|
+
function packageManager() {
|
|
29
|
+
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm add';
|
|
30
|
+
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn add';
|
|
31
|
+
if (fs.existsSync(path.join(cwd, 'bun.lockb')) || fs.existsSync(path.join(cwd, 'bun.lock'))) return 'bun add';
|
|
32
|
+
return 'npm install';
|
|
33
|
+
}
|
|
34
|
+
function install(pkgs) {
|
|
35
|
+
let have = {};
|
|
36
|
+
try { const pj = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')); have = { ...pj.dependencies, ...pj.devDependencies }; } catch { /* no package.json */ }
|
|
37
|
+
const missing = [...new Set(pkgs)].filter(p => !have[p]);
|
|
38
|
+
if (!missing.length) return;
|
|
39
|
+
const cmdline = `${packageManager()} ${missing.join(' ')}`;
|
|
40
|
+
if (flag('no-install')) { say(`→ also install: ${cmdline}`); return; }
|
|
41
|
+
say(`→ ${cmdline}`);
|
|
42
|
+
try { execSync(cmdline, { cwd, stdio: 'inherit' }); } catch { die(`could not install; run it yourself: ${cmdline}`); }
|
|
43
|
+
}
|
|
44
|
+
function write(dir, file, { overwrite, update }) {
|
|
45
|
+
const target = path.join(dir, file.path);
|
|
46
|
+
if (fs.existsSync(target) && !overwrite) {
|
|
47
|
+
// --update: keep yours, put the new version next to it (button.new.tsx) when it differs, so you can compare and merge
|
|
48
|
+
if (update && fs.readFileSync(target, 'utf8') !== file.content) { fs.writeFileSync(target.replace(/(\.[^.]+)$/, '.new$1'), file.content); return 'new'; }
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
52
|
+
fs.writeFileSync(target, file.content);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
56
|
+
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' };
|
|
57
|
+
// Names people type: the folder (button), a component (IconButton, icon-button) or a few aliases. Returns [group, isPro].
|
|
58
|
+
function resolve(name) {
|
|
59
|
+
const n = norm(name);
|
|
60
|
+
for (const [g, def] of Object.entries(registry.groups)) if (norm(g) === n || def.exports.some(e => norm(e) === n)) return [g, false];
|
|
61
|
+
for (const [g, exports] of Object.entries(registry.pro || {})) if (norm(g) === n || exports.some(e => norm(e) === n)) return [g, true];
|
|
62
|
+
const a = ALIAS[n];
|
|
63
|
+
if (a) return [a, !registry.groups[a]];
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
async function proRegistry() {
|
|
67
|
+
if (process.env.ALEA_PRO_REGISTRY_FILE) return JSON.parse(fs.readFileSync(process.env.ALEA_PRO_REGISTRY_FILE, 'utf8'));
|
|
68
|
+
const key = opt('license') || process.env.ALEA_LICENSE_KEY;
|
|
69
|
+
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>).');
|
|
70
|
+
let res;
|
|
71
|
+
try { res = await fetch(`${REGISTRY_URL}/cli/pro-registry.json`, { headers: { authorization: `Bearer ${key}` } }); } catch (e) { die(`could not reach ${REGISTRY_URL} (${e.message})`); }
|
|
72
|
+
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');
|
|
73
|
+
if (!res.ok) die(`the Pro registry answered ${res.status}`);
|
|
74
|
+
return res.json();
|
|
75
|
+
}
|
|
76
|
+
// index.ts and styles.css list what is on disk, so free and Pro components stay listed whatever was added last
|
|
77
|
+
function writeIndex(dir) {
|
|
78
|
+
const comps = path.join(dir, 'components');
|
|
79
|
+
const exports = [], css = ["/* Alea styles. GENERATED by alea: tokens, base and the components you added. */", "@import './base.css';"];
|
|
80
|
+
if (fs.existsSync(comps)) for (const g of fs.readdirSync(comps).sort()) {
|
|
81
|
+
const gd = path.join(comps, g);
|
|
82
|
+
if (!fs.statSync(gd).isDirectory()) continue;
|
|
83
|
+
for (const f of fs.readdirSync(gd).sort()) {
|
|
84
|
+
if (/\.tsx?$/.test(f) && !f.endsWith('.d.ts')) exports.push(`export * from './components/${g}/${f.replace(/\.tsx?$/, '')}';`);
|
|
85
|
+
if (f.endsWith('.css')) css.push(`@import './components/${g}/${f}';`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
css.push("@import './presets.css';", "@import '@alea-design/motion/motion.css';");
|
|
89
|
+
fs.writeFileSync(path.join(dir, 'index.ts'), `// GENERATED by alea: everything you added. Import from here.\nimport './styles.css';\n${exports.join('\n')}\nexport { cx } from './utils/cx';\nexport { useStrings, registerStrings, type AleaStrings } from './i18n/strings';\n`);
|
|
90
|
+
fs.writeFileSync(path.join(dir, 'styles.css'), css.join('\n') + '\n');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const [cmd, ...rest] = argv.filter((a, i) => !a.startsWith('--') && !VALUE_FLAGS.test(argv[i - 1] || ''));
|
|
94
|
+
if (!cmd || cmd === 'help' || flag('help')) {
|
|
95
|
+
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] [--overwrite] [--update] copy components (and what they use); --update puts new versions next to yours\n alea list what you can add (Pro needs ALEA_LICENSE_KEY)\n`);
|
|
96
|
+
} else if (cmd === 'init') {
|
|
97
|
+
const dir = opt('dir', 'src/components/ui');
|
|
98
|
+
const conf = { $schema: 'https://alea.alevasquez.dev/alea.schema.json', dir, version: registry.version };
|
|
99
|
+
fs.writeFileSync(CONFIG, JSON.stringify(conf, null, 2) + '\n');
|
|
100
|
+
const abs = path.join(cwd, dir);
|
|
101
|
+
for (const f of registry.base) write(abs, f, { overwrite: true });
|
|
102
|
+
writeIndex(abs);
|
|
103
|
+
say(`✓ alea.json, ${dir}/tokens.css, base.css, presets.css, styles.css and index.ts`);
|
|
104
|
+
install(['react-aria-components', 'lucide-react', '@alea-design/motion']);
|
|
105
|
+
say(`\nNext: npx @alea-design/cli add button\nThen import from '${dir.replace(/^src\//, '@/')}' (or a relative path).`);
|
|
106
|
+
} else if (cmd === 'add') {
|
|
107
|
+
const conf = config();
|
|
108
|
+
const dir = path.join(cwd, conf.dir);
|
|
109
|
+
const resolved = flag('all') ? Object.keys(registry.groups).map(g => [g, false]) : rest.map(n => resolve(n) || die(`no component called "${n}". See: alea list`));
|
|
110
|
+
if (!resolved.length) die('say which components, e.g. alea add button select');
|
|
111
|
+
const groups = { ...registry.groups };
|
|
112
|
+
if (resolved.some(([, pro]) => pro)) Object.assign(groups, (await proRegistry()).groups);
|
|
113
|
+
const wanted = resolved.map(([g]) => g);
|
|
114
|
+
for (const g of wanted) if (!groups[g]) die(`no component called "${g}". See: alea list`);
|
|
115
|
+
const all = new Set();
|
|
116
|
+
const visit = g => { if (all.has(g)) return; all.add(g); (groups[g].deps || []).forEach(visit); };
|
|
117
|
+
wanted.forEach(visit);
|
|
118
|
+
for (const f of registry.base) if (!fs.existsSync(path.join(dir, f.path))) write(dir, f, { overwrite: false });
|
|
119
|
+
let wrote = 0, kept = 0, fresh = 0;
|
|
120
|
+
for (const g of [...all].sort()) for (const f of groups[g].files) { const r = write(dir, f, { overwrite: flag('overwrite'), update: flag('update') }); r === 'new' ? fresh++ : r ? wrote++ : kept++; }
|
|
121
|
+
writeIndex(dir);
|
|
122
|
+
const extra = [...all].sort().filter(g => !wanted.includes(g));
|
|
123
|
+
say(`✓ ${wanted.join(', ')}${extra.length ? ` (with ${extra.join(', ')})` : ''}: ${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)` : ''}`);
|
|
124
|
+
install(['react-aria-components', 'lucide-react', '@alea-design/motion', ...[...all].flatMap(g => groups[g].npm || [])]);
|
|
125
|
+
} else if (cmd === 'list') {
|
|
126
|
+
for (const [g, def] of Object.entries(registry.groups)) say(`${g.padEnd(12)} ${def.exports.join(', ')}`);
|
|
127
|
+
for (const [g, exports] of Object.entries(registry.pro || {})) say(`${(g + ' (Pro)').padEnd(12)} ${exports.join(', ')}`);
|
|
128
|
+
} else {
|
|
129
|
+
die(`unknown command "${cmd}". Try: alea help`);
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alea-design/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Copy Alea components into your project: alea init, add, list.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"react components",
|
|
8
|
+
"copy paste",
|
|
9
|
+
"design system",
|
|
10
|
+
"alea"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://alea.alevasquez.dev/installation",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/alevascha/alea-design.git",
|
|
16
|
+
"directory": "packages/cli"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/alevascha/alea-design/issues"
|
|
20
|
+
},
|
|
21
|
+
"author": "Alejandro Vasquez (https://alevasquez.dev)",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"alea": "bin/alea.mjs"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"bin",
|
|
29
|
+
"registry.json",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"registry": "node scripts/build-registry.mjs",
|
|
38
|
+
"test": "node scripts/build-registry.mjs && node --test test/*.test.mjs"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@alea-design/motion": "^0.1.0",
|
|
42
|
+
"lucide-react": "^0.525.0",
|
|
43
|
+
"qrcode-generator": "^1.5.2",
|
|
44
|
+
"react-aria-components": "^1.22.1"
|
|
45
|
+
}
|
|
46
|
+
}
|