forked from iamricard/gulp-cordova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (63 loc) · 1.72 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
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
/*
* gulp-cordova
* https://github.com/rcsole/gulp-cordova
*
* Copyright (c) 2015 Ricard Solé Casas
* Licensed under the MIT license.
*/
var wrapper = require('./wrapper')
var gutil = require('gulp-util')
var chalk = require('chalk')
var map = require('map-stream')
var async = require('async')
var GULP_CORDOVA = '[gulp-cordova]'
module.exports = function(commands, options) {
var endStream = null
var opts = options || {}
opts.rootDir = process.cwd()
function cordovaError(message) {
return new gutil.PluginError({
plugin: GULP_CORDOVA,
message: message
})
}
function cordovaStream(file, callback) {
endStream = callback
if (!file.contents && !commands) {
return endStream(new cordovaError('Please provide either a config file or a command object'))
}
if (file.contents && !commands) {
commands = JSON.parse(file.contents.toString()).cordova
}
if (!Array.isArray(commands)) {
return endStream(new cordovaError('Commands must be an array'))
}
if (!Array.isArray(commands[0])) {
commands = [commands]
}
async.eachSeries(commands, function(command, next) {
execute(command, next)
}, function(err) {
if (!opts.silent) {
gutil.log(GULP_CORDOVA,
'Going back to root directory:',
opts.rootDir
)
}
process.chdir(opts.rootDir)
endStream()
})
}
function execute(command, next) {
if (opts.cwd) {
process.chdir(opts.cwd)
}
if (!opts.silent) {
gutil.log(GULP_CORDOVA,
'Running command:', chalk.magenta('cordova'), chalk.cyan(command.join(' ')),
'in', process.cwd())
}
wrapper(command, next)
}
return map(cordovaStream)
}