-
Notifications
You must be signed in to change notification settings - Fork 1
/
biojs2galaxy.js
executable file
·154 lines (129 loc) · 3.78 KB
/
biojs2galaxy.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env node
/*
* biojs-galaxy
* https://github.com/biojs/biojs-galaxy
*
* Copyright (c) 2014 BioJS
* Licensed under the GPLv3
*/
var q = require('bluebird');
var fsp = require('fs-promise');
var path = require('path');
var join = require('path').join;
var program = require('commander');
var minilog = require('minilog');
var path = require('path');
var tmp = require('tmp');
var _ = require('lodash');
var log = minilog("main");
var NpmList = require("./lib/workmen.js");
var NpmInstall = require("./lib/npmInstall.js");
var MakoBrowserify = require('./lib/makoBrowserify');
var config = require(__dirname + '/package.json');
program
.version(config.version)
.usage('[packages]')
.description('Automated import of biojs components into galaxy')
.option('-v, --verbose', 'Increase verbosity', false)
.option('-a, --all', 'Download all packages from npm', false)
.option('-o, --output [folder]', 'Output folder', join(process.cwd(), 'build'))
.option('-p, --path [path]', 'Path to local package')
.option('-r, --remove', 'Clear output folder', false)
.parse(process.argv);
// logging
if (program.verbose) {
minilog
.suggest
.clear()
.deny('verbose', 'trace');
}
minilog.enable();
// where all galaxy plugins should be installed to
var pkgs = [];
// modes
var modes = {
localMode: !!program.path,
downloadAll: !!program.all,
};
if (typeof program.args !== 'undefined' && program.args.length > 0) {
pkgs = program.args[0];
pkgs = pkgs.split(",").map(function(s) {
return s.trim();
});
} else if (_.compact(_.values(modes)).length == 0) {
console.error("Please choose an option");
program.help();
}
var opts = {
path: program.output,
tmpPath: ''
};
var tagList = ['galaxy-biojs', 'galaxy-vis'];
if (opts.path[0] != "/") {
opts.path = process.cwd() + "/" + opts.path;
}
var chainReady = q.resolve();
if (program.remove) {
chainReady = fsp.remove(opts.path);
}
chainReady = chainReady.then(function() {
return fsp.mkdirp(opts.path);
});
if (modes.localMode) {
opts.tmpPath = program.path;
if (opts.tmpPath != "/") {
opts.tmpPath = process.cwd() + "/" + opts.tmpPath;
}
chainReady.then(function() {
var pkg = require(program.path + "/package.json");
log.info(pkg.name + ": starting -> mako");
var localOpts = _.extend({
local: true,
}, opts);
var inst = new MakoBrowserify(pkg, localOpts);
return inst.build().then(function() {
log.info("saved to ", opts.opts);
log.info("copy the component folder to config/plugins/visualizations/ of your galaxy installation and enable vis plugins");
}, function(err) {
log.error("Error:", err);
});
});
} else {
// init tmp directory needed for installer
var installer = new NpmInstall();
chainReady = chainReady.then(function() {
return installer.init();
}).then(function() {
opts.tmpPath = installer.path;
});
var instance = new NpmList({keywords: tagList}, function(pkgs) {
log.info("All packages have been installed. Congrats!");
});
// BIND event streams
// we have seen a package -> begin to install
instance.on("single-pkg-start", installer.install.bind(installer));
// package has been installed -> begin the mako toolchain
instance.on("installed-pkg", function(pkg) {
log.info(pkg.name + ": finished -> mako");
var inst = new MakoBrowserify(pkg, opts);
inst.build().then(function() {
instance.trigger("done-pkg", pkg);
}, function(err) {
log.error("Error:", err);
});
});
// a single package has been finalised
instance.on("done-pkg", function(pkg) {
log.debug(pkg.name + ": success");
});
chainReady.then(function() {
if (modes.downloadAll) {
instance.start();
} else {
instance.start(pkgs);
}
});
}
chainReady.error(function(err) {
log.error(err);
});