-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathcli.ts
96 lines (89 loc) · 2.17 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
#!/usr/bin/env node
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import { run } from './run';
const yarg = yargs(hideBin(process.argv))
.usage('Create .css.d.ts from CSS modules *.css files.\nUsage: $0 [options] <search directory>')
.example('$0 src/styles', '')
.example('$0 src -o dist', '')
.example('$0 -p styles/**/*.css -w', '')
.detectLocale(false)
.demand(['_'])
.options({
p: {
desc: 'Glob pattern with css files',
type: 'string',
alias: 'pattern',
},
o: {
desc: 'Output directory',
type: 'string',
alias: 'outDir',
},
l: {
desc: 'List any files that are different than those that would be generated. If any are different, exit with a status code 1.',
type: 'boolean',
alias: 'listDifferent',
},
w: {
desc: "Watch input directory's css files or pattern",
type: 'boolean',
alias: 'watch',
},
c: {
desc: "Watch input directory's css files or pattern",
type: 'boolean',
alias: 'camelCase',
},
e: {
type: 'boolean',
desc: 'Use named exports as opposed to default exports to enable tree shaking.',
alias: 'namedExports',
},
d: {
type: 'boolean',
desc: "'Drop the input files extension'",
alias: 'dropExtension',
},
s: {
type: 'boolean',
alias: 'silent',
desc: 'Silent output. Do not show "files written" messages',
},
f: {
desc: "Follow symlinks",
type: 'boolean',
alias: 'followSymlinks',
},
})
.alias('h', 'help')
.help('h')
.version(require('../package.json').version);
main();
async function main(): Promise<void> {
const argv = await yarg.argv;
if (argv.h) {
yarg.showHelp();
return;
}
let searchDir: string;
if (argv._ && argv._[0]) {
searchDir = `${argv._[0]}`;
} else if (argv.p) {
searchDir = './';
} else {
yarg.showHelp();
return;
}
await run(searchDir, {
pattern: argv.p,
outDir: argv.o,
watch: argv.w,
camelCase: argv.c,
namedExports: argv.e,
dropExtension: argv.d,
silent: argv.s,
listDifferent: argv.l,
followSymlinks: argv.f,
});
}