@transight-design/cli 0.3.0 → 0.5.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 +107 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command7 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/init.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -40,16 +40,16 @@ var runShadcn = (args, options = {}) => {
|
|
|
40
40
|
return Promise.resolve(0);
|
|
41
41
|
}
|
|
42
42
|
console.log(pc.dim("\u2192 ") + pc.cyan(display));
|
|
43
|
-
return new Promise((
|
|
43
|
+
return new Promise((resolve2) => {
|
|
44
44
|
const proc = spawn(cmd, fullArgs, {
|
|
45
45
|
stdio: "inherit",
|
|
46
46
|
cwd: options.cwd ?? process.cwd(),
|
|
47
47
|
shell: process.platform === "win32"
|
|
48
48
|
});
|
|
49
|
-
proc.on("close", (code) =>
|
|
49
|
+
proc.on("close", (code) => resolve2(code ?? 0));
|
|
50
50
|
proc.on("error", (err) => {
|
|
51
51
|
console.error(pc.red(`shadcn \uC2E4\uD589 \uC2E4\uD328: ${err.message}`));
|
|
52
|
-
|
|
52
|
+
resolve2(1);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
};
|
|
@@ -93,7 +93,7 @@ var initCommand = new Command("init").description("Transight Design System \uBC8
|
|
|
93
93
|
dryRun: options.dryRun
|
|
94
94
|
});
|
|
95
95
|
if (code === 0 && !options.dryRun) {
|
|
96
|
-
const agentInstruction =
|
|
96
|
+
const agentInstruction = '\uB8E8\uD2B8 \uC5D0\uC774\uC804\uD2B8 \uC9C0\uC2DC \uD30C\uC77C(AGENTS.md/AGENT.md/CLAUDE.md/.cursor/rules)\uC5D0 "UI \uC791\uC5C5 \uC804 transight-design.AGENT.md\uB97C \uBC18\uB4DC\uC2DC \uC77D\uACE0 \uB530\uB978\uB2E4"\uB97C \uCD94\uAC00\uD574\uC918';
|
|
97
97
|
console.log("");
|
|
98
98
|
console.log(pc2.green("\u2713 \uC124\uCE58 \uC644\uB8CC"));
|
|
99
99
|
console.log("");
|
|
@@ -101,7 +101,7 @@ var initCommand = new Command("init").description("Transight Design System \uBC8
|
|
|
101
101
|
console.log("");
|
|
102
102
|
console.log(" " + pc2.cyan(pc2.bold(agentInstruction)));
|
|
103
103
|
console.log("");
|
|
104
|
-
console.log(pc2.dim("(\
|
|
104
|
+
console.log(pc2.dim("(\uC5D0\uC774\uC804\uD2B8\uAC00 \uD56D\uC0C1 \uC77D\uB294 \uD504\uB85C\uC81D\uD2B8 \uADDC\uCE59 \uD30C\uC77C\uC5D0 \uB514\uC790\uC778 \uC2DC\uC2A4\uD15C \uCC38\uC870\uB97C \uACE0\uC815\uD569\uB2C8\uB2E4)"));
|
|
105
105
|
console.log("");
|
|
106
106
|
}
|
|
107
107
|
process.exit(code);
|
|
@@ -134,11 +134,95 @@ var listCommand = new Command3("list").description("\uC0AC\uC6A9 \uAC00\uB2A5\uD
|
|
|
134
134
|
process.exit(code);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
// src/commands/
|
|
137
|
+
// src/commands/update.ts
|
|
138
|
+
import { access, mkdir, writeFile } from "fs/promises";
|
|
139
|
+
import { dirname, resolve, sep } from "path";
|
|
138
140
|
import { Command as Command4 } from "commander";
|
|
139
141
|
import pc5 from "picocolors";
|
|
140
|
-
var
|
|
141
|
-
|
|
142
|
+
var DEFAULT_REF = "main";
|
|
143
|
+
var itemUrl = (name, ref) => {
|
|
144
|
+
const [owner, repo] = GITHUB_REPO.split("/");
|
|
145
|
+
const resolvedRef = ref ?? DEFAULT_REF;
|
|
146
|
+
return `https://raw.githubusercontent.com/${owner}/${repo}/${resolvedRef}/packages/ui/public/r/${name}.json`;
|
|
147
|
+
};
|
|
148
|
+
var targetPathFor = (file) => {
|
|
149
|
+
const target = file.target ?? file.path;
|
|
150
|
+
if (!target) return null;
|
|
151
|
+
if (target.startsWith("~/")) return target.slice(2);
|
|
152
|
+
if (target.startsWith("./")) return target.slice(2);
|
|
153
|
+
return target;
|
|
154
|
+
};
|
|
155
|
+
var resolveInsideCwd = (relativeTarget) => {
|
|
156
|
+
const cwd = process.cwd();
|
|
157
|
+
const absolute = resolve(cwd, relativeTarget);
|
|
158
|
+
const cwdWithSeparator = cwd.endsWith(sep) ? cwd : `${cwd}${sep}`;
|
|
159
|
+
if (absolute !== cwd && !absolute.startsWith(cwdWithSeparator)) {
|
|
160
|
+
throw new Error(`\uD504\uB85C\uC81D\uD2B8 \uBC16 \uACBD\uB85C\uB294 \uC5C5\uB370\uC774\uD2B8\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${relativeTarget}`);
|
|
161
|
+
}
|
|
162
|
+
return absolute;
|
|
163
|
+
};
|
|
164
|
+
var ensureInstalled = async (absolutePath) => {
|
|
165
|
+
try {
|
|
166
|
+
await access(absolutePath);
|
|
167
|
+
} catch {
|
|
168
|
+
throw new Error(`\uC124\uCE58\uB41C \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${absolutePath}`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var fetchRegistryItem = async (name, ref) => {
|
|
172
|
+
const url = itemUrl(name, ref);
|
|
173
|
+
const response = await fetch(url);
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
throw new Error(`registry item\uC744 \uAC00\uC838\uC624\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (${response.status}): ${url}`);
|
|
176
|
+
}
|
|
177
|
+
return await response.json();
|
|
178
|
+
};
|
|
179
|
+
var updateCommand = new Command4("update").description("\uC774\uBBF8 \uC124\uCE58\uB41C \uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uB9CC \uC5C5\uB370\uC774\uD2B8 (dependencies/styles\uB294 \uB36E\uC5B4\uC4F0\uC9C0 \uC54A\uC74C)").argument("<components...>", "\uC5C5\uB370\uC774\uD2B8\uD560 \uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984\uB4E4").option("--dry-run", "\uC2E4\uD589\uD558\uC9C0 \uC54A\uACE0 \uBCC0\uACBD \uB300\uC0C1\uB9CC \uCD9C\uB825", false).option("--ref <ref>", "GitHub \uB808\uD37C\uB7F0\uC2A4 (\uBE0C\uB79C\uCE58\xB7\uD0DC\uADF8\xB7SHA)").action(async (components, options) => {
|
|
180
|
+
if (components.length === 0) {
|
|
181
|
+
console.error(pc5.red("\uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984\uC744 \uD558\uB098 \uC774\uC0C1 \uC9C0\uC815\uD574\uC8FC\uC138\uC694."));
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
console.log(
|
|
185
|
+
pc5.bold(pc5.cyan("Transight Design System")) + ` \u2014 update ${pc5.yellow(components.join(", "))}`
|
|
186
|
+
);
|
|
187
|
+
try {
|
|
188
|
+
for (const component of components) {
|
|
189
|
+
const item = await fetchRegistryItem(component, options.ref);
|
|
190
|
+
const files = item.files ?? [];
|
|
191
|
+
if (files.length === 0) {
|
|
192
|
+
throw new Error(`\uC5C5\uB370\uC774\uD2B8\uD560 \uD30C\uC77C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${component}`);
|
|
193
|
+
}
|
|
194
|
+
for (const file of files) {
|
|
195
|
+
if (typeof file.content !== "string") {
|
|
196
|
+
throw new Error(`registry item\uC5D0 content\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4: ${component}`);
|
|
197
|
+
}
|
|
198
|
+
const target = targetPathFor(file);
|
|
199
|
+
if (!target) {
|
|
200
|
+
throw new Error(`target \uACBD\uB85C\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4: ${component}`);
|
|
201
|
+
}
|
|
202
|
+
const absoluteTarget = resolveInsideCwd(target);
|
|
203
|
+
await ensureInstalled(absoluteTarget);
|
|
204
|
+
if (options.dryRun) {
|
|
205
|
+
console.log(pc5.dim("[dry-run] ") + pc5.cyan(`${component} -> ${target}`));
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
await mkdir(dirname(absoluteTarget), { recursive: true });
|
|
209
|
+
await writeFile(absoluteTarget, file.content, "utf-8");
|
|
210
|
+
console.log(pc5.green("updated ") + target);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
process.exit(0);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
216
|
+
console.error(pc5.red(message));
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// src/commands/view.ts
|
|
222
|
+
import { Command as Command5 } from "commander";
|
|
223
|
+
import pc6 from "picocolors";
|
|
224
|
+
var viewCommand = new Command5("view").description("\uCEF4\uD3EC\uB10C\uD2B8 \uC815\uBCF4 \uBBF8\uB9AC \uBCF4\uAE30 (\uC124\uCE58 \uC548 \uD568)").argument("<component>", "\uC870\uD68C\uD560 \uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984").option("--dry-run", "\uC2E4\uD589\uD558\uC9C0 \uC54A\uACE0 \uD638\uCD9C\uD560 \uBA85\uB839\uB9CC \uCD9C\uB825", false).option("--ref <ref>", "GitHub \uB808\uD37C\uB7F0\uC2A4").action(async (component, options) => {
|
|
225
|
+
console.log(pc6.bold(pc6.cyan("Transight Design System")) + ` \u2014 view ${pc6.yellow(component)}`);
|
|
142
226
|
const code = await runShadcn(["view", githubAddress(component, options.ref)], {
|
|
143
227
|
dryRun: options.dryRun
|
|
144
228
|
});
|
|
@@ -146,8 +230,8 @@ var viewCommand = new Command4("view").description("\uCEF4\uD3EC\uB10C\uD2B8 \uC
|
|
|
146
230
|
});
|
|
147
231
|
|
|
148
232
|
// src/commands/variant.ts
|
|
149
|
-
import { Command as
|
|
150
|
-
import
|
|
233
|
+
import { Command as Command6 } from "commander";
|
|
234
|
+
import pc7 from "picocolors";
|
|
151
235
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
152
236
|
import { join } from "path";
|
|
153
237
|
var STYLE_AXES = ["color", "theme", "shape", "size"];
|
|
@@ -213,7 +297,7 @@ ${after}`;
|
|
|
213
297
|
return `${trimmedBefore}${needsComma ? "," : ""}
|
|
214
298
|
${line}${after}`;
|
|
215
299
|
};
|
|
216
|
-
var variantCommand = new
|
|
300
|
+
var variantCommand = new Command6("variant").description(
|
|
217
301
|
"\uCEF4\uD3EC\uB10C\uD2B8\uC758 variant preset \uAD00\uB9AC (\uD604\uC7AC: add)"
|
|
218
302
|
);
|
|
219
303
|
variantCommand.command("add").description(
|
|
@@ -221,19 +305,19 @@ variantCommand.command("add").description(
|
|
|
221
305
|
).requiredOption("--component <name>", "\uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984 (\uC608: button)").requiredOption("--name <name>", "\uCD94\uAC00\uD560 variant \uC774\uB984 (\uC608: my-brand)").option("--color <value>", "color (gray/blue/red/orange/yellow/olive/green/skyblue/purple/pink/white/gradient-blue)").option("--theme <value>", "theme (solid/outline/soft)").option("--shape <value>", "shape (default/pill/square)").option("--size <value>", "size (xs/sm/md/lg/xl)").option("--path <path>", "\uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C \uACBD\uB85C override (\uAE30\uBCF8: src/components/{base|custom}/<X>.tsx)").option("--dry-run", "\uC2E4\uC81C \uD30C\uC77C\uC744 \uC4F0\uC9C0 \uC54A\uACE0 \uACB0\uACFC\uB9CC \uCD9C\uB825", false).action(async (options) => {
|
|
222
306
|
const { component, name, path, dryRun } = options;
|
|
223
307
|
if (!component || !name) {
|
|
224
|
-
console.error(
|
|
308
|
+
console.error(pc7.red("--component\uC640 --name\uC740 \uD544\uC218\uC785\uB2C8\uB2E4."));
|
|
225
309
|
process.exit(1);
|
|
226
310
|
}
|
|
227
311
|
if (!STYLE_AXES.some((axis) => options[axis])) {
|
|
228
312
|
console.error(
|
|
229
|
-
|
|
313
|
+
pc7.red("color / theme / shape / size \uC911 \uCD5C\uC18C \uD55C \uCD95\uC740 \uC9C0\uC815\uD574\uC57C \uC758\uBBF8 \uC788\uB294 variant\uC785\uB2C8\uB2E4.")
|
|
230
314
|
);
|
|
231
315
|
process.exit(1);
|
|
232
316
|
}
|
|
233
317
|
const filePath = resolveComponentPath(component, path);
|
|
234
318
|
if (!filePath) {
|
|
235
319
|
console.error(
|
|
236
|
-
|
|
320
|
+
pc7.red(
|
|
237
321
|
`\uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uC744 \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${component}
|
|
238
322
|
\uAE30\uBCF8 \uACBD\uB85C: src/components/base/${component}.tsx \uB610\uB294 src/components/custom/${component}.tsx
|
|
239
323
|
--path <\uACBD\uB85C>\uB85C \uC9C1\uC811 \uC9C0\uC815 \uAC00\uB2A5\uD569\uB2C8\uB2E4.`
|
|
@@ -251,7 +335,7 @@ variantCommand.command("add").description(
|
|
|
251
335
|
const next = insertPresetLine(source, component, line);
|
|
252
336
|
if (!next) {
|
|
253
337
|
console.error(
|
|
254
|
-
|
|
338
|
+
pc7.red(
|
|
255
339
|
`${component}VariantPresets \uAC1D\uCCB4\uB97C ${filePath}\uC5D0\uC11C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.
|
|
256
340
|
\uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uC5D0 variant preset \uC2AC\uB86F\uC774 \uC815\uC758\uB418\uC5B4 \uC788\uB294\uC9C0 \uD655\uC778\uD558\uC138\uC694.`
|
|
257
341
|
)
|
|
@@ -259,25 +343,26 @@ variantCommand.command("add").description(
|
|
|
259
343
|
process.exit(1);
|
|
260
344
|
}
|
|
261
345
|
console.log(
|
|
262
|
-
|
|
346
|
+
pc7.bold(pc7.cyan("Transight Design System")) + ` \u2014 variant add ${pc7.yellow(`${component}.${name}`)}`
|
|
263
347
|
);
|
|
264
|
-
console.log(
|
|
265
|
-
console.log(
|
|
348
|
+
console.log(pc7.dim(` \uD30C\uC77C: ${filePath}`));
|
|
349
|
+
console.log(pc7.dim(` \uCD94\uAC00 \uB77C\uC778:`));
|
|
266
350
|
console.log(` ${line}`);
|
|
267
351
|
if (dryRun) {
|
|
268
|
-
console.log(
|
|
352
|
+
console.log(pc7.yellow("\n[dry-run] \uD30C\uC77C\uC744 \uC4F0\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4."));
|
|
269
353
|
return;
|
|
270
354
|
}
|
|
271
355
|
writeFileSync(filePath, next, "utf-8");
|
|
272
|
-
console.log(
|
|
356
|
+
console.log(pc7.green("\n\u2713 \uB4F1\uB85D \uC644\uB8CC. <" + capitalize(component) + ` variant="${name}" />\uB85C \uC0AC\uC6A9\uD558\uC138\uC694.`));
|
|
273
357
|
});
|
|
274
358
|
var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
275
359
|
|
|
276
360
|
// src/index.ts
|
|
277
|
-
var program = new
|
|
361
|
+
var program = new Command7();
|
|
278
362
|
program.name("transight-design").description("Transight Design System CLI (shadcn \uC704\uC784 \uB798\uD37C)").version("0.0.0");
|
|
279
363
|
program.addCommand(initCommand);
|
|
280
364
|
program.addCommand(addCommand);
|
|
365
|
+
program.addCommand(updateCommand);
|
|
281
366
|
program.addCommand(listCommand);
|
|
282
367
|
program.addCommand(viewCommand);
|
|
283
368
|
program.addCommand(variantCommand);
|