@kinetixui/cli 0.2.0 → 0.3.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/dist/index.js +51 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import
|
|
5
|
+
import pc4 from "picocolors";
|
|
6
6
|
|
|
7
7
|
// src/commands/add.ts
|
|
8
8
|
import { existsSync as existsSync4 } from "fs";
|
|
@@ -102,6 +102,19 @@ function runInstall(cwd, pm, packages) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
// src/lib/registry.ts
|
|
105
|
+
async function fetchRegistryIndex(registryUrl) {
|
|
106
|
+
const url = `${registryUrl.replace(/\/$/, "")}/registry.json`;
|
|
107
|
+
const res = await fetch(url);
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
throw new Error(`Could not load the registry index (${res.status} at ${url}).`);
|
|
110
|
+
}
|
|
111
|
+
const data = await res.json();
|
|
112
|
+
return data.items;
|
|
113
|
+
}
|
|
114
|
+
async function fetchComponentNames(registryUrl) {
|
|
115
|
+
const items = await fetchRegistryIndex(registryUrl);
|
|
116
|
+
return items.filter((item) => item.type === "registry:ui").map((item) => item.name);
|
|
117
|
+
}
|
|
105
118
|
async function fetchRegistryItem(registryUrl, name) {
|
|
106
119
|
const url = `${registryUrl.replace(/\/$/, "")}/${name}.json`;
|
|
107
120
|
const res = await fetch(url);
|
|
@@ -132,7 +145,13 @@ async function add(names, options) {
|
|
|
132
145
|
if (!existsSync4(path4.join(cwd, CONFIG_FILE))) {
|
|
133
146
|
console.log(pc.yellow("!"), `No ${CONFIG_FILE} found \u2014 using defaults. Run "kinetixui init" first to set your own aliases.`);
|
|
134
147
|
}
|
|
135
|
-
|
|
148
|
+
if (options.all) {
|
|
149
|
+
console.log("Fetching the full component list\u2026");
|
|
150
|
+
names = await fetchComponentNames(options.registry);
|
|
151
|
+
} else if (names.length === 0) {
|
|
152
|
+
throw new Error('Pass component names to add (e.g. "kinetixui add button card"), or use --all for every component.');
|
|
153
|
+
}
|
|
154
|
+
console.log(options.all ? `Resolving all ${names.length} components\u2026` : `Resolving ${names.join(", ")}\u2026`);
|
|
136
155
|
const items = await resolveTree(options.registry, names);
|
|
137
156
|
const { deps, written, skipped } = await writeItems(cwd, config, items.values(), options.overwrite);
|
|
138
157
|
for (const file of written) console.log(pc.green("\u2714"), `Added ${file}`);
|
|
@@ -226,25 +245,50 @@ async function init(options) {
|
|
|
226
245
|
}
|
|
227
246
|
console.log();
|
|
228
247
|
console.log(`Next: ${pc2.cyan("npx @kinetixui/cli add button")}`);
|
|
248
|
+
console.log(`See everything: ${pc2.cyan("npx @kinetixui/cli list")}`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/commands/list.ts
|
|
252
|
+
import pc3 from "picocolors";
|
|
253
|
+
async function list(options) {
|
|
254
|
+
const items = await fetchRegistryIndex(options.registry);
|
|
255
|
+
const components = items.filter((item) => item.type === "registry:ui").sort((a, b) => a.name.localeCompare(b.name));
|
|
256
|
+
console.log(`${components.length} component(s):`);
|
|
257
|
+
console.log();
|
|
258
|
+
for (const item of components) {
|
|
259
|
+
const description = item.description ? pc3.dim(` \u2014 ${item.description}`) : "";
|
|
260
|
+
console.log(` ${pc3.cyan(item.name)}${description}`);
|
|
261
|
+
}
|
|
262
|
+
console.log();
|
|
263
|
+
console.log(`Add one: ${pc3.cyan("npx @kinetixui/cli add <name>")}`);
|
|
264
|
+
console.log(`Add everything: ${pc3.cyan("npx @kinetixui/cli add --all")}`);
|
|
229
265
|
}
|
|
230
266
|
|
|
231
267
|
// src/index.ts
|
|
232
268
|
var DEFAULT_REGISTRY = "https://kinetixui.com/r";
|
|
233
269
|
var program = new Command();
|
|
234
|
-
program.name("kinetixui").description("Add KinetixUI components and tokens to your project.").version("0.
|
|
270
|
+
program.name("kinetixui").description("Add KinetixUI components and tokens to your project.").version("0.3.0");
|
|
235
271
|
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
272
|
try {
|
|
237
273
|
await init({ registry: opts.registry, yes: opts.yes });
|
|
238
274
|
} catch (err) {
|
|
239
|
-
console.error(
|
|
275
|
+
console.error(pc4.red("\u2716"), err.message);
|
|
276
|
+
process.exitCode = 1;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
program.command("add").description("Add one or more components to your project.").argument("[components...]", "component names, e.g. button card").option("-a, --all", "add every component in the registry", false).option("-o, --overwrite", "overwrite existing files", false).option("-r, --registry <url>", "registry base URL", DEFAULT_REGISTRY).action(async (components, opts) => {
|
|
280
|
+
try {
|
|
281
|
+
await add(components, { registry: opts.registry, overwrite: opts.overwrite, all: opts.all });
|
|
282
|
+
} catch (err) {
|
|
283
|
+
console.error(pc4.red("\u2716"), err.message);
|
|
240
284
|
process.exitCode = 1;
|
|
241
285
|
}
|
|
242
286
|
});
|
|
243
|
-
program.command("
|
|
287
|
+
program.command("list").description("List every component available in the registry.").option("-r, --registry <url>", "registry base URL", DEFAULT_REGISTRY).action(async (opts) => {
|
|
244
288
|
try {
|
|
245
|
-
await
|
|
289
|
+
await list({ registry: opts.registry });
|
|
246
290
|
} catch (err) {
|
|
247
|
-
console.error(
|
|
291
|
+
console.error(pc4.red("\u2716"), err.message);
|
|
248
292
|
process.exitCode = 1;
|
|
249
293
|
}
|
|
250
294
|
});
|