-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RN Update script updates react version implicitly (#610)
* Travis Driven Development * Updated rn-cli.config to support old RN versions
- Loading branch information
Showing
6 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
let fs = require('fs'); | ||
let path = require('path'); | ||
const https = require('https'); | ||
|
||
const projectPath = process.argv[2]; | ||
const reactNativeVersion = process.argv[3]; | ||
|
||
const filePath = path.join(process.cwd(), projectPath, 'package.json'); | ||
let packageJson = require(filePath); | ||
async function run() { | ||
const projectPath = process.argv[2]; | ||
const reactNativeVersion = process.argv[3]; | ||
|
||
console.log(`Changing react-native dependency in ${filePath} to ${reactNativeVersion}`); | ||
const filePath = path.join(process.cwd(), projectPath, 'package.json'); | ||
console.log(`Trying to change react-native dependency in ${filePath}`); | ||
|
||
packageJson.dependencies['react-native'] = reactNativeVersion; | ||
fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); | ||
let packageJson = require(filePath); | ||
|
||
const data = await fetch(`https://registry.npmjs.org/react-native/${reactNativeVersion}/`); | ||
const reactVersion = data.peerDependencies.react; | ||
|
||
console.log(`Changed dependencies: | ||
react-native: ${reactNativeVersion} | ||
react: ${reactVersion}`); | ||
|
||
packageJson.dependencies['react-native'] = reactNativeVersion; | ||
packageJson.dependencies['react'] = reactVersion; | ||
fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2)); | ||
} | ||
|
||
async function fetch(url) { | ||
return new Promise((resolve, reject) => { | ||
https.get(url, res => { | ||
res.setEncoding('utf8'); | ||
let body = ""; | ||
res.on('data', data => { | ||
body += data; | ||
}); | ||
res.on('end', () => { | ||
body = JSON.parse(body); | ||
resolve(body); | ||
}); | ||
res.on('error', (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
run(); |