diff --git a/README.md b/README.md index ff32a29..9ea8b20 100644 --- a/README.md +++ b/README.md @@ -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'; diff --git a/android/build.gradle b/android/build.gradle index 1ebbd11..f852d78 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.1.3' } } diff --git a/package.json b/package.json index 034c447..e74214c 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/scripts/installer.js b/scripts/installer.js new file mode 100644 index 0000000..cb246cd --- /dev/null +++ b/scripts/installer.js @@ -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) + }) + }) +}