-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (56 loc) · 1.63 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var path = require('path');
var fs = require('fs');
var PACKAGE_SRC_DIR = process.cwd() + '/src';
var PROJECT_SRC_DIR = path.resolve(__dirname, '../../src');
var PACKAGE_JSON = require(process.cwd() + '/package.json');
function log(msg) { console.log(' -> ' + msg); }
function blank() { console.log(''); }
function mkdirp(dir) {
var dirStat;
try {
dirStat = fs.statSync(dir);
} catch (e) {
fs.mkdirSync(dir);
return;
}
if(!dirStat.isDirectory()) {
throw new Error(dir + ' exists but is not a directory');
}
}
function mergeDir(src, target, dirsOnly) {
log('merging dir: ' + src);
mkdirp(target);
var dirs = fs.readdirSync(src);
if(dirs && dirs.length) {
dirs.forEach(function(d) {
var newSrc = src + '/' + d;
var newTarget = target + '/' + d;
var stat = fs.statSync(newSrc);
if(stat.isDirectory()) {
mkdirp(newTarget);
mergeDir(newSrc, newTarget);
} else if(stat.isFile() && !dirsOnly) {
mergeFile(newSrc, newTarget)
} else {
log('ignoring file: ' + newSrc);
}
});
}
}
function mergeFile(src, target) {
log('merging file: ' + src);
var contents = fs.readFileSync(src);
fs.writeFileSync(target, contents, { encoding: 'utf8' });
}
module.exports.install = function() {
blank();
console.log('SFDC PACKAGE POST INSTALL => ' + PACKAGE_JSON.name + '@' + PACKAGE_JSON.version);
log('package src dir: ' + PACKAGE_SRC_DIR);
log('project src dir: ' + PROJECT_SRC_DIR);
log('merging files');
blank();
mergeDir(PACKAGE_SRC_DIR, PROJECT_SRC_DIR, true);
blank();
log('merge complete!');
blank();
}