-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·67 lines (61 loc) · 1.79 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
#!/usr/bin/env node
var ncp = require('ncp').ncp;
var path = require('path');
var fs = require('fs');
require('yargs')
.usage('$0 <cmd> [args]')
.option('directory', {
alias: 'd',
describe: 'Provide the directory to install Violet to'
})
.option('type', {
alias: 't',
describe: 'Install Violet scss or js'
})
.command('install', 'Install Violet', {}, function (argv) {
var directory = 'violet';
var type = 'scss';
if (argv.directory != null) {
directory = argv.directory;
}
if (argv.type != null) {
type = argv.type;
}
install(directory, type);
})
.command('update', 'Update Violet', {}, function (argv) {
var directory = 'violet';
var type = 'scss';
if (argv.directory != null) {
directory = argv.directory;
}
if (argv.type != null) {
type = argv.type;
}
deleteFolderRecursive(directory);
install(directory, type);
})
.help('help')
.argv;
function install(directory, type) {
ncp(path.resolve(__dirname, './src/' + type), directory, function (err) {
if (err) {
return console.error(err);
}
console.log('Installed Violet!');
});
}
// thanks to http://www.geedew.com/remove-a-directory-that-is-not-empty-in-nodejs/
function deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}