forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-ide.js
174 lines (147 loc) · 4.6 KB
/
open-ide.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const fs = require('fs')
const path = require('path')
const open = require('open')
const { execSync } = require('child_process')
const appPaths = require('../app-paths')
const { warn, fatal } = require('./logger')
function findXcodeWorkspace (folder) {
const root = fs.readdirSync(folder)
for (let item of root) {
const __path = path.join(folder, item)
if (item.endsWith('.xcworkspace')) {
return __path
}
}
}
function runMacOS (mode, target) {
if (target === 'ios') {
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/ios')
: appPaths.resolve.capacitor('ios/App')
open(findXcodeWorkspace(folder), {
wait: false
})
}
else {
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')
open(folder, {
app: 'android studio',
wait: false
})
}
}
function getLinuxPath (bin) {
const canonicalPaths = [
'/usr/local/android-studio/bin/studio.sh',
'/opt/android-studio/bin/studio.sh'
]
if (bin.linuxAndroidStudio) {
canonicalPaths.unshift(bin.linuxAndroidStudio)
}
for (let studioPath of canonicalPaths) {
if (fs.existsSync(studioPath)) {
return studioPath
}
}
}
function runLinux (mode, bin, target) {
if (target === 'android') {
const studioPath = getLinuxPath(bin)
if (studioPath) {
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')
open(folder, {
app: studioPath,
wait: false
})
return
}
}
else if (target === 'ios') {
fatal(`iOS target not supported on Linux`)
}
warn(`Cannot determine path to IDE executable`)
console.log(' Please set quasar.conf.js > bin > linuxAndroidStudio with the escaped path to your studio.sh')
console.log(` Example: '/usr/local/android-studio/bin/studio.sh'`)
process.exit(1)
}
function getWindowsPath (bin) {
if (bin.windowsAndroidStudio && fs.existsSync(bin.windowsAndroidStudio)) {
return bin.windowsAndroidStudio
}
const studioPath = 'C:\\Program Files\\Android\\Android Studio\\bin\\studio64.exe'
if (fs.existsSync(studioPath)) {
return studioPath
}
try {
const buffer = execSync('REG QUERY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Android Studio" /v Path')
const bufferString = buffer.toString('utf-8').replace(/(\r\n|\n|\r)/gm, '')
const index = bufferString.indexOf('REG_SZ')
if (index > 0) {
const asPath = bufferString.substring(index + 6).trim() + '\\bin\\studio64.exe'
if (fs.existsSync(asPath)) {
return asPath
}
}
}
catch (e) {}
}
function runWindows (mode, bin, target) {
if (target === 'android') {
const studioPath = getWindowsPath(bin)
if (studioPath) {
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')
open(folder, {
app: `${studioPath}`,
wait: false
})
// pause required, otherwise Windows fails
// to open the process
return new Promise(resolve => {
setTimeout(resolve, 300)
})
}
}
else if (target === 'ios') {
fatal(`iOS target not supported on Windows`)
}
warn(`Cannot determine path to IDE executable`)
console.log(' Please set quasar.conf.js > bin > windowsAndroidStudio with the escaped path to your studio64.exe')
console.log(` Example: 'C:\\\\Program Files\\\\Android\\\\Android Studio\\\\bin\\\\studio64.exe'`)
process.exit(1)
}
module.exports = function (mode, bin, target, dev) {
console.log()
console.log(` ⚠️ `)
console.log(` ⚠️ Opening ${target === 'ios' ? 'XCode' : 'Android Studio'} IDE...`)
if (dev) {
console.log(` ⚠️ From there, use the IDE to run the app.`)
console.log(` ⚠️ `)
console.log(` ⚠️ DO NOT close the terminal as this will kill the devserver.`)
}
else {
console.log(` ⚠️ From there, use the IDE to build the final package.`)
}
if (target === 'android') {
console.log(` ⚠️ `)
console.log(` ⚠️ DO NOT upgrade Gradle or any other deps as Android Studio will suggest.`)
console.log(` ⚠️ If you encounter any IDE errors then click on File > Invalidate caches and restart.`)
}
console.log(` ⚠️ `)
console.log()
switch (process.platform) {
case 'darwin':
return runMacOS(mode, target)
case 'linux':
return runLinux(mode, bin, target)
case 'win32':
return runWindows(mode, bin, target)
default:
fatal(`Unsupported host OS for opening the IDE`)
}
}