@transight-design/cli 0.2.3 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +109 -22
  2. 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 Command6 } from "commander";
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((resolve) => {
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) => resolve(code ?? 0));
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
- resolve(1);
52
+ resolve2(1);
53
53
  });
54
54
  });
55
55
  };
@@ -110,7 +110,7 @@ var initCommand = new Command("init").description("Transight Design System \uBC8
110
110
  // src/commands/add.ts
111
111
  import { Command as Command2 } from "commander";
112
112
  import pc3 from "picocolors";
113
- var addCommand = new Command2("add").description("\uCEF4\uD3EC\uB10C\uD2B8/\uD329 \uCD94\uAC00 (\uC608: transight-design add essential \uB610\uB294 button card dialog)").argument("<components...>", "\uC124\uCE58\uD560 \uCEF4\uD3EC\uB10C\uD2B8 \uB610\uB294 \uD329 \uC774\uB984\uB4E4").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 (\uBE0C\uB79C\uCE58\xB7\uD0DC\uADF8\xB7SHA)").action(async (components, options) => {
113
+ var addCommand = new Command2("add").description("\uCEF4\uD3EC\uB10C\uD2B8/\uD329 \uCD94\uAC00 (\uC608: transight-design add essential \uB610\uB294 button card dialog)").argument("<components...>", "\uC124\uCE58\uD560 \uCEF4\uD3EC\uB10C\uD2B8 \uB610\uB294 \uD329 \uC774\uB984\uB4E4").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 (\uBE0C\uB79C\uCE58\xB7\uD0DC\uADF8\xB7SHA)").option("--overwrite", "\uAE30\uC874 \uD30C\uC77C\uC744 prompt \uC5C6\uC774 \uB36E\uC5B4\uC4F0\uAE30 (\uC5C5\uB370\uC774\uD2B8 \uC6A9)", false).action(async (components, options) => {
114
114
  if (components.length === 0) {
115
115
  console.error(pc3.red("\uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984\uC744 \uD558\uB098 \uC774\uC0C1 \uC9C0\uC815\uD574\uC8FC\uC138\uC694."));
116
116
  process.exit(1);
@@ -119,7 +119,9 @@ var addCommand = new Command2("add").description("\uCEF4\uD3EC\uB10C\uD2B8/\uD32
119
119
  console.log(
120
120
  pc3.bold(pc3.cyan("Transight Design System")) + ` \u2014 add ${pc3.yellow(components.join(", "))}`
121
121
  );
122
- const code = await runShadcn(["add", ...addresses], { dryRun: options.dryRun });
122
+ const args = ["add", ...addresses];
123
+ if (options.overwrite) args.push("--overwrite");
124
+ const code = await runShadcn(args, { dryRun: options.dryRun });
123
125
  process.exit(code);
124
126
  });
125
127
 
@@ -132,11 +134,95 @@ var listCommand = new Command3("list").description("\uC0AC\uC6A9 \uAC00\uB2A5\uD
132
134
  process.exit(code);
133
135
  });
134
136
 
135
- // src/commands/view.ts
137
+ // src/commands/update.ts
138
+ import { access, mkdir, writeFile } from "fs/promises";
139
+ import { dirname, resolve, sep } from "path";
136
140
  import { Command as Command4 } from "commander";
137
141
  import pc5 from "picocolors";
138
- var viewCommand = new Command4("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) => {
139
- console.log(pc5.bold(pc5.cyan("Transight Design System")) + ` \u2014 view ${pc5.yellow(component)}`);
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)}`);
140
226
  const code = await runShadcn(["view", githubAddress(component, options.ref)], {
141
227
  dryRun: options.dryRun
142
228
  });
@@ -144,8 +230,8 @@ var viewCommand = new Command4("view").description("\uCEF4\uD3EC\uB10C\uD2B8 \uC
144
230
  });
145
231
 
146
232
  // src/commands/variant.ts
147
- import { Command as Command5 } from "commander";
148
- import pc6 from "picocolors";
233
+ import { Command as Command6 } from "commander";
234
+ import pc7 from "picocolors";
149
235
  import { existsSync, readFileSync, writeFileSync } from "fs";
150
236
  import { join } from "path";
151
237
  var STYLE_AXES = ["color", "theme", "shape", "size"];
@@ -211,7 +297,7 @@ ${after}`;
211
297
  return `${trimmedBefore}${needsComma ? "," : ""}
212
298
  ${line}${after}`;
213
299
  };
214
- var variantCommand = new Command5("variant").description(
300
+ var variantCommand = new Command6("variant").description(
215
301
  "\uCEF4\uD3EC\uB10C\uD2B8\uC758 variant preset \uAD00\uB9AC (\uD604\uC7AC: add)"
216
302
  );
217
303
  variantCommand.command("add").description(
@@ -219,19 +305,19 @@ variantCommand.command("add").description(
219
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) => {
220
306
  const { component, name, path, dryRun } = options;
221
307
  if (!component || !name) {
222
- console.error(pc6.red("--component\uC640 --name\uC740 \uD544\uC218\uC785\uB2C8\uB2E4."));
308
+ console.error(pc7.red("--component\uC640 --name\uC740 \uD544\uC218\uC785\uB2C8\uB2E4."));
223
309
  process.exit(1);
224
310
  }
225
311
  if (!STYLE_AXES.some((axis) => options[axis])) {
226
312
  console.error(
227
- pc6.red("color / theme / shape / size \uC911 \uCD5C\uC18C \uD55C \uCD95\uC740 \uC9C0\uC815\uD574\uC57C \uC758\uBBF8 \uC788\uB294 variant\uC785\uB2C8\uB2E4.")
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.")
228
314
  );
229
315
  process.exit(1);
230
316
  }
231
317
  const filePath = resolveComponentPath(component, path);
232
318
  if (!filePath) {
233
319
  console.error(
234
- pc6.red(
320
+ pc7.red(
235
321
  `\uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uC744 \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${component}
236
322
  \uAE30\uBCF8 \uACBD\uB85C: src/components/base/${component}.tsx \uB610\uB294 src/components/custom/${component}.tsx
237
323
  --path <\uACBD\uB85C>\uB85C \uC9C1\uC811 \uC9C0\uC815 \uAC00\uB2A5\uD569\uB2C8\uB2E4.`
@@ -249,7 +335,7 @@ variantCommand.command("add").description(
249
335
  const next = insertPresetLine(source, component, line);
250
336
  if (!next) {
251
337
  console.error(
252
- pc6.red(
338
+ pc7.red(
253
339
  `${component}VariantPresets \uAC1D\uCCB4\uB97C ${filePath}\uC5D0\uC11C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.
254
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.`
255
341
  )
@@ -257,25 +343,26 @@ variantCommand.command("add").description(
257
343
  process.exit(1);
258
344
  }
259
345
  console.log(
260
- pc6.bold(pc6.cyan("Transight Design System")) + ` \u2014 variant add ${pc6.yellow(`${component}.${name}`)}`
346
+ pc7.bold(pc7.cyan("Transight Design System")) + ` \u2014 variant add ${pc7.yellow(`${component}.${name}`)}`
261
347
  );
262
- console.log(pc6.dim(` \uD30C\uC77C: ${filePath}`));
263
- console.log(pc6.dim(` \uCD94\uAC00 \uB77C\uC778:`));
348
+ console.log(pc7.dim(` \uD30C\uC77C: ${filePath}`));
349
+ console.log(pc7.dim(` \uCD94\uAC00 \uB77C\uC778:`));
264
350
  console.log(` ${line}`);
265
351
  if (dryRun) {
266
- console.log(pc6.yellow("\n[dry-run] \uD30C\uC77C\uC744 \uC4F0\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4."));
352
+ console.log(pc7.yellow("\n[dry-run] \uD30C\uC77C\uC744 \uC4F0\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4."));
267
353
  return;
268
354
  }
269
355
  writeFileSync(filePath, next, "utf-8");
270
- console.log(pc6.green("\n\u2713 \uB4F1\uB85D \uC644\uB8CC. <" + capitalize(component) + ` variant="${name}" />\uB85C \uC0AC\uC6A9\uD558\uC138\uC694.`));
356
+ console.log(pc7.green("\n\u2713 \uB4F1\uB85D \uC644\uB8CC. <" + capitalize(component) + ` variant="${name}" />\uB85C \uC0AC\uC6A9\uD558\uC138\uC694.`));
271
357
  });
272
358
  var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
273
359
 
274
360
  // src/index.ts
275
- var program = new Command6();
361
+ var program = new Command7();
276
362
  program.name("transight-design").description("Transight Design System CLI (shadcn \uC704\uC784 \uB798\uD37C)").version("0.0.0");
277
363
  program.addCommand(initCommand);
278
364
  program.addCommand(addCommand);
365
+ program.addCommand(updateCommand);
279
366
  program.addCommand(listCommand);
280
367
  program.addCommand(viewCommand);
281
368
  program.addCommand(variantCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transight-design/cli",
3
- "version": "0.2.3",
3
+ "version": "0.4.0",
4
4
  "description": "Transight Design System CLI — thin wrapper around `shadcn`",
5
5
  "license": "MIT",
6
6
  "type": "module",