Skip to content
This repository was archived by the owner on Jul 3, 2021. It is now read-only.

Commit 5bf964d

Browse files
committed
- adding auto installer
1 parent 2548ebd commit 5bf964d

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ allprojects {
7171

7272
- **iOS**
7373

74-
`$ cd ./node_modules/react-native-iconic/ios/ && pod install`
74+
- After `react-native link react-native-iconic`, please verify `node_modules/react-native-iconic/ios/` contains `Pods` folder. If does not exist please execute `pod install` command on `node_modules/react-native-iconic/ios/`, if any error => try `pod repo update` then `pod install`
75+
7576

7677

7778
## 💻 Usage
79+
7880
```javascript
7981
import RNIconic from 'react-native-iconic';
8082

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
9+
classpath 'com.android.tools.build:gradle:3.1.3'
1010
}
1111
}
1212

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "react-native-iconic",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "React Native - Animated Icons with different states",
55
"main": "RNIconic.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"postinstall": "node scripts/installer.js"
89
},
910
"keywords": [
1011
"react-native"

scripts/installer.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const exec = require('child_process').exec
2+
3+
var osvar = process.platform
4+
5+
if (osvar !== 'darwin') return
6+
7+
exists('pod')
8+
.then(function(command) {
9+
installPods()
10+
})
11+
.catch(function() {
12+
installCocoaPods().then(() => {
13+
installPods()
14+
})
15+
})
16+
17+
function installPods() {
18+
console.log('executing pod install command')
19+
20+
exec('cd ./ios && pod install', (err, stdout, stderr) => {
21+
console.log(stderr)
22+
23+
if (err === undefined || err === null) {
24+
console.log('pod install command successfull')
25+
return
26+
}
27+
28+
if (stdout !== undefined && stdout !== null) {
29+
if (stdout.includes('could not find compatible versions for pod')) {
30+
console.log('executing pod repo update command.')
31+
32+
exec('pod repo update', (err, stdout, stderr) => {
33+
if (err === undefined || err === null) {
34+
console.log('pod repo update successfull')
35+
36+
exec('cd ./ios && pod install', (err, stdout, stderr) => {})
37+
38+
return
39+
}
40+
41+
console.log(stdout)
42+
})
43+
}
44+
} else {
45+
console.log('pod install sucessfull')
46+
}
47+
})
48+
}
49+
50+
function installCocoaPods() {
51+
console.log('installing socoapods.')
52+
53+
return new Promise((resolve, reject) => {
54+
run('sudo gem install cocoapods')
55+
.then(() => {
56+
console.log('sudo gem install cocoapods sucessfull')
57+
resolve()
58+
})
59+
.catch(e => {
60+
console.log(e)
61+
})
62+
})
63+
}
64+
65+
// returns Promise which fulfills with true if command exists
66+
function exists(cmd) {
67+
return run(`which ${cmd}`).then(stdout => {
68+
if (stdout.trim().length === 0) {
69+
// maybe an empty command was supplied?
70+
// are we running on Windows??
71+
return Promise.reject(new Error('No output'))
72+
}
73+
74+
const rNotFound = /^[\w\-]+ not found/g
75+
76+
if (rNotFound.test(cmd)) {
77+
return Promise.resolve(false)
78+
}
79+
80+
return Promise.resolve(true)
81+
})
82+
}
83+
84+
function run(command) {
85+
return new Promise((fulfill, reject) => {
86+
exec(command, (err, stdout, stderr) => {
87+
if (err) {
88+
reject(err)
89+
return
90+
}
91+
92+
if (stderr) {
93+
reject(new Error(stderr))
94+
return
95+
}
96+
97+
fulfill(stdout)
98+
})
99+
})
100+
}

0 commit comments

Comments
 (0)