This repository was archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinstaller.js
100 lines (80 loc) · 2.14 KB
/
installer.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
const exec = require('child_process').exec
var osvar = process.platform
if (osvar !== 'darwin') return
exists('pod')
.then(function(command) {
installPods()
})
.catch(function() {
installCocoaPods().then(() => {
installPods()
})
})
function installPods() {
console.log('executing pod install command')
exec('cd ./ios && pod install', (err, stdout, stderr) => {
console.log(stderr)
if (err === undefined || err === null) {
console.log('pod install command successfull')
return
}
if (stdout !== undefined && stdout !== null) {
if (stdout.includes('could not find compatible versions for pod')) {
console.log('executing pod repo update command.')
exec('pod repo update', (err, stdout, stderr) => {
if (err === undefined || err === null) {
console.log('pod repo update successfull')
exec('cd ./ios && pod install', (err, stdout, stderr) => {})
return
}
console.log(stdout)
})
}
} else {
console.log('pod install sucessfull')
}
})
}
function installCocoaPods() {
console.log('installing socoapods.')
return new Promise((resolve, reject) => {
run('sudo gem install cocoapods')
.then(() => {
console.log('sudo gem install cocoapods sucessfull')
resolve()
})
.catch(e => {
console.log(e)
})
})
}
// returns Promise which fulfills with true if command exists
function exists(cmd) {
return run(`which ${cmd}`).then(stdout => {
if (stdout.trim().length === 0) {
// maybe an empty command was supplied?
// are we running on Windows??
return Promise.reject(new Error('No output'))
}
const rNotFound = /^[\w\-]+ not found/g
if (rNotFound.test(cmd)) {
return Promise.resolve(false)
}
return Promise.resolve(true)
})
}
function run(command) {
return new Promise((fulfill, reject) => {
exec(command, (err, stdout, stderr) => {
if (err) {
reject(err)
return
}
if (stderr) {
reject(new Error(stderr))
return
}
fulfill(stdout)
})
})
}