-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
49 lines (44 loc) · 1.69 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
'use strict';
var gulp = require('gulp'),
exec = require('gulp-exec'),
tap = require('gulp-tap'),
isWin = /^win/.test(process.platform),
commandSeparator = isWin ? '&' : ';',
basePath = "/",
init = function (path) {
basePath = path.endsWith("/") ? path : path + "/";
},
install = function (paths, callback) {
var src, stream, options = {
dir: function (filePath) {
return filePath.replace('package.json', '');
}
},
shared = function (file) {
var packageJSON = require(file.path),
libs = packageJSON.customDependencies;
if (libs) {
for (var lib in libs) {
if (libs[lib].toLowerCase() === "local") {
gulp.src(basePath + lib + '/**/*').pipe(gulp.dest(file.path.replace('package.json', 'node_modules/' + lib + '/')));
}
}
}
};
src = paths.map(function (path) {
return (path.endsWith("/") ? path : path + "/") + '**/package.json';
});
src.push('!./**/{node_modules,node_modules/**}');
stream = gulp.src(src)
.pipe(tap(shared))
.pipe(exec('(cd <%= options.dir(file.path) %> ' + commandSeparator + ' npm install) ' + commandSeparator + ' echo Installed for: <%= file.path %> \n', options))
.pipe(exec.reporter());
stream.on('finish', callback || function () {
console.log("Package installation completed.");
});
return stream;
};
module.exports = {
init: init,
install: install
};