-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremap-cli.js
More file actions
44 lines (37 loc) · 1.16 KB
/
Copy pathremap-cli.js
File metadata and controls
44 lines (37 loc) · 1.16 KB
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
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const converter = require('./index.js')
yargs(hideBin(process.argv))
.command('remap [input] [output]', 'remap css color valus to css variables', (yargs) => {
return yargs
.positional('input', {
describe: 'input css file that contains color values',
demandOption: true
})
.positional('output', {
describe: 'output path to save the remaped css file that contains css color variables',
demandOption: true
})
}, (argv) => {
const inPath = argv.input
const outPath = argv.output
if (!inPath) {
throw Error('Need input path for transformation')
}
if (!fs.existsSync(inPath)) {
throw Error('Input path does not exist or is not accessible')
}
if (!outPath) {
throw Error('Need output path for transformation')
}
const outDir = path.dirname(outPath)
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir)
}
const remapedCss = converter(inPath)
fs.writeFileSync(outPath, remapedCss)
})
.parse()