-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (56 loc) · 1.52 KB
/
index.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
var fs = require("node-fs-extra");
var path = require("path");
var rl = require('readline-sync');
var glob = require("glob");
var tmp = require("tmp");
var simpleGit = require('simple-git');
module.exports = {
generate: function(options, cb) {
this.cloneDirTo(
'https://github.com/cantierecreativo/bemo.git',
'bemo',
options.stylesheetsDir,
function() {
if (options.extension) {
var sassFiles = glob.sync(path.join(options.stylesheetsDir, "**/*.sass"));
sassFiles.forEach(function(sassFile) {
var newPath = sassFile.replace(/\.sass$/, "." + options.extension);
fs.renameSync(sassFile, newPath);
});
}
cb(null);
}
);
},
ask: function(question) {
return rl.question(question + " ");
},
yesNo: function(question) {
var answer = this.ask(question + " [y/n]").toLowerCase();
return answer == 'y' || answer == 'yes';
},
confirmCleanDir: function(path) {
function cleanDir() {
fs.mkdirpSync(path);
}
if (!fs.existsSync(path)) {
cleanDir();
return;
}
if (this.yesNo("Can I overwrite the dir " + path + "?")) {
fs.removeSync(path);
cleanDir();
} else {
process.exit(0);
}
},
cloneDirTo: function(repo, repoPath, dest, cb) {
this.confirmCleanDir(dest);
var git = simpleGit();
var tmpDir = tmp.dirSync();
git.clone(repo, tmpDir.name, function() {
fs.copySync(path.join(tmpDir.name, repoPath), dest);
cb(null);
});
}
}