@kinetixui/cli 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/LICENSE +21 -0
- package/dist/index.js +251 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 KinetixUI
|
|
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/dist/index.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import pc3 from "picocolors";
|
|
6
|
+
|
|
7
|
+
// src/commands/add.ts
|
|
8
|
+
import { existsSync as existsSync4 } from "fs";
|
|
9
|
+
import path4 from "path";
|
|
10
|
+
import pc from "picocolors";
|
|
11
|
+
|
|
12
|
+
// src/lib/apply.ts
|
|
13
|
+
import { existsSync as existsSync2 } from "fs";
|
|
14
|
+
import { mkdir, writeFile as writeFile2 } from "fs/promises";
|
|
15
|
+
import path2 from "path";
|
|
16
|
+
|
|
17
|
+
// src/lib/config.ts
|
|
18
|
+
import { existsSync } from "fs";
|
|
19
|
+
import { readFile, writeFile } from "fs/promises";
|
|
20
|
+
import path from "path";
|
|
21
|
+
var CONFIG_FILE = "kinetixui.json";
|
|
22
|
+
var DEFAULT_CONFIG = {
|
|
23
|
+
$schema: "https://kinetixui.com/schema/config.json",
|
|
24
|
+
tailwind: { css: "app/globals.css" },
|
|
25
|
+
aliases: {
|
|
26
|
+
components: "@/components",
|
|
27
|
+
ui: "@/components/ui",
|
|
28
|
+
lib: "@/lib",
|
|
29
|
+
utils: "@/lib/utils"
|
|
30
|
+
},
|
|
31
|
+
srcDir: false
|
|
32
|
+
};
|
|
33
|
+
async function readConfig(cwd) {
|
|
34
|
+
const file = path.join(cwd, CONFIG_FILE);
|
|
35
|
+
if (!existsSync(file)) return null;
|
|
36
|
+
return JSON.parse(await readFile(file, "utf8"));
|
|
37
|
+
}
|
|
38
|
+
async function writeConfig(cwd, config) {
|
|
39
|
+
await writeFile(path.join(cwd, CONFIG_FILE), JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
40
|
+
}
|
|
41
|
+
function resolveAliasDir(cwd, config, alias) {
|
|
42
|
+
const raw = config.aliases[alias].replace(/^@\//, "");
|
|
43
|
+
return path.join(cwd, config.srcDir ? "src" : "", raw);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/lib/apply.ts
|
|
47
|
+
function targetPath(cwd, config, file) {
|
|
48
|
+
if (file.target === "app/globals.css") {
|
|
49
|
+
return path2.join(cwd, config.srcDir ? "src" : "", config.tailwind.css);
|
|
50
|
+
}
|
|
51
|
+
const dir = file.type === "registry:lib" ? resolveAliasDir(cwd, config, "lib") : resolveAliasDir(cwd, config, "ui");
|
|
52
|
+
return path2.join(dir, path2.basename(file.target));
|
|
53
|
+
}
|
|
54
|
+
async function writeItems(cwd, config, items, overwrite) {
|
|
55
|
+
const deps = /* @__PURE__ */ new Set();
|
|
56
|
+
const written = [];
|
|
57
|
+
const skipped = [];
|
|
58
|
+
for (const item of items) {
|
|
59
|
+
for (const dep of item.dependencies ?? []) deps.add(dep);
|
|
60
|
+
for (const file of item.files) {
|
|
61
|
+
const dest = targetPath(cwd, config, file);
|
|
62
|
+
const rel = path2.relative(cwd, dest);
|
|
63
|
+
if (existsSync2(dest) && !overwrite) {
|
|
64
|
+
skipped.push(rel);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
await mkdir(path2.dirname(dest), { recursive: true });
|
|
68
|
+
await writeFile2(dest, file.content, "utf8");
|
|
69
|
+
written.push(rel);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { deps, written, skipped };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/lib/pm.ts
|
|
76
|
+
import { existsSync as existsSync3 } from "fs";
|
|
77
|
+
import { spawn } from "child_process";
|
|
78
|
+
import path3 from "path";
|
|
79
|
+
function detectPackageManager(cwd) {
|
|
80
|
+
if (existsSync3(path3.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
81
|
+
if (existsSync3(path3.join(cwd, "yarn.lock"))) return "yarn";
|
|
82
|
+
if (existsSync3(path3.join(cwd, "bun.lockb"))) return "bun";
|
|
83
|
+
return "npm";
|
|
84
|
+
}
|
|
85
|
+
function installArgs(pm, packages) {
|
|
86
|
+
return pm === "npm" ? ["install", ...packages] : ["add", ...packages];
|
|
87
|
+
}
|
|
88
|
+
function runInstall(cwd, pm, packages) {
|
|
89
|
+
if (packages.length === 0) return Promise.resolve();
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const child = spawn(pm, installArgs(pm, packages), {
|
|
92
|
+
cwd,
|
|
93
|
+
stdio: "inherit",
|
|
94
|
+
shell: process.platform === "win32"
|
|
95
|
+
});
|
|
96
|
+
child.on("error", reject);
|
|
97
|
+
child.on("close", (code) => {
|
|
98
|
+
if (code === 0) resolve();
|
|
99
|
+
else reject(new Error(`"${pm} ${installArgs(pm, packages).join(" ")}" exited with code ${code}`));
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/lib/registry.ts
|
|
105
|
+
async function fetchRegistryItem(registryUrl, name) {
|
|
106
|
+
const url = `${registryUrl.replace(/\/$/, "")}/${name}.json`;
|
|
107
|
+
const res = await fetch(url);
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
throw new Error(`Could not find "${name}" in the registry (${res.status} at ${url}).`);
|
|
110
|
+
}
|
|
111
|
+
return await res.json();
|
|
112
|
+
}
|
|
113
|
+
async function resolveTree(registryUrl, names) {
|
|
114
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
115
|
+
const queue = [...names];
|
|
116
|
+
while (queue.length) {
|
|
117
|
+
const name = queue.shift();
|
|
118
|
+
if (!name || resolved.has(name)) continue;
|
|
119
|
+
const item = await fetchRegistryItem(registryUrl, name);
|
|
120
|
+
resolved.set(name, item);
|
|
121
|
+
for (const dep of item.registryDependencies ?? []) {
|
|
122
|
+
if (!resolved.has(dep)) queue.push(dep);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return resolved;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/commands/add.ts
|
|
129
|
+
async function add(names, options) {
|
|
130
|
+
const cwd = process.cwd();
|
|
131
|
+
const config = await readConfig(cwd) ?? DEFAULT_CONFIG;
|
|
132
|
+
if (!existsSync4(path4.join(cwd, CONFIG_FILE))) {
|
|
133
|
+
console.log(pc.yellow("!"), `No ${CONFIG_FILE} found \u2014 using defaults. Run "kinetixui init" first to set your own aliases.`);
|
|
134
|
+
}
|
|
135
|
+
console.log(`Resolving ${names.join(", ")}\u2026`);
|
|
136
|
+
const items = await resolveTree(options.registry, names);
|
|
137
|
+
const { deps, written, skipped } = await writeItems(cwd, config, items.values(), options.overwrite);
|
|
138
|
+
for (const file of written) console.log(pc.green("\u2714"), `Added ${file}`);
|
|
139
|
+
for (const file of skipped) console.log(pc.yellow("skip"), `${file} already exists (pass --overwrite to replace it)`);
|
|
140
|
+
if (deps.size > 0) {
|
|
141
|
+
const pm = detectPackageManager(cwd);
|
|
142
|
+
console.log();
|
|
143
|
+
console.log(`Installing ${[...deps].join(", ")} with ${pm}\u2026`);
|
|
144
|
+
await runInstall(cwd, pm, [...deps]);
|
|
145
|
+
}
|
|
146
|
+
console.log();
|
|
147
|
+
console.log(pc.green("Done."));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/commands/init.ts
|
|
151
|
+
import { existsSync as existsSync5 } from "fs";
|
|
152
|
+
import path5 from "path";
|
|
153
|
+
import pc2 from "picocolors";
|
|
154
|
+
import prompts from "prompts";
|
|
155
|
+
async function init(options) {
|
|
156
|
+
const cwd = process.cwd();
|
|
157
|
+
const configPath = path5.join(cwd, CONFIG_FILE);
|
|
158
|
+
if (existsSync5(configPath) && !options.yes) {
|
|
159
|
+
const { proceed } = await prompts({
|
|
160
|
+
type: "confirm",
|
|
161
|
+
name: "proceed",
|
|
162
|
+
message: `${CONFIG_FILE} already exists. Overwrite it?`,
|
|
163
|
+
initial: false
|
|
164
|
+
});
|
|
165
|
+
if (!proceed) {
|
|
166
|
+
console.log("Cancelled.");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const srcDirDetected = existsSync5(path5.join(cwd, "src"));
|
|
171
|
+
const answers = options.yes ? {
|
|
172
|
+
srcDir: srcDirDetected,
|
|
173
|
+
css: DEFAULT_CONFIG.tailwind.css,
|
|
174
|
+
components: DEFAULT_CONFIG.aliases.components,
|
|
175
|
+
utils: DEFAULT_CONFIG.aliases.utils
|
|
176
|
+
} : await prompts([
|
|
177
|
+
{
|
|
178
|
+
type: "toggle",
|
|
179
|
+
name: "srcDir",
|
|
180
|
+
message: "Use a src/ directory?",
|
|
181
|
+
initial: srcDirDetected,
|
|
182
|
+
active: "yes",
|
|
183
|
+
inactive: "no"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: "text",
|
|
187
|
+
name: "css",
|
|
188
|
+
message: "Where's your global CSS file?",
|
|
189
|
+
initial: DEFAULT_CONFIG.tailwind.css
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: "text",
|
|
193
|
+
name: "components",
|
|
194
|
+
message: "Import alias for components?",
|
|
195
|
+
initial: DEFAULT_CONFIG.aliases.components
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: "text",
|
|
199
|
+
name: "utils",
|
|
200
|
+
message: "Import alias for utils?",
|
|
201
|
+
initial: DEFAULT_CONFIG.aliases.utils
|
|
202
|
+
}
|
|
203
|
+
]);
|
|
204
|
+
if (answers.css === void 0) {
|
|
205
|
+
console.log("Cancelled.");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const config = {
|
|
209
|
+
...DEFAULT_CONFIG,
|
|
210
|
+
srcDir: !!answers.srcDir,
|
|
211
|
+
tailwind: { css: answers.css },
|
|
212
|
+
aliases: {
|
|
213
|
+
components: answers.components,
|
|
214
|
+
ui: `${answers.components}/ui`,
|
|
215
|
+
lib: answers.utils.replace(/\/utils$/, ""),
|
|
216
|
+
utils: answers.utils
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
await writeConfig(cwd, config);
|
|
220
|
+
console.log(pc2.green("\u2714"), `Created ${CONFIG_FILE}`);
|
|
221
|
+
const items = await resolveTree(options.registry, ["tokens"]);
|
|
222
|
+
const { written, skipped } = await writeItems(cwd, config, items.values(), false);
|
|
223
|
+
for (const file of written) console.log(pc2.green("\u2714"), `Wrote ${file}`);
|
|
224
|
+
for (const file of skipped) {
|
|
225
|
+
console.log(pc2.yellow("!"), `${file} already exists \u2014 merge the token contract in by hand, or delete it and re-run init.`);
|
|
226
|
+
}
|
|
227
|
+
console.log();
|
|
228
|
+
console.log(`Next: ${pc2.cyan("npx @kinetixui/cli add button")}`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/index.ts
|
|
232
|
+
var DEFAULT_REGISTRY = "https://kinetixui.com/r";
|
|
233
|
+
var program = new Command();
|
|
234
|
+
program.name("kinetixui").description("Add KinetixUI components and tokens to your project.").version("0.2.0");
|
|
235
|
+
program.command("init").description("Set up kinetixui.json and pull in the token contract.").option("-y, --yes", "skip prompts and use defaults", false).option("-r, --registry <url>", "registry base URL", DEFAULT_REGISTRY).action(async (opts) => {
|
|
236
|
+
try {
|
|
237
|
+
await init({ registry: opts.registry, yes: opts.yes });
|
|
238
|
+
} catch (err) {
|
|
239
|
+
console.error(pc3.red("\u2716"), err.message);
|
|
240
|
+
process.exitCode = 1;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
program.command("add").description("Add one or more components to your project.").argument("<components...>", "component names, e.g. button card").option("-o, --overwrite", "overwrite existing files", false).option("-r, --registry <url>", "registry base URL", DEFAULT_REGISTRY).action(async (components, opts) => {
|
|
244
|
+
try {
|
|
245
|
+
await add(components, { registry: opts.registry, overwrite: opts.overwrite });
|
|
246
|
+
} catch (err) {
|
|
247
|
+
console.error(pc3.red("\u2716"), err.message);
|
|
248
|
+
process.exitCode = 1;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
program.parseAsync();
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kinetixui/cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Add KinetixUI components and tokens to your project.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://kinetixui.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "ziadfteha/kinetixui"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"kinetixui": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"commander": "^12.1.0",
|
|
20
|
+
"picocolors": "^1.1.1",
|
|
21
|
+
"prompts": "^2.4.2"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.10.2",
|
|
25
|
+
"@types/prompts": "^2.4.9",
|
|
26
|
+
"tsup": "^8.3.5",
|
|
27
|
+
"typescript": "^5.7.2"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup src/index.ts --format esm --clean",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"dev": "tsup src/index.ts --format esm --watch --onSuccess \"node dist/index.js\""
|
|
39
|
+
}
|
|
40
|
+
}
|