1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 | const fs = require('fs');
|
5 | const yargs = require('yargs');
|
6 |
|
7 | const { argv } = yargs
|
8 | .usage('')
|
9 | .option('path', {
|
10 | alias: 'p',
|
11 | string: true,
|
12 | })
|
13 | .option('output', {
|
14 | alias: 'o',
|
15 | string: true,
|
16 | })
|
17 | .demandOption('path')
|
18 | .demandOption('output');
|
19 |
|
20 | const path = `${argv.path}/svgs/`;
|
21 |
|
22 | const generatedJSON = {};
|
23 | fs.readdirSync(path)
|
24 | .filter(file => fs.statSync(path + file).isDirectory())
|
25 | .forEach(file => {
|
26 | const icons = fs.readdirSync(path + file);
|
27 | generatedJSON[file] = icons.map(icon => icon.split('.')[0]);
|
28 | });
|
29 |
|
30 | fs.writeFileSync(
|
31 | argv.output,
|
32 | `${JSON.stringify(generatedJSON, null, 2)}\r\n`,
|
33 | 'utf8'
|
34 | );
|