-
Notifications
You must be signed in to change notification settings - Fork 14
/
init.js
32 lines (30 loc) · 893 Bytes
/
init.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
var path = require('path');
var fs = require('fs');
var copyRecursiveSync = function(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if(stats.isDirectory()) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
fs.writeFileSync(dest, fs.readFileSync(src));
}
};
exports.init = function(dest){
var srcPath = path.join(__dirname, '/lib/sample_repo/');
var destPath = path.join(process.cwd(), dest) ;
try{
copyRecursiveSync(srcPath, destPath);
console.log("Created successfully.");
}catch(err){
if(err.code === "EEXIST"){
console.log(dest + " already exists");
}else{
console.log(err);
}
}
}