-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
cli.js
98 lines (93 loc) · 2.6 KB
/
cli.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
#!/usr/bin/env node
const yargs = require('yargs')
const ConvertTo = require('./dist')
const chalk = require('chalk')
const log = console.log
const error = (msg) => chalk.bold.bgRed('\n' + chalk.white(msg) + '\n')
const path = require('path')
const argv = yargs // eslint-disable-line
.usage('Usage: $0 -config [relative_path] -destination [relative_path]')
.option('config', {
alias: 'c',
describe: 'Tailwind config file path',
type: 'string', /* array | boolean | string */
nargs: 1,
demand: true
})
.option('destination', {
alias: 'd',
describe: 'Path to save Sass config file to',
type: 'string', /* array | boolean | string */
nargs: 1,
demand: true
})
.option('format', {
alias: 'f',
describe: 'Format to generate - sass,less,stylus',
type: 'string',
choices: ['sass', 'scss', 'less', 'styl', 'css', 'json'],
nargs: 1,
demand: true
})
.option('prefix', {
describe: 'variable prefix',
type: 'string', /* array | boolean | string */
nargs: 1
})
.option('flat', {
describe: 'Variable style (flat or nested map)',
type: 'boolean', /* array | boolean | string */
boolean: true,
nargs: 1
})
.option('quoted-keys', {
describe: 'Should map keys be quoted',
type: 'boolean', /* array | boolean | string */
boolean: true,
nargs: 1
})
.option('flatten-maps-after', {
describe: 'After which level, should deeply nested maps be flattened out. Defaults to -1 (always)',
type: 'number', /* array | boolean | string */
nargs: 1
})
.option('preserve-keys', {
describe: 'Keys to preserve',
type: 'array', /* array | boolean | string */
nargs: 1,
coerce: (array = []) => {
return array.flatMap(v => v.split(','))
}
})
.option('only-include-keys', {
describe: 'Keys to include exclusivly',
type: 'array', /* array | boolean | string */
nargs: 1,
coerce: (array = []) => {
return array.flatMap(v => v.split(','))
}
})
.argv
try {
const converter = new ConvertTo({
config: path.join(process.cwd(), argv.config),
destination: argv.destination,
format: argv.format,
prefix: argv.prefix,
flat: argv.flat,
quotedKeys: argv['quoted-keys'],
flattenMapsAfter: argv['flatten-maps-after'],
preserveKeys: argv['preserve-keys'],
onlyIncludeKeys: argv['only-include-keys'],
})
converter.writeToFile()
.then((options) => {
log(chalk.bold.bgGreen(`\n Config file written successfully to ${options.destination} `))
})
.catch((e) => {
log(error(e.message))
})
} catch (e) {
log(error(e.message))
throw e
}