@noarka/cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +18 -2
- package/dist/cli.js +177 -0
- package/package.json +33 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Noarka
|
|
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,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @noarka/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scaffold Noarka UI primitives into your project, shadcn-style.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @noarka/cli init
|
|
7
|
+
npx @noarka/cli add button
|
|
8
|
+
npx @noarka/cli list
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- `init` writes `utils/cn.ts` once per project.
|
|
12
|
+
- `add <component>` copies the primitive to `components/ui/` (lowercase
|
|
13
|
+
basenames, same-dir imports rewritten) and writes `utils/cn.ts` if missing.
|
|
14
|
+
Components that use another primitive print a follow-up `add` command.
|
|
15
|
+
- Templates ship inside `@noarka/ui` itself, so scaffolded code always
|
|
16
|
+
matches the installed library version.
|
|
17
|
+
|
|
18
|
+
Options: `--dir <path>` scaffolds into another project root, `--overwrite`
|
|
19
|
+
replaces existing files.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
var require2 = createRequire(import.meta.url);
|
|
8
|
+
function cliVersion() {
|
|
9
|
+
try {
|
|
10
|
+
const pkg = require2("../package.json");
|
|
11
|
+
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
12
|
+
} catch {
|
|
13
|
+
return "0.0.0";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function uiRoot() {
|
|
17
|
+
try {
|
|
18
|
+
return path.dirname(require2.resolve("@noarka/ui/package.json"));
|
|
19
|
+
} catch {
|
|
20
|
+
console.error(
|
|
21
|
+
"Could not find @noarka/ui. Install it first:\n npm install @noarka/ui"
|
|
22
|
+
);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function primitivesDir() {
|
|
27
|
+
return path.join(uiRoot(), "src", "primitives");
|
|
28
|
+
}
|
|
29
|
+
function normalize(value) {
|
|
30
|
+
return value.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
31
|
+
}
|
|
32
|
+
function slugifyDir(dir) {
|
|
33
|
+
return dir.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function available() {
|
|
36
|
+
return fs.readdirSync(primitivesDir(), { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
37
|
+
}
|
|
38
|
+
function findDir(name) {
|
|
39
|
+
const want = normalize(name);
|
|
40
|
+
return available().find((d) => normalize(d) === want) ?? null;
|
|
41
|
+
}
|
|
42
|
+
function ensureDir(dir) {
|
|
43
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
function writeFile(target, content, overwrite) {
|
|
46
|
+
if (fs.existsSync(target) && !overwrite) {
|
|
47
|
+
return "skipped (exists, use --overwrite to replace)";
|
|
48
|
+
}
|
|
49
|
+
ensureDir(path.dirname(target));
|
|
50
|
+
fs.writeFileSync(target, content, "utf8");
|
|
51
|
+
return "created";
|
|
52
|
+
}
|
|
53
|
+
function readTemplate(rel) {
|
|
54
|
+
return fs.readFileSync(path.join(uiRoot(), rel), "utf8");
|
|
55
|
+
}
|
|
56
|
+
function scaffoldName(basename) {
|
|
57
|
+
return basename.charAt(0).toLowerCase() + basename.slice(1);
|
|
58
|
+
}
|
|
59
|
+
function rewriteImports(source) {
|
|
60
|
+
return source.replace(/from\s+["']\.\/([^"']+)["']/g, (_m, spec) => {
|
|
61
|
+
const parts = spec.split("/");
|
|
62
|
+
parts[parts.length - 1] = scaffoldName(parts[parts.length - 1]);
|
|
63
|
+
return `from "./${parts.join("/")}"`;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function ensureCn(projectDir, overwrite) {
|
|
67
|
+
const target = path.join(projectDir, "utils", "cn.ts");
|
|
68
|
+
const content = readTemplate(path.join("src", "utils", "cn.ts"));
|
|
69
|
+
return { target, status: writeFile(target, content, overwrite) };
|
|
70
|
+
}
|
|
71
|
+
function componentFiles(dir) {
|
|
72
|
+
return fs.readdirSync(path.join(primitivesDir(), dir)).filter((f) => f !== "index.ts" && (f.endsWith(".tsx") || f.endsWith(".ts"))).sort();
|
|
73
|
+
}
|
|
74
|
+
function peerDeps(dir) {
|
|
75
|
+
const deps = /* @__PURE__ */ new Set();
|
|
76
|
+
for (const file of componentFiles(dir)) {
|
|
77
|
+
const src = readTemplate(path.join("src", "primitives", dir, file));
|
|
78
|
+
for (const match of src.matchAll(/from\s+["']\.\.\/([^/"']+)/g)) {
|
|
79
|
+
if (match[1] === ".." || match[1] === "utils") continue;
|
|
80
|
+
if (match[1] !== dir) deps.add(slugifyDir(match[1]));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [...deps].sort();
|
|
84
|
+
}
|
|
85
|
+
function cmdInit(projectDir, overwrite) {
|
|
86
|
+
const { target, status } = ensureCn(projectDir, overwrite);
|
|
87
|
+
console.log(`${status}: ${path.relative(process.cwd(), target)}`);
|
|
88
|
+
console.log("\nNext: import the design tokens once in your global CSS:");
|
|
89
|
+
console.log(' @import "@noarka/ui/styles/tokens.css";');
|
|
90
|
+
console.log(' @import "@noarka/ui/styles/base.css";');
|
|
91
|
+
console.log(' @source "../node_modules/@noarka/ui/dist/**/*.js";');
|
|
92
|
+
}
|
|
93
|
+
function cmdAdd(name, projectDir, overwrite) {
|
|
94
|
+
const dir = findDir(name);
|
|
95
|
+
if (!dir) {
|
|
96
|
+
console.error(`Unknown component "${name}".
|
|
97
|
+
`);
|
|
98
|
+
cmdList();
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
for (const file of componentFiles(dir)) {
|
|
102
|
+
const src = readTemplate(path.join("src", "primitives", dir, file));
|
|
103
|
+
const target = path.join(projectDir, "components", "ui", scaffoldName(file));
|
|
104
|
+
console.log(`${writeFile(target, rewriteImports(src), overwrite)}: ${path.relative(process.cwd(), target)}`);
|
|
105
|
+
}
|
|
106
|
+
const cn = ensureCn(projectDir, overwrite);
|
|
107
|
+
console.log(`${cn.status}: ${path.relative(process.cwd(), cn.target)}`);
|
|
108
|
+
const peers = peerDeps(dir).filter((d) => normalize(d) !== normalize(dir));
|
|
109
|
+
if (peers.length > 0) {
|
|
110
|
+
console.log(`
|
|
111
|
+
This component also uses: ${peers.join(", ")}`);
|
|
112
|
+
console.log(`Run: noarka add ${peers.join(" ")}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function cmdList() {
|
|
116
|
+
console.log("Available components:");
|
|
117
|
+
for (const dir of available()) {
|
|
118
|
+
console.log(` ${slugifyDir(dir)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function help() {
|
|
122
|
+
console.log(`noarka: scaffold Noarka UI primitives into your project.
|
|
123
|
+
|
|
124
|
+
Usage:
|
|
125
|
+
noarka init [options] write utils/cn.ts once per project
|
|
126
|
+
noarka add <component> [options] copy a primitive to components/ui/
|
|
127
|
+
noarka list show available components
|
|
128
|
+
|
|
129
|
+
Options:
|
|
130
|
+
--dir <path> project root to scaffold into (default: current directory)
|
|
131
|
+
--overwrite replace files that already exist
|
|
132
|
+
-h, --help show this message
|
|
133
|
+
-v, --version show the version`);
|
|
134
|
+
}
|
|
135
|
+
function parseArgs(argv) {
|
|
136
|
+
const opts2 = { dir: process.cwd(), overwrite: false };
|
|
137
|
+
const rest2 = [];
|
|
138
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
139
|
+
const arg = argv[i];
|
|
140
|
+
if (arg === "--dir" && argv[i + 1]) {
|
|
141
|
+
opts2.dir = path.resolve(argv[i + 1]);
|
|
142
|
+
i += 1;
|
|
143
|
+
} else if (arg === "--overwrite") {
|
|
144
|
+
opts2.overwrite = true;
|
|
145
|
+
} else if (arg === "-h" || arg === "--help") {
|
|
146
|
+
help();
|
|
147
|
+
process.exit(0);
|
|
148
|
+
} else if (arg === "-v" || arg === "--version") {
|
|
149
|
+
console.log(cliVersion());
|
|
150
|
+
process.exit(0);
|
|
151
|
+
} else if (arg.startsWith("-")) {
|
|
152
|
+
console.error(`Unknown option "${arg}". See: noarka --help`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
} else {
|
|
155
|
+
rest2.push(arg);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { opts: opts2, rest: rest2 };
|
|
159
|
+
}
|
|
160
|
+
var { opts, rest } = parseArgs(process.argv.slice(2));
|
|
161
|
+
var [command, ...names] = rest;
|
|
162
|
+
if (command === "init") {
|
|
163
|
+
cmdInit(opts.dir, opts.overwrite);
|
|
164
|
+
} else if (command === "add") {
|
|
165
|
+
if (names.length === 0) {
|
|
166
|
+
console.error("Specify at least one component. See: noarka list");
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
for (const name of names) cmdAdd(name, opts.dir, opts.overwrite);
|
|
170
|
+
} else if (command === "list") {
|
|
171
|
+
cmdList();
|
|
172
|
+
} else if (!command) {
|
|
173
|
+
help();
|
|
174
|
+
} else {
|
|
175
|
+
console.error(`Unknown command "${command}". See: noarka --help`);
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noarka/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Scaffold Noarka UI primitives into your project, shadcn-style.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"noarka": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"noarka",
|
|
17
|
+
"ui",
|
|
18
|
+
"cli",
|
|
19
|
+
"scaffold",
|
|
20
|
+
"components"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@noarka/ui": "^0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.3.5",
|
|
30
|
+
"typescript": "^5"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup src/cli.ts --format esm --clean",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
35
|
+
}
|
|
6
36
|
}
|