-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfreight.js
91 lines (78 loc) · 2.15 KB
/
freight.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
var log = require('./modules/loglevel');
module.exports = function () {
function Freight() {}
Freight.init = function (options) {
if (options.log) {
log = options.log;
}
var startup = require('./lib/startup')(log);
var track = require('./lib/track')(log);
var password = require('./lib/password')(log);
// set logging
startup.log(options);
// validate input
startup.validate(options);
var url = options.url;
// the information that is needed to get stuff bundled!
var extra = {
create: false,
track: false,
force: false,
// Kue priority
priority: options['queue-priority'] || 'normal',
// request to get a production only bundle
production: startup.detectProduction(options),
projectDir: options.directory || '.'
};
var project = {
name: 'noname',
npm: {
dependencies: {},
devDependencies: {}
},
bower: {
dependencies: {},
devDependencies: {},
resolutions: {}
},
bowerrc: {}
};
// if action is to create a bundle
if (options.action === 'create') {
extra.create = true;
if (options.force) {
log.debug('Force bundle.');
extra.force = true;
}
return password().then(function(password) {
extra.password = password;
return startup.freightRequest(url, project, extra, options);
});
} else if (options.action === 'track') {
// if action is to hook a git repository
extra.track = true;
return password()
.then(function(password) {
extra.password = password;
return track.request(url, project, extra, options);
})
.then(
function (result) {
log.debug('Freight request complete.');
if (! options.server) {
process.exit(0);
}
},
function (err) {
log.error(err);
if (! options.server) {
process.exit(1);
}
}
);
} else {
return startup.freightRequest(url, project, extra, options);
}
};
return Freight;
};