@transight-design/cli 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +132 -3
  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 Command5 } from "commander";
4
+ import { Command as Command6 } from "commander";
5
5
 
6
6
  // src/commands/init.ts
7
7
  import { Command } from "commander";
@@ -61,7 +61,7 @@ var initCommand = new Command("init").description("Transight Design System \uC80
61
61
  // src/commands/add.ts
62
62
  import { Command as Command2 } from "commander";
63
63
  import pc3 from "picocolors";
64
- var addCommand = new Command2("add").description("\uCEF4\uD3EC\uB10C\uD2B8 \uCD94\uAC00 (\uC608: transight-design add button card dialog)").argument("<components...>", "\uC124\uCE58\uD560 \uCEF4\uD3EC\uB10C\uD2B8 \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) => {
64
+ 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) => {
65
65
  if (components.length === 0) {
66
66
  console.error(pc3.red("\uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984\uC744 \uD558\uB098 \uC774\uC0C1 \uC9C0\uC815\uD574\uC8FC\uC138\uC694."));
67
67
  process.exit(1);
@@ -94,13 +94,142 @@ var viewCommand = new Command4("view").description("\uCEF4\uD3EC\uB10C\uD2B8 \uC
94
94
  process.exit(code);
95
95
  });
96
96
 
97
+ // src/commands/variant.ts
98
+ import { Command as Command5 } from "commander";
99
+ import pc6 from "picocolors";
100
+ import { existsSync, readFileSync, writeFileSync } from "fs";
101
+ import { join } from "path";
102
+ var STYLE_AXES = ["color", "theme", "shape", "size"];
103
+ var resolveComponentPath = (component, override) => {
104
+ if (override) {
105
+ const abs = join(process.cwd(), override);
106
+ return existsSync(abs) ? abs : null;
107
+ }
108
+ const candidates = [
109
+ join(process.cwd(), "src", "components", "base", `${component}.tsx`),
110
+ join(process.cwd(), "src", "components", "custom", `${component}.tsx`),
111
+ join(process.cwd(), "packages", "ui", "src", "components", `${component}.tsx`)
112
+ ];
113
+ return candidates.find((p) => existsSync(p)) ?? null;
114
+ };
115
+ var findPresetObjectRange = (source, component) => {
116
+ const re = /([A-Za-z_$][\w$]*)VariantPresets\s*=\s*\{/g;
117
+ let match;
118
+ while ((match = re.exec(source)) !== null) {
119
+ const startBrace = match.index + match[0].length - 1;
120
+ let depth = 1;
121
+ let i = startBrace + 1;
122
+ let inString = null;
123
+ while (depth > 0 && i < source.length) {
124
+ const c = source[i];
125
+ if (inString) {
126
+ if (c === inString && source[i - 1] !== "\\") inString = null;
127
+ } else if (c === '"' || c === "'" || c === "`") {
128
+ inString = c;
129
+ } else if (c === "{") {
130
+ depth++;
131
+ } else if (c === "}") {
132
+ depth--;
133
+ }
134
+ i++;
135
+ }
136
+ if (depth === 0) {
137
+ return { startBrace, endBrace: i - 1 };
138
+ }
139
+ }
140
+ return null;
141
+ };
142
+ var buildNewPresetLine = (name, styles) => {
143
+ const parts = [];
144
+ for (const axis of STYLE_AXES) {
145
+ const value = styles[axis];
146
+ if (value) parts.push(`${axis}: '${value}'`);
147
+ }
148
+ return ` '${name}': { ${parts.join(", ")} }`;
149
+ };
150
+ var insertPresetLine = (source, component, line) => {
151
+ const range = findPresetObjectRange(source, component);
152
+ if (!range) return null;
153
+ const before = source.slice(0, range.endBrace);
154
+ const after = source.slice(range.endBrace);
155
+ const trimmedBefore = before.trimEnd();
156
+ const needsComma = !trimmedBefore.endsWith(",") && !trimmedBefore.endsWith("{");
157
+ if (trimmedBefore.endsWith("{")) {
158
+ return `${trimmedBefore}
159
+ ${line}
160
+ ${after}`;
161
+ }
162
+ return `${trimmedBefore}${needsComma ? "," : ""}
163
+ ${line}${after}`;
164
+ };
165
+ var variantCommand = new Command5("variant").description(
166
+ "\uCEF4\uD3EC\uB10C\uD2B8\uC758 variant preset \uAD00\uB9AC (\uD604\uC7AC: add)"
167
+ );
168
+ variantCommand.command("add").description(
169
+ "\uC0C8 variant\uB97C \uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uC758 <X>VariantPresets \uAC1D\uCCB4\uC5D0 \uD55C \uC904\uB85C \uCD94\uAC00. Style 4\uCD95(color/theme/shape/size)\uB9CC \uBC1B\uC74C. \uBBF8\uBA85\uC2DC \uCD95\uC740 cva default\uB85C \uC790\uB3D9."
170
+ ).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) => {
171
+ const { component, name, path, dryRun } = options;
172
+ if (!component || !name) {
173
+ console.error(pc6.red("--component\uC640 --name\uC740 \uD544\uC218\uC785\uB2C8\uB2E4."));
174
+ process.exit(1);
175
+ }
176
+ if (!STYLE_AXES.some((axis) => options[axis])) {
177
+ console.error(
178
+ pc6.red("color / theme / shape / size \uC911 \uCD5C\uC18C \uD55C \uCD95\uC740 \uC9C0\uC815\uD574\uC57C \uC758\uBBF8 \uC788\uB294 variant\uC785\uB2C8\uB2E4.")
179
+ );
180
+ process.exit(1);
181
+ }
182
+ const filePath = resolveComponentPath(component, path);
183
+ if (!filePath) {
184
+ console.error(
185
+ pc6.red(
186
+ `\uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uC744 \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${component}
187
+ \uAE30\uBCF8 \uACBD\uB85C: src/components/base/${component}.tsx \uB610\uB294 src/components/custom/${component}.tsx
188
+ --path <\uACBD\uB85C>\uB85C \uC9C1\uC811 \uC9C0\uC815 \uAC00\uB2A5\uD569\uB2C8\uB2E4.`
189
+ )
190
+ );
191
+ process.exit(1);
192
+ }
193
+ const source = readFileSync(filePath, "utf-8");
194
+ const styles = {};
195
+ for (const axis of STYLE_AXES) {
196
+ const value = options[axis];
197
+ if (value) styles[axis] = value;
198
+ }
199
+ const line = buildNewPresetLine(name, styles);
200
+ const next = insertPresetLine(source, component, line);
201
+ if (!next) {
202
+ console.error(
203
+ pc6.red(
204
+ `${component}VariantPresets \uAC1D\uCCB4\uB97C ${filePath}\uC5D0\uC11C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.
205
+ \uCEF4\uD3EC\uB10C\uD2B8 \uD30C\uC77C\uC5D0 variant preset \uC2AC\uB86F\uC774 \uC815\uC758\uB418\uC5B4 \uC788\uB294\uC9C0 \uD655\uC778\uD558\uC138\uC694.`
206
+ )
207
+ );
208
+ process.exit(1);
209
+ }
210
+ console.log(
211
+ pc6.bold(pc6.cyan("Transight Design System")) + ` \u2014 variant add ${pc6.yellow(`${component}.${name}`)}`
212
+ );
213
+ console.log(pc6.dim(` \uD30C\uC77C: ${filePath}`));
214
+ console.log(pc6.dim(` \uCD94\uAC00 \uB77C\uC778:`));
215
+ console.log(` ${line}`);
216
+ if (dryRun) {
217
+ console.log(pc6.yellow("\n[dry-run] \uD30C\uC77C\uC744 \uC4F0\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4."));
218
+ return;
219
+ }
220
+ writeFileSync(filePath, next, "utf-8");
221
+ console.log(pc6.green("\n\u2713 \uB4F1\uB85D \uC644\uB8CC. <" + capitalize(component) + ` variant="${name}" />\uB85C \uC0AC\uC6A9\uD558\uC138\uC694.`));
222
+ });
223
+ var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
224
+
97
225
  // src/index.ts
98
- var program = new Command5();
226
+ var program = new Command6();
99
227
  program.name("transight-design").description("Transight Design System CLI (shadcn \uC704\uC784 \uB798\uD37C)").version("0.0.0");
100
228
  program.addCommand(initCommand);
101
229
  program.addCommand(addCommand);
102
230
  program.addCommand(listCommand);
103
231
  program.addCommand(viewCommand);
232
+ program.addCommand(variantCommand);
104
233
  program.parseAsync(process.argv).catch((err) => {
105
234
  console.error(err);
106
235
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transight-design/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Transight Design System CLI — thin wrapper around `shadcn`",
5
5
  "license": "MIT",
6
6
  "type": "module",