Skip to content

Commit

Permalink
- adding ios pod installer
Browse files Browse the repository at this point in the history
  • Loading branch information
prscms committed Jun 28, 2018
1 parent d6b7773 commit f8f33f9
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ allprojects {
> **Note:** Android SDK 27 > is supported
- **iOS**
- Run Command: `cd ../node_modules/react-native-toasty/ios` && `pod install`. If it has error => try pod repo update then pod install
- After `react-native link react-native-toasty`, please verify `node_modules/react-native-toasty/ios/` contains `Pods` folder. If does not exist please execute `pod install` command on `node_modules/react-native-toasty/ios/`, if any error => try `pod repo update` then `pod install`


## 💻 Usage
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-toasty",
"version": "0.0.1",
"version": "0.0.2",
"description": "React Native: Native Toast",
"main": "js/RNToasty.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 f8f33f9

Please sign in to comment.