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