This repository has been archived by the owner on Apr 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwrapper.js
105 lines (90 loc) · 3.02 KB
/
wrapper.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
/*
* Extracted from https://github.com/apache/cordova-cli/blob/master/src/cli.js
*
* gulp-cordova
* https://github.com/rcsole/gulp-cordova
*
* Copyright (c) 2015 Ricard Solé Casas
* Licensed under the MIT license.
*/
const cordova_lib = require('cordova-lib')
const _ = require('lodash')
const cordova = cordova_lib.cordova
const events = cordova_lib.events
const fs = require('fs')
function cordovaWrapper(commandArray, next) {
var cmd = commandArray[0]
var subcommand
var msg
var known_platforms = Object.keys(cordova_lib.cordova_platforms)
/**
* Output the error in terminal/console
* @param dbgMsg
*/
function callback (dbgMsg) {
console.log(dbgMsg);
}
if (!cordova.hasOwnProperty(cmd)) {
return callback('Cordova does not know ' + cmd)
}
var opts = {
platforms: [],
options: [],
verbose: false,
silent: true,
browserify: false
}
if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run') {
// temporary storage of platforms
var platforms = commandArray.slice(1)
// distinguish platforms from arguments
// only boolean type of arguments (e.g. --release) allowed/working
for (var i = 0; i < platforms.length; i++) {
if (platforms[i].indexOf('--') === 0) { // is argument
opts.options.push(platforms[i])
} else { // is platform
opts.platforms.push(platforms[i])
}
}
var badPlatforms = _.difference(opts.platforms, known_platforms)
if (!_.isEmpty(badPlatforms)) {
return callback('Unknown platforms: ' + badPlatforms.join(', '))
}
// CB-6976 Windows Universal Apps. Allow mixing windows and windows8 aliases
opts.platforms = opts.platforms.map(function(platform) {
// allow using old windows8 alias for new unified windows platform
if (platform == 'windows8' && fs.existsSync('platforms/windows')) {
return 'windows'
}
// allow using new windows alias for old windows8 platform
if (platform == 'windows' &&
!fs.existsSync('platforms/windows') &&
fs.existsSync('platforms/windows8')) {
return 'windows8'
}
return platform
})
cordova.raw[cmd].call(null, opts).done(next)
} else if (cmd == 'serve') {
var port = commandArray[1]
cordova.raw.serve(port).done(next)
} else if (cmd == 'create') {
var cfg = {}
// If we got a fourth parameter, consider it to be JSON to init the config.
if (commandArray[4]) {
cfg = JSON.parse(commandArray[4])
}
// create(dir, id, name, cfg)
cordova.raw.create(commandArray[1] // dir to create the project in
, commandArray[2] // App id
, commandArray[3] // App name
, cfg
).done(next)
} else {
// platform/plugins add/rm [target(s)]
subcommand = commandArray[1] // sub-command like "add", "ls", "rm" etc.
var targets = commandArray.slice(2) // array of targets, either platforms or plugins
cordova.raw[cmd](subcommand.toString(), targets).done(next)
}
}
module.exports = cordovaWrapper