-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·44 lines (31 loc) · 932 Bytes
/
app.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
#!/usr/bin/env node
'use strict';
const program = require('commander');
const Path = require('path');
const { writeFile, readFile } = require('fs');
const chalk = require('chalk')
const sketch2json = require('sketch2json');
program
.command('* <path>')
.description('parse sketch file to json file')
.action((path) => {
if(!path){
console.log('You must defined path');
}
readFile(path, (err, data) => {
if(err){
console.log(chalk.bold.red(`❌ ${err}`));
}
sketch2json(data).then(result => {
const name = Path.parse(path).name;
writeFile(`${name}.json`, JSON.stringify(result, null, 4), (err) => {
if (err) {
return console.log(chalk.bold.red(`❌ ${err}`));
}
console.log(chalk.bold.green(`✓ ${name}.json created`));
process.exit();
});
})
});
});
program.parse(process.argv);