mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 07:35:25 +00:00
Add warnings while upgrading RN with react-native upgrade
Summary: Closes https://github.com/facebook/react-native/pull/4854 Reviewed By: svcscm Differential Revision: D2803252 Pulled By: foghina fb-gh-sync-id: e6b05b19cf45773d7683ae8ae35643f400e51692
This commit is contained in:
parent
6d9096fb3f
commit
80bf431f98
@ -9,16 +9,67 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const chalk = require('chalk');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Promise = require('promise');
|
const Promise = require('promise');
|
||||||
const yeoman = require('yeoman-environment');
|
const yeoman = require('yeoman-environment');
|
||||||
|
const semver = require('semver');
|
||||||
|
|
||||||
module.exports = function upgrade(args, config) {
|
module.exports = function upgrade(args, config) {
|
||||||
args = args || process.argv;
|
args = args || process.argv;
|
||||||
let env = yeoman.createEnv();
|
const env = yeoman.createEnv();
|
||||||
let name = JSON.parse(fs.readFileSync('package.json', 'utf8')).name;
|
const pak = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
||||||
let generatorPath = path.join(__dirname, '..', 'generator');
|
const version = pak.dependencies['react-native'];
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
if (version === 'latest' || version === '*') {
|
||||||
|
console.warn(
|
||||||
|
chalk.yellow(
|
||||||
|
'Major releases are most likely to introduce breaking changes.\n' +
|
||||||
|
'Use a proper version number in your \'package.json\' file to avoid breakage.\n' +
|
||||||
|
'e.g. - ^0.18.0'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const installed = JSON.parse(fs.readFileSync('node_modules/react-native/package.json', 'utf8'));
|
||||||
|
|
||||||
|
if (semver.satisfies(installed.version, version)) {
|
||||||
|
const v = version.replace(/^(~|\^|=)/, '').replace(/x/i, '0');
|
||||||
|
|
||||||
|
if (semver.valid(v)) {
|
||||||
|
console.log(
|
||||||
|
'Upgrading project to react-native v' + installed.version + '\n' +
|
||||||
|
'Be sure to read the release notes and breaking changes:\n' +
|
||||||
|
chalk.blue(
|
||||||
|
'https://github.com/facebook/react-native/releases/tag/v' + semver.major(v) + '.' + semver.minor(v) + '.0'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(
|
||||||
|
'A valid version number for \'react-native\' is not specified your \'package.json\' file.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
chalk.yellow(
|
||||||
|
'react-native version in \'package.json\' doesn\'t match the installed version in \'node_modules\'.\n' +
|
||||||
|
'Try running \'npm install\' to fix the issue.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
chalk.yellow(
|
||||||
|
'Your \'package.json\' file doesn\'t seem to have \'react-native\' as a dependency.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const generatorPath = path.join(__dirname, '..', 'generator');
|
||||||
env.register(generatorPath, 'react:app');
|
env.register(generatorPath, 'react:app');
|
||||||
let generatorArgs = ['react:app', name].concat(args);
|
const generatorArgs = ['react:app', pak.name].concat(args);
|
||||||
return new Promise((resolve) => env.run(generatorArgs, {upgrade: true}, resolve));
|
return new Promise((resolve) => env.run(generatorArgs, {upgrade: true}, resolve));
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user