kinetixui 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/dist/index.js +251 -0
- package/package.json +37 -0
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 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.1.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,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kinetixui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Add KinetixUI components and tokens to your project.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://kinetixui.com",
|
|
8
|
+
"repository": "ziadfteha/kinetixui",
|
|
9
|
+
"bin": {
|
|
10
|
+
"kinetixui": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup src/index.ts --format esm --clean",
|
|
17
|
+
"typecheck": "tsc --noEmit",
|
|
18
|
+
"dev": "tsup src/index.ts --format esm --watch --onSuccess \"node dist/index.js\""
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"commander": "^12.1.0",
|
|
22
|
+
"picocolors": "^1.1.1",
|
|
23
|
+
"prompts": "^2.4.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.10.2",
|
|
27
|
+
"@types/prompts": "^2.4.9",
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"typescript": "^5.7.2"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|