@alea-design/cli 0.1.0 → 0.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 +14 -0
- package/bin/alea.mjs +26 -2
- package/package.json +6 -2
- package/registry.json +1 -1
package/README.md
CHANGED
|
@@ -8,4 +8,18 @@ npx @alea-design/cli add button select dialog
|
|
|
8
8
|
ALEA_LICENSE_KEY=... npx @alea-design/cli add data-grid # Alea Pro
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
The same commands with the other package managers (the package has one command, `alea`, so the package name is enough):
|
|
12
|
+
|
|
13
|
+
| Manager | Run the CLI |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| npm | `npx @alea-design/cli init` |
|
|
16
|
+
| pnpm | `pnpm dlx @alea-design/cli init` |
|
|
17
|
+
| Yarn 2 or later | `yarn dlx @alea-design/cli init` |
|
|
18
|
+
| Bun | `bunx @alea-design/cli init` |
|
|
19
|
+
| Deno | `deno run -A npm:@alea-design/cli init` |
|
|
20
|
+
|
|
21
|
+
Replace `init` with `add button select`, `list` or any other command. `init` and `add` install the peers with the manager of the project: they look for `pnpm-lock.yaml`, `yarn.lock`, `bun.lock` or `bun.lockb`, and `deno.lock` (or a `deno.json` without a `package.json`), and use npm otherwise; in a Deno project they run `deno add npm:...`.
|
|
22
|
+
|
|
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
|
+
|
|
11
25
|
Docs: https://alea.alevasquez.dev/installation · MIT license
|
package/bin/alea.mjs
CHANGED
|
@@ -29,6 +29,7 @@ function packageManager() {
|
|
|
29
29
|
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm add';
|
|
30
30
|
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn add';
|
|
31
31
|
if (fs.existsSync(path.join(cwd, 'bun.lockb')) || fs.existsSync(path.join(cwd, 'bun.lock'))) return 'bun add';
|
|
32
|
+
if (fs.existsSync(path.join(cwd, 'deno.lock')) || (!fs.existsSync(path.join(cwd, 'package.json')) && ['deno.json', 'deno.jsonc'].some(f => fs.existsSync(path.join(cwd, f))))) return 'deno add';
|
|
32
33
|
return 'npm install';
|
|
33
34
|
}
|
|
34
35
|
function install(pkgs) {
|
|
@@ -36,7 +37,10 @@ function install(pkgs) {
|
|
|
36
37
|
try { const pj = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')); have = { ...pj.dependencies, ...pj.devDependencies }; } catch { /* no package.json */ }
|
|
37
38
|
const missing = [...new Set(pkgs)].filter(p => !have[p]);
|
|
38
39
|
if (!missing.length) return;
|
|
39
|
-
|
|
40
|
+
// pinned to the ranges @alea-design/ui depends on (a plain install of lucide-react would pull a newer major)
|
|
41
|
+
// Deno takes npm specifiers: deno add npm:lucide-react@^0.525.0
|
|
42
|
+
const pm = packageManager();
|
|
43
|
+
const cmdline = `${pm} ${missing.map(p => (pm === 'deno add' ? 'npm:' : '') + (registry.peers?.[p] ? `${p}@${registry.peers[p]}` : p)).join(' ')}`;
|
|
40
44
|
if (flag('no-install')) { say(`→ also install: ${cmdline}`); return; }
|
|
41
45
|
say(`→ ${cmdline}`);
|
|
42
46
|
try { execSync(cmdline, { cwd, stdio: 'inherit' }); } catch { die(`could not install; run it yourself: ${cmdline}`); }
|
|
@@ -88,6 +92,26 @@ function writeIndex(dir) {
|
|
|
88
92
|
css.push("@import './presets.css';", "@import '@alea-design/motion/motion.css';");
|
|
89
93
|
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
94
|
fs.writeFileSync(path.join(dir, 'styles.css'), css.join('\n') + '\n');
|
|
95
|
+
writeCssTypes(dir);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// index.ts has `import './styles.css'`. TypeScript 6+ checks side-effect imports, so a project without a bundler's env types
|
|
99
|
+
// (vite/client, next) needs one line that declares CSS files; when the project already declares them we write nothing.
|
|
100
|
+
function cssTypesDeclared() {
|
|
101
|
+
const places = [cwd, path.join(cwd, 'src'), path.join(cwd, 'app')];
|
|
102
|
+
for (const p of places) {
|
|
103
|
+
if (!fs.existsSync(p)) continue;
|
|
104
|
+
for (const f of fs.readdirSync(p)) {
|
|
105
|
+
if (!f.endsWith('.d.ts') || f === 'styles.d.ts') continue;
|
|
106
|
+
try { if (/vite\/client|next\/image-types|next-env|declare\s+module\s+['"]\*\.css['"]/.test(fs.readFileSync(path.join(p, f), 'utf8'))) return true; } catch { /* unreadable: write ours */ }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function writeCssTypes(dir) {
|
|
112
|
+
const file = path.join(dir, 'styles.d.ts');
|
|
113
|
+
if (cssTypesDeclared()) { fs.rmSync(file, { force: true }); return; }
|
|
114
|
+
fs.writeFileSync(file, "// GENERATED by alea: lets TypeScript accept the side-effect import of styles.css in index.ts.\ndeclare module '*.css';\n");
|
|
91
115
|
}
|
|
92
116
|
|
|
93
117
|
const [cmd, ...rest] = argv.filter((a, i) => !a.startsWith('--') && !VALUE_FLAGS.test(argv[i - 1] || ''));
|
|
@@ -100,7 +124,7 @@ if (!cmd || cmd === 'help' || flag('help')) {
|
|
|
100
124
|
const abs = path.join(cwd, dir);
|
|
101
125
|
for (const f of registry.base) write(abs, f, { overwrite: true });
|
|
102
126
|
writeIndex(abs);
|
|
103
|
-
say(`✓ alea.json, ${dir}/tokens.css, base.css, presets.css, styles.css and index.ts`);
|
|
127
|
+
say(`✓ alea.json, ${dir}/tokens.css, base.css, presets.css, styles.css${fs.existsSync(path.join(abs, 'styles.d.ts')) ? ', styles.d.ts' : ''} and index.ts`);
|
|
104
128
|
install(['react-aria-components', 'lucide-react', '@alea-design/motion']);
|
|
105
129
|
say(`\nNext: npx @alea-design/cli add button\nThen import from '${dir.replace(/^src\//, '@/')}' (or a relative path).`);
|
|
106
130
|
} else if (cmd === 'add') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alea-design/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Copy Alea components into your project: alea init, add, list.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -38,9 +38,13 @@
|
|
|
38
38
|
"test": "node scripts/build-registry.mjs && node --test test/*.test.mjs"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@alea-design/motion": "^0.
|
|
41
|
+
"@alea-design/motion": "^0.2.0",
|
|
42
42
|
"lucide-react": "^0.525.0",
|
|
43
43
|
"qrcode-generator": "^1.5.2",
|
|
44
44
|
"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"
|
|
45
49
|
}
|
|
46
50
|
}
|