-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathbower-installer.js
executable file
·65 lines (49 loc) · 1.56 KB
/
bower-installer.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
#!/usr/bin/env node
var _ = require('lodash');
var File = require('file-utils').File;
var colors = require('colors');
var bower = require('bower');
var fs = require('fs');
var path = require('path');
var basePath = process.cwd();
var cfg = require(path.join(basePath,'component.json')).install;
if(!cfg || !cfg.path) {
console.log(("bower-installer error").red + " component.json must contain a valid install path");
}
var installPath = new File(basePath + '/' + cfg.path);
var installDependency = function(deps, key) {
deps = cfg.sources && cfg.sources[key] ? cfg.sources[key] : deps;
if(!_.isArray(deps)) {
deps = [ deps ];
}
_.each(deps, function(dep) {
var f_s = dep;
var f = new File( basePath + '/' + f_s );
var f_path = basePath + '/' + cfg.path + '/' + f.getName();
f.copy( f_path, function(error, copied) {
if(!error && copied) {
console.log(('\t' + key + ' : ' + f_path).green);
} else {
console.log(('Error\t' + dep + ' : ' + f_path).red);
console.log('\t\t' + error);
}
});
});
};
installPath.remove(function() {
installPath.createDirectory();
});
bower.commands
.list({paths: true})
.on('data', function (data) {
console.log('Installing: ');
_.each(data, function(dep, key) {
if(_.isArray(dep)) {
_.each(dep, function(subDep) {
installDependency(subDep, key);
});
} else {
installDependency(dep, key);
}
});
});