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

Commit

Permalink
- adding auto installer
Browse files Browse the repository at this point in the history
  • Loading branch information
prscms committed Jun 29, 2018
1 parent 2548ebd commit 5bf964d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ allprojects {

- **iOS**

`$ cd ./node_modules/react-native-iconic/ios/ && pod install`
- 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`



## 💻 Usage

```javascript
import RNIconic from 'react-native-iconic';

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.3'
}
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "react-native-iconic",
"version": "0.0.8",
"version": "0.0.9",
"description": "React Native - Animated Icons with different states",
"main": "RNIconic.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "node scripts/installer.js"
},
"keywords": [
"react-native"
Expand Down
100 changes: 100 additions & 0 deletions scripts/installer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
})
})
}

0 comments on commit 5bf964d

Please sign in to comment.