@transight-design/cli 0.1.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 -0
- package/package.json +33 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command as Command5 } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands/init.ts
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
import pc2 from "picocolors";
|
|
9
|
+
|
|
10
|
+
// src/config.ts
|
|
11
|
+
var GITHUB_REPO = "traverse-corp/transight-design";
|
|
12
|
+
var BUNDLE_ITEM = "transight-design";
|
|
13
|
+
var githubAddress = (item, ref) => {
|
|
14
|
+
const base = `${GITHUB_REPO}/${item}`;
|
|
15
|
+
return ref ? `${base}#${ref}` : base;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/lib/runner.ts
|
|
19
|
+
import { spawn } from "child_process";
|
|
20
|
+
import pc from "picocolors";
|
|
21
|
+
var detectRunner = () => {
|
|
22
|
+
const ua = process.env.npm_config_user_agent ?? "";
|
|
23
|
+
if (ua.startsWith("pnpm")) return { cmd: "pnpm", prefix: ["dlx"] };
|
|
24
|
+
if (ua.startsWith("bun")) return { cmd: "bunx", prefix: ["--bun"] };
|
|
25
|
+
if (ua.startsWith("yarn")) return { cmd: "yarn", prefix: ["dlx"] };
|
|
26
|
+
return { cmd: "npx", prefix: [] };
|
|
27
|
+
};
|
|
28
|
+
var runShadcn = (args, options = {}) => {
|
|
29
|
+
const { cmd, prefix } = detectRunner();
|
|
30
|
+
const fullArgs = [...prefix, "shadcn@latest", ...args];
|
|
31
|
+
const display = `${cmd} ${fullArgs.join(" ")}`;
|
|
32
|
+
if (options.dryRun) {
|
|
33
|
+
console.log(pc.dim("[dry-run] ") + pc.cyan(display));
|
|
34
|
+
return Promise.resolve(0);
|
|
35
|
+
}
|
|
36
|
+
console.log(pc.dim("\u2192 ") + pc.cyan(display));
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
const proc = spawn(cmd, fullArgs, {
|
|
39
|
+
stdio: "inherit",
|
|
40
|
+
cwd: options.cwd ?? process.cwd(),
|
|
41
|
+
shell: process.platform === "win32"
|
|
42
|
+
});
|
|
43
|
+
proc.on("close", (code) => resolve(code ?? 0));
|
|
44
|
+
proc.on("error", (err) => {
|
|
45
|
+
console.error(pc.red(`shadcn \uC2E4\uD589 \uC2E4\uD328: ${err.message}`));
|
|
46
|
+
resolve(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/commands/init.ts
|
|
52
|
+
var initCommand = new Command("init").description("Transight Design System \uC804\uCCB4 \uBC88\uB4E4 \uC124\uCE58 (\uD1A0\uD070\xB7\uD3F0\uD2B8\xB7lib\xB7hooks\xB7\uCEF4\uD3EC\uB10C\uD2B8)").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 (options) => {
|
|
53
|
+
console.log(pc2.bold(pc2.cyan("Transight Design System")) + " \u2014 init");
|
|
54
|
+
const code = await runShadcn(
|
|
55
|
+
["add", githubAddress(BUNDLE_ITEM, options.ref)],
|
|
56
|
+
{ dryRun: options.dryRun }
|
|
57
|
+
);
|
|
58
|
+
process.exit(code);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// src/commands/add.ts
|
|
62
|
+
import { Command as Command2 } from "commander";
|
|
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) => {
|
|
65
|
+
if (components.length === 0) {
|
|
66
|
+
console.error(pc3.red("\uCEF4\uD3EC\uB10C\uD2B8 \uC774\uB984\uC744 \uD558\uB098 \uC774\uC0C1 \uC9C0\uC815\uD574\uC8FC\uC138\uC694."));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const addresses = components.map((name) => githubAddress(name, options.ref));
|
|
70
|
+
console.log(
|
|
71
|
+
pc3.bold(pc3.cyan("Transight Design System")) + ` \u2014 add ${pc3.yellow(components.join(", "))}`
|
|
72
|
+
);
|
|
73
|
+
const code = await runShadcn(["add", ...addresses], { dryRun: options.dryRun });
|
|
74
|
+
process.exit(code);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// src/commands/list.ts
|
|
78
|
+
import { Command as Command3 } from "commander";
|
|
79
|
+
import pc4 from "picocolors";
|
|
80
|
+
var listCommand = new Command3("list").description("\uC0AC\uC6A9 \uAC00\uB2A5\uD55C \uBAA8\uB4E0 \uCEF4\uD3EC\uB10C\uD2B8 \uBAA9\uB85D").option("--dry-run", "\uC2E4\uD589\uD558\uC9C0 \uC54A\uACE0 \uD638\uCD9C\uD560 \uBA85\uB839\uB9CC \uCD9C\uB825", false).action(async (options) => {
|
|
81
|
+
console.log(pc4.bold(pc4.cyan("Transight Design System")) + " \u2014 list");
|
|
82
|
+
const code = await runShadcn(["list", GITHUB_REPO], { dryRun: options.dryRun });
|
|
83
|
+
process.exit(code);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// src/commands/view.ts
|
|
87
|
+
import { Command as Command4 } from "commander";
|
|
88
|
+
import pc5 from "picocolors";
|
|
89
|
+
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) => {
|
|
90
|
+
console.log(pc5.bold(pc5.cyan("Transight Design System")) + ` \u2014 view ${pc5.yellow(component)}`);
|
|
91
|
+
const code = await runShadcn(["view", githubAddress(component, options.ref)], {
|
|
92
|
+
dryRun: options.dryRun
|
|
93
|
+
});
|
|
94
|
+
process.exit(code);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// src/index.ts
|
|
98
|
+
var program = new Command5();
|
|
99
|
+
program.name("transight-design").description("Transight Design System CLI (shadcn \uC704\uC784 \uB798\uD37C)").version("0.0.0");
|
|
100
|
+
program.addCommand(initCommand);
|
|
101
|
+
program.addCommand(addCommand);
|
|
102
|
+
program.addCommand(listCommand);
|
|
103
|
+
program.addCommand(viewCommand);
|
|
104
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
105
|
+
console.error(err);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@transight-design/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Transight Design System CLI — thin wrapper around `shadcn`",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"transight-design": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup src/index.ts --format esm --target node20 --clean --shims",
|
|
15
|
+
"dev": "tsx src/index.ts",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"clean": "rm -rf dist .turbo",
|
|
18
|
+
"prepublishOnly": "npm run typecheck && npm run build"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"commander": "^12.1.0",
|
|
25
|
+
"picocolors": "^1.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"tsup": "^8.3.0",
|
|
30
|
+
"tsx": "^4.19.0",
|
|
31
|
+
"typescript": "^5.6.0"
|
|
32
|
+
}
|
|
33
|
+
}
|