1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.current = current;
|
7 | exports.latest = latest;
|
8 | exports.logIfUpdateAvailable = logIfUpdateAvailable;
|
9 | function _path() {
|
10 | const data = _interopRequireDefault(require("path"));
|
11 | _path = function () {
|
12 | return data;
|
13 | };
|
14 | return data;
|
15 | }
|
16 | function _semver() {
|
17 | const data = _interopRequireDefault(require("semver"));
|
18 | _semver = function () {
|
19 | return data;
|
20 | };
|
21 | return data;
|
22 | }
|
23 | var _errors = require("../errors");
|
24 | var _logger = _interopRequireDefault(require("../logger"));
|
25 | var _resolveNodeModuleDir = _interopRequireDefault(require("../resolveNodeModuleDir"));
|
26 | var _getLatestRelease = _interopRequireDefault(require("./getLatestRelease"));
|
27 | var _printNewRelease = _interopRequireDefault(require("./printNewRelease"));
|
28 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29 | const getReactNativeVersion = projectRoot => {
|
30 | var _require;
|
31 | return (_require = require(_path().default.join((0, _resolveNodeModuleDir.default)(projectRoot, 'react-native'), 'package.json'))) === null || _require === void 0 ? void 0 : _require.version;
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | async function logIfUpdateAvailable(projectRoot) {
|
38 | const hasUpdate = await latest(projectRoot);
|
39 | if (hasUpdate) {
|
40 | (0, _printNewRelease.default)(hasUpdate.name, hasUpdate.upgrade, hasUpdate.current);
|
41 | }
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 | async function latest(projectRoot) {
|
47 | try {
|
48 | const currentVersion = getReactNativeVersion(projectRoot);
|
49 | if (!currentVersion) {
|
50 | return;
|
51 | }
|
52 | const {
|
53 | name
|
54 | } = require(_path().default.join(projectRoot, 'package.json'));
|
55 | const latestRelease = await (0, _getLatestRelease.default)(name, currentVersion);
|
56 | if (latestRelease) {
|
57 | return {
|
58 | name,
|
59 | current: currentVersion,
|
60 | upgrade: latestRelease
|
61 | };
|
62 | }
|
63 | } catch (e) {
|
64 |
|
65 |
|
66 | _logger.default.debug('Cannot detect current version of React Native, ' + 'skipping check for a newer release');
|
67 | _logger.default.debug(e);
|
68 | }
|
69 | return undefined;
|
70 | }
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | function current(projectRoot) {
|
76 | try {
|
77 | const found = _semver().default.parse(getReactNativeVersion(projectRoot));
|
78 | if (found) {
|
79 | return found;
|
80 | }
|
81 | } catch {
|
82 | throw new _errors.UnknownProjectError(projectRoot);
|
83 | }
|
84 | return undefined;
|
85 | }
|
86 |
|
87 |
|
\ | No newline at end of file |