-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathcli.ts
119 lines (115 loc) · 2.82 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env node
import { defineCommand, runMain } from "citty";
import { resolve } from "pathe";
import { name, version, description } from "../package.json";
import { mkdist, MkdistOptions } from "./index";
const main = defineCommand({
meta: {
name,
version,
description,
},
args: {
dir: {
type: "positional",
description: "Project root directory",
default: ".",
},
cwd: {
type: "string",
description: "Current working directory",
},
src: {
type: "string",
description: "Source directory relative to project root directory",
default: "src",
},
dist: {
type: "string",
description: "Destination directory relative to project root directory",
default: "dist",
},
clean: {
type: "boolean",
description: "Clean the destination directory",
default: true,
},
pattern: {
type: "string",
description: "Pattern includes or excludes files",
default: "**",
},
format: {
type: "string",
description: "File format",
valueHint: "cjs|esm",
},
declaration: {
type: "boolean",
description: "Generate type declaration file",
default: false,
alias: ["d"],
},
ext: {
type: "string",
description: "File extension",
valueHint: "mjs|js|ts",
},
jsx: {
type: "string",
description: "Specify which JSX runtime to use",
valueHint: "transform|preserve|automatic",
},
jsxFactory: {
type: "string",
description: "JSX factory",
valueHint: "h|React.createElement",
},
jsxFragment: {
type: "string",
description: "JSX fragment",
valueHint: "Fragment|React.Fragment",
},
loaders: {
type: "string",
description: "Loaders",
valueHint: "js|vue|sass",
},
minify: {
type: "boolean",
description: "Minify output files",
default: false,
},
target: {
type: "string",
description: "Target environment (esbuild)",
},
},
async run({ args }) {
const { writtenFiles } = await mkdist({
rootDir: resolve(args.cwd || process.cwd(), args.dir),
srcDir: args.src,
distDir: args.dist,
cleanDist: args.clean,
format: args.format,
pattern: args.pattern,
ext: args.ext,
declaration: args.declaration,
loaders: args.loaders?.split(","),
esbuild: {
jsx: args.jsx,
jsxFactory: args.jsxFactory,
jsxFragment: args.jsxFragment,
minify: args.minify,
target: args.target,
},
} as MkdistOptions);
console.log(writtenFiles.map((f) => `- ${f}`).join("\n"));
process.exit(0);
},
});
// eslint-disable-next-line unicorn/prefer-top-level-await
runMain(main).catch((error) => {
console.error(error);
process.exit(1);
});