-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
40 lines (34 loc) · 1.08 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const yargs = require('yargs');
const { hideBin } = require('yargs/helpers');
const { findUnusedVariables } = require('../lib/index');
const argv = yargs(hideBin(process.argv))
.option('config', {
alias: 'c',
type: 'string',
description: 'Path to the configuration file',
default: 'css-variable-checker.config.json'
})
.option('json', {
alias: 'j',
type: 'boolean',
description: 'Output the results as a JSON string'
})
.help()
.argv;
const configPath = path.resolve(process.cwd(), argv.config);
if (!fs.existsSync(configPath)) {
console.error(`Configuration file not found: ${configPath}`);
process.exit(1);
}
const config = require(configPath);
const unusedVariables = findUnusedVariables(config);
if (argv.json) {
console.log(JSON.stringify(unusedVariables, null, 2));
} else {
const outputPath = path.join(process.cwd(), 'output.json');
fs.writeFileSync(outputPath, JSON.stringify(unusedVariables, null, 2));
console.log(`Done! Check ${outputPath} for results.`);
}