This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
slushfile.js
86 lines (72 loc) · 2.21 KB
/
slushfile.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
/*
* slush-biojs-io
*/
var gulp = require('gulp'),
_ = require('underscore'),
fullnameTask = require('fullname'),
usernameTask = require('username');
var colors = require('colors');
var show = function() {
console.log.apply(console, arguments);
};
var inquirer = require("./inquirer.js");
var questions = require("./questions.js");
var exec = require('child_process').exec;
gulp.task('default', function(done) {
// set handy defaults
var opts = {};
opts.fullname = "";
opts.email = "";
opts.username = "";
npmURL = "https://registry.npmjs.org/" + require("./package.json").name + "/latest";
var pkgVersion = require("./package.json").version;
var http = require('client-http');
// check whether slush-biojs is up-to-date
http.get(npmURL, function(data) {
if (typeof data != "undefined") {
// TODO: download failed
} else {
var pkg = JSON.parse(data);
var currentVersion = pkg.version;
if (currentVersion != pkgVersion) {
console.log();
console.log();
show("YOUR slush-biojs version is OUTDATED ".red + "(current: " + currentVersion + ", installed: " + pkgVersion + ")");
show("PLEASE UPDATE slush-biojs".red);
show("RUN: npm install -g slush-biojs");
process.exit(1);
}
}
});
usernameTask(function(err, name) {
opts.username = name;
});
fullnameTask(function(err, name) {
opts.fullname = name;
});
exec('git config --global user.email', function(err, stdout) {
opts.email = stdout.trim();
});
exec('npm -v ', function(err, stdout) {
var parts = stdout.split(".");
if (parts[0] < 2) {
console.log();
console.log("Your npm version is outdated. Please update");
console.log("https://github.com/joyent/node/wiki/installing-node.js-via-package-manager");
process.exit(1);
}
});
var prev = {};
var prompts = questions.getPrompts(prev, opts);
var repeater = function(answers, repeat) {
prev = _.pick(answers, questions.getKeys(prompts));
prompts = questions.getPrompts(prev, opts);
if (repeat) {
inquirer.ask(prompts, repeater);
} else {
done();
// TODO: save some answers as default
}
};
inquirer.ask(prompts, repeater);
});