-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathargs.js
145 lines (139 loc) · 4.42 KB
/
args.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict'
const chalk = require('chalk')
const logo = `
/|\\
// //
// //
//___*___*___//
//--*---------*--//
/|| * * ||/
// ||* *|| //
// || * * || //
//_____||___*_________*___||_____//
`
const cli = require('../package.json').version
const version = chalk.bold.red(`
/|\\
// //
// //
//___*___*___//
//--*---------*--//
/|| * * ||/
// ||* v${cli} *|| //
// || * * || //
//_____||___*_________*___||_____//
`)
module.exports = require('yargs')
.usage(
`${chalk.bold.red(logo)}
Usage:
$0 [input.css] [OPTIONS] [-o|--output output.css] [--watch|-w]
$0 <input.css>... [OPTIONS] --dir <output-directory> [--watch|-w]
$0 <input-directory> [OPTIONS] --dir <output-directory> [--watch|-w]
$0 <input-glob-pattern> [OPTIONS] --dir <output-directory> [--watch|-w]
$0 <input.css>... [OPTIONS] --replace`
)
.group(
['o', 'd', 'r', 'map', 'no-map', 'watch', 'verbose', 'env'],
'Basic options:'
)
.option('o', {
alias: 'output',
desc: 'Output file',
type: 'string',
conflicts: ['dir', 'replace'],
})
.option('d', {
alias: 'dir',
desc: 'Output directory',
type: 'string',
conflicts: ['output', 'replace'],
})
.option('r', {
alias: 'replace',
desc: 'Replace (overwrite) the input file',
type: 'boolean',
conflicts: ['output', 'dir'],
})
.alias('m', 'map')
.describe('map', 'Create an external sourcemap')
.describe('no-map', 'Disable the default inline sourcemaps')
.option('w', {
alias: 'watch',
desc: 'Watch files for changes and recompile as needed',
type: 'boolean',
conflicts: 'replace',
})
.option('verbose', {
desc: 'Be verbose',
type: 'boolean',
})
.option('env', {
desc: 'A shortcut for setting NODE_ENV',
type: 'string',
})
.group(
['u', 'parser', 'stringifier', 'syntax'],
'Options for use without a config file:'
)
.option('u', {
alias: 'use',
desc: 'List of postcss plugins to use',
type: 'array',
})
.option('parser', {
desc: 'Custom postcss parser',
type: 'string',
})
.option('stringifier', {
desc: 'Custom postcss stringifier',
type: 'string',
})
.option('syntax', {
desc: 'Custom postcss syntax',
type: 'string',
})
.group(['ext', 'base'], 'Options for use with --dir:')
.option('ext', {
desc: 'Override the output file extension; for use with --dir',
type: 'string',
implies: 'dir',
coerce(ext) {
if (ext.indexOf('.') !== 0) return `.${ext}`
return ext
},
})
.option('base', {
desc:
'Mirror the directory structure relative to this path in the output directory, for use with --dir',
type: 'string',
implies: 'dir',
})
.group(['include-dotfiles', 'poll', 'config'], 'Advanced options:')
.option('include-dotfiles', {
desc: 'Enable glob to match files/dirs that begin with "."',
type: 'boolean',
})
.option('poll', {
desc:
'Use polling for file watching. Can optionally pass polling interval; default 100 ms',
implies: 'watch',
})
.option('config', {
desc: 'Set a custom directory to look for a config file',
type: 'string',
})
.version(version)
.alias('h', 'help')
.example('$0 input.css -o output.css', 'Basic usage')
.example('$0 src/**/*.css --base src --dir build', 'Glob Pattern & output')
.example(
'cat input.css | $0 -u autoprefixer > output.css',
'Piping input & output'
)
.epilog(
`If no input files are passed, it reads from stdin. If neither -o, --dir, or --replace is passed, it writes to stdout.
If there are multiple input files, the --dir or --replace option must be passed.
Input files may contain globs (e.g. src/**/*.css). If you pass an input directory, it will process all files in the directory and any subdirectories, respecting the glob pattern.
For more details, please see https://github.com/postcss/postcss-cli`
).argv