Fix broken releases script

Summary:
Fails on my machine due to fact that `replace` returns an instance of a String, rather than an instance of ShellString (that includes `to` on its prototype).

Solution is to use an explicit `writeFileSync`. You can see that change in the wild on 0.50-stable branch.

CC janicduplessis (edit by hramos)
Closes https://github.com/facebook/react-native/pull/16303

Differential Revision: D6031331

Pulled By: hramos

fbshipit-source-id: 41c583d53df75bea1a55fa19174d912e414209c0
This commit is contained in:
Mike Grabowski 2017-10-11 19:34:06 -07:00 committed by Facebook Github Bot
parent cc86d12175
commit b2eb7fd77b
1 changed files with 29 additions and 20 deletions

View File

@ -15,7 +15,7 @@
* After changing the files it makes a commit and tags it. * After changing the files it makes a commit and tags it.
* All you have to do is push changes to remote and CI will make a new build. * All you have to do is push changes to remote and CI will make a new build.
*/ */
const fs = require('fs');
const { const {
cat, cat,
echo, echo,
@ -58,30 +58,39 @@ if (!match) {
} }
let [, major, minor, patch, prerelease] = match; let [, major, minor, patch, prerelease] = match;
cat('scripts/versiontemplates/ReactNativeVersion.java.template') fs.writeFileSync(
.replace('${major}', major) 'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
.replace('${minor}', minor) cat('scripts/versiontemplates/ReactNativeVersion.java.template')
.replace('${patch}', patch) .replace('${major}', major)
.replace('${prerelease}', prerelease !== undefined ? `"${prerelease}"` : 'null') .replace('${minor}', minor)
.to('ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java'); .replace('${patch}', patch)
.replace('${prerelease}', prerelease !== undefined ? `"${prerelease}"` : 'null'),
'utf-8'
);
cat('scripts/versiontemplates/RCTVersion.h.template') fs.writeFileSync(
.replace('${major}', `@(${major})`) 'React/Base/RCTVersion.h',
.replace('${minor}', `@(${minor})`) cat('scripts/versiontemplates/RCTVersion.h.template')
.replace('${patch}', `@(${patch})`) .replace('${major}', `@(${major})`)
.replace('${prerelease}', prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]') .replace('${minor}', `@(${minor})`)
.to('React/Base/RCTVersion.h'); .replace('${patch}', `@(${patch})`)
.replace('${prerelease}', prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]'),
'utf-8'
);
cat('scripts/versiontemplates/ReactNativeVersion.js.template') fs.writeFileSync(
.replace('${major}', major) 'Libraries/Core/ReactNativeVersion.js',
.replace('${minor}', minor) cat('scripts/versiontemplates/ReactNativeVersion.js.template')
.replace('${patch}', patch) .replace('${major}', major)
.replace('${prerelease}', prerelease !== undefined ? `'${prerelease}'` : 'null') .replace('${minor}', minor)
.to('Libraries/Core/ReactNativeVersion.js'); .replace('${patch}', patch)
.replace('${prerelease}', prerelease !== undefined ? `'${prerelease}'` : 'null'),
'utf-8'
);
let packageJson = JSON.parse(cat('package.json')); let packageJson = JSON.parse(cat('package.json'));
packageJson.version = version; packageJson.version = version;
JSON.stringify(packageJson, null, 2).to('package.json'); fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8');
// - change ReactAndroid/gradle.properties // - change ReactAndroid/gradle.properties
if (sed('-i', /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, 'ReactAndroid/gradle.properties').code) { if (sed('-i', /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, 'ReactAndroid/gradle.properties').code) {