|
1 | 1 | import Scaffold from "./scaffold" |
2 | | -import args from "args" |
| 2 | +import massarg from "massarg" |
3 | 3 | import { ScaffoldCmdConfig } from "./types" |
4 | 4 |
|
5 | | -const options = args |
6 | | - .command("", "") |
7 | | - .option( |
8 | | - ["n", "name"], |
9 | | - "Name to be passed to the generated files. {{name}} and {{Name}} inside contents and file names will be replaced accordingly." |
10 | | - ) |
11 | | - .option( |
12 | | - ["o", "output"], |
13 | | - "Path to output to. If --create-sub-folder is enabled, the subfolder will be created inside this path." |
14 | | - ) |
15 | | - .option( |
16 | | - ["t", "templates"], |
17 | | - "Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path, " + |
| 5 | +massarg<ScaffoldCmdConfig & { help: boolean; extras: string[] }>() |
| 6 | + .main(Scaffold) |
| 7 | + .option({ |
| 8 | + name: "name", |
| 9 | + aliases: ["n"], |
| 10 | + isDefault: true, |
| 11 | + description: |
| 12 | + "Name to be passed to the generated files. {{name}} and {{Name}} inside contents and file names will be replaced accordingly.", |
| 13 | + }) |
| 14 | + .option({ |
| 15 | + name: "output", |
| 16 | + aliases: ["o"], |
| 17 | + description: |
| 18 | + "Path to output to. If --create-sub-folder is enabled, the subfolder will be created inside this path.", |
| 19 | + }) |
| 20 | + .option({ |
| 21 | + name: "templates", |
| 22 | + aliases: ["t"], |
| 23 | + description: |
| 24 | + "Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path, " + |
18 | 25 | "or a glob pattern for multiple file matching easily.", |
19 | | - [] |
20 | | - ) |
21 | | - .option(["w", "overwrite"], "Enable to override output files, even if they already exist.", false) |
22 | | - .option( |
23 | | - ["d", "data"], |
24 | | - "Add custom data to the templates. By default, only your app name is included.", |
25 | | - undefined, |
26 | | - JSON.parse |
27 | | - ) |
28 | | - .option(["s", "create-sub-folder"], "Create subfolder with the input name", false) |
29 | | - .option(["q", "silent"], "Supress output logs", false) |
30 | | - .option( |
31 | | - ["d", "dry-run"], |
32 | | - "Don't emit actual files. This is good for testing your scaffolds and making sure they " + |
| 26 | + defaultValue: [], |
| 27 | + array: true, |
| 28 | + }) |
| 29 | + .option({ |
| 30 | + aliases: ["w"], |
| 31 | + name: "overwrite", |
| 32 | + description: "Enable to override output files, even if they already exist.", |
| 33 | + defaultValue: false, |
| 34 | + boolean: true, |
| 35 | + }) |
| 36 | + .option({ |
| 37 | + aliases: ["d"], |
| 38 | + name: "data", |
| 39 | + description: "Add custom data to the templates. By default, only your app name is included.", |
| 40 | + parse: (v) => JSON.parse(v), |
| 41 | + }) |
| 42 | + .option({ |
| 43 | + aliases: ["s"], |
| 44 | + name: "create-sub-folder", |
| 45 | + description: "Create subfolder with the input name", |
| 46 | + defaultValue: false, |
| 47 | + boolean: true, |
| 48 | + }) |
| 49 | + .option({ aliases: ["q"], name: "quiet", description: "Supress output logs", defaultValue: false, boolean: true }) |
| 50 | + .option({ |
| 51 | + aliases: ["dr"], |
| 52 | + name: "dry-run", |
| 53 | + description: |
| 54 | + "Don't emit actual files. This is good for testing your scaffolds and making sure they " + |
33 | 55 | "don't fail, without having to write actual files.", |
34 | | - false |
35 | | - ) |
36 | | - .example( |
37 | | - `yarn cmd -t examples/test-input/Component -o examples/test-output -d '{"property":"myProp","value":"10"}'`, |
38 | | - "Usage" |
39 | | - ) |
40 | | - .parse(process.argv, { |
41 | | - value: "name", |
42 | | - mri: {}, |
43 | | - mainColor: "yellow", |
44 | | - subColor: ["dim"], |
45 | | - name: "simple-scaffold", |
46 | | - usageFilter: (usage: string) => { |
47 | | - usage = usage.replace("[options] [command] ", "").replace("name", "[options] name") |
48 | | - const lines = usage.split("\n") |
49 | | - usage = [ |
50 | | - ...lines.slice( |
51 | | - 0, |
52 | | - lines.findIndex((l) => l.startsWith(" Commands:")) |
53 | | - ), |
54 | | - ...lines.slice(lines.findIndex((l) => l.startsWith(" Options:"))), |
55 | | - ].join("\n") |
56 | | - return usage |
57 | | - }, |
58 | | - }) as ScaffoldCmdConfig |
59 | | - |
60 | | -Scaffold(options) |
| 56 | + defaultValue: false, |
| 57 | + boolean: true, |
| 58 | + }) |
| 59 | + // .example( |
| 60 | + // `yarn cmd -t examples/test-input/Component -o examples/test-output -d '{"property":"myProp","value":"10"}'`, |
| 61 | + // "Usage" |
| 62 | + // ) |
| 63 | + .help({ |
| 64 | + binName: "simple-scaffold", |
| 65 | + useGlobalColumns: true, |
| 66 | + usageExample: "[options]", |
| 67 | + }) |
| 68 | + .parse() |
| 69 | +// .parse(process.argv, { |
| 70 | +// value: "name", |
| 71 | +// mri: {}, |
| 72 | +// mainColor: "yellow", |
| 73 | +// subColor: ["dim"], |
| 74 | +// name: "simple-scaffold", |
| 75 | +// usageFilter: (usage: string) => { |
| 76 | +// usage = usage.replace("[options] [command] ", "").replace("name", "[options] name") |
| 77 | +// const lines = usage.split("\n") |
| 78 | +// usage = [ |
| 79 | +// ...lines.slice( |
| 80 | +// 0, |
| 81 | +// lines.findIndex((l) => l.startsWith(" Commands:")) |
| 82 | +// ), |
| 83 | +// ...lines.slice(lines.findIndex((l) => l.startsWith(" Options:"))), |
| 84 | +// ].join("\n") |
| 85 | +// return usage |
| 86 | +// }, |
| 87 | +// } |
| 88 | +// ) as ScaffoldCmdConfig |
0 commit comments