forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode-cordova.js
112 lines (91 loc) · 3.01 KB
/
mode-cordova.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
const fs = require('fs')
const fse = require('fs-extra')
const appPaths = require('../app-paths')
const { log, warn, fatal } = require('../helpers/logger')
const { spawnSync } = require('../helpers/spawn')
class Mode {
get isInstalled () {
return fs.existsSync(appPaths.cordovaDir)
}
async add (target) {
if (this.isInstalled) {
warn(`Cordova support detected already. Aborting.`)
return
}
const pkg = require(appPaths.resolve.app('package.json'))
const appName = pkg.productName || pkg.name || 'Quasar App'
if (/^[0-9]/.test(appName)) {
warn(
`App product name cannot start with a number. ` +
`Please change the "productName" prop in your /package.json then try again.`
)
return
}
const inquirer = require('inquirer')
console.log()
const answer = await inquirer.prompt([{
name: 'appId',
type: 'input',
message: 'What is the Cordova app id?',
default: 'org.cordova.quasar.app',
validate: appId => appId ? true : 'Please fill in a value'
}])
log('Creating Cordova source folder...')
spawnSync(
'cordova',
['create', 'src-cordova', answer.appId, appName],
{ cwd: appPaths.appDir },
() => {
fatal(`There was an error trying to install Cordova support`)
}
)
const { ensureWWW } = require('../cordova/ensure-consistency')
ensureWWW(true)
log(`Cordova support was installed`)
log(`App name was taken from package.json: "${appName}"`)
log()
warn(`If you want a different App name then remove Cordova support, edit productName field from package.json then add Cordova support again.`)
warn()
console.log(` ⚠️ WARNING!`)
console.log(` ⚠️ If developing for iOS, it is HIGHLY recommended that you install the Ionic Webview Plugin.`)
console.log(` ⚠️ Please refer to docs: https://quasar.dev/quasar-cli/developing-cordova-apps/preparation`)
console.log(` ⚠️ --------`)
console.log()
if (!target) {
console.log()
console.log(` No Cordova platform has been added yet as these get installed on demand automatically when running "quasar dev" or "quasar build".`)
log()
return
}
this.addPlatform(target)
}
hasPlatform (target) {
return fs.existsSync(appPaths.resolve.cordova(`platforms/${target}`))
}
addPlatform (target) {
const ensureConsistency = require('../cordova/ensure-consistency')
ensureConsistency()
if (this.hasPlatform(target)) {
return
}
log(`Adding Cordova platform "${target}"`)
spawnSync(
'cordova',
['platform', 'add', target],
{ cwd: appPaths.cordovaDir },
() => {
warn(`There was an error trying to install Cordova platform "${target}"`)
process.exit(1)
}
)
}
remove () {
if (!this.isInstalled) {
warn(`No Cordova support detected. Aborting.`)
return
}
fse.removeSync(appPaths.cordovaDir)
log(`Cordova support was removed`)
}
}
module.exports = Mode