|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -import { fileURLToPath } from "node:url"; |
4 | | -import { dirname, resolve } from "node:path"; |
5 | | -import { spawn } from "node:child_process"; |
6 | | -import minimist from "minimist"; |
7 | | -import { red, green, cyan } from "kolorist"; |
8 | | - |
9 | | -const __dirname = dirname(fileURLToPath(import.meta.url)); |
10 | | - |
11 | | -const argv = minimist(process.argv.slice(2), { |
12 | | - alias: { |
13 | | - h: "help", |
14 | | - v: "version", |
15 | | - }, |
16 | | -}); |
17 | | - |
18 | | -const helpMessage = ` |
19 | | -${green( |
20 | | - "create-halo-plugin" |
21 | | -)} - Quickly create Halo plugin development templates |
22 | | -
|
23 | | -${cyan("Usage:")} |
24 | | - create-halo-plugin [project-directory] [options] |
25 | | -
|
26 | | -${cyan("Options:")} |
27 | | - -h, --help Show help information |
28 | | - -v, --version Show version information |
29 | | -
|
30 | | -${cyan("Examples:")} |
31 | | - create-halo-plugin # Create in plugin-{name} directory |
32 | | - create-halo-plugin my-plugin # Create in my-plugin directory |
33 | | - create-halo-plugin ./my-awesome-plugin # Create in specified path |
34 | | - npx create-halo-plugin my-plugin |
35 | | -`; |
36 | | - |
37 | | -async function main() { |
38 | | - if (argv.help) { |
39 | | - console.log(helpMessage); |
40 | | - process.exit(0); |
41 | | - } |
42 | | - |
43 | | - if (argv.version) { |
44 | | - const pkg = await import("./package.json", { with: { type: "json" } }); |
45 | | - console.log(pkg.default.version); |
46 | | - process.exit(0); |
47 | | - } |
48 | | - |
49 | | - try { |
50 | | - // Pass all arguments to the main script |
51 | | - const indexPath = resolve(__dirname, "./src/index.js"); |
52 | | - const child = spawn("node", [indexPath, ...process.argv.slice(2)], { |
53 | | - stdio: "inherit", |
54 | | - }); |
55 | | - |
56 | | - child.on("exit", (code) => { |
57 | | - process.exit(code || 0); |
58 | | - }); |
59 | | - |
60 | | - child.on("error", (error) => { |
61 | | - console.error(red("Error occurred:"), error.message); |
62 | | - process.exit(1); |
63 | | - }); |
64 | | - } catch (error) { |
65 | | - console.error(red("Creation failed:"), error.message); |
66 | | - process.exit(1); |
67 | | - } |
68 | | -} |
69 | | - |
70 | | -main().catch((error) => { |
71 | | - console.error(red("Error occurred:"), error); |
72 | | - process.exit(1); |
73 | | -}); |
| 3 | +import "./src/index.js"; |
0 commit comments