1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getReactScriptsPath = getReactScriptsPath;
|
7 | exports.isReactScriptsInstalled = isReactScriptsInstalled;
|
8 |
|
9 | var _fs = _interopRequireDefault(require("fs"));
|
10 |
|
11 | var _path = _interopRequireDefault(require("path"));
|
12 |
|
13 | var _semver = _interopRequireDefault(require("@storybook/semver"));
|
14 |
|
15 | var _nodeLogger = require("@storybook/node-logger");
|
16 |
|
17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18 |
|
19 | var appDirectory = _fs.default.realpathSync(process.cwd());
|
20 |
|
21 | var reactScriptsPath;
|
22 |
|
23 | function getReactScriptsPath({
|
24 | noCache: noCache
|
25 | } = {}) {
|
26 | if (reactScriptsPath && !noCache) return reactScriptsPath;
|
27 |
|
28 | var reactScriptsScriptPath = _fs.default.realpathSync(_path.default.join(appDirectory, '/node_modules/.bin/react-scripts'));
|
29 |
|
30 | try {
|
31 |
|
32 |
|
33 |
|
34 | var pathIsNotResolved = /node_modules[\\/]\.bin[\\/]react-scripts/i.test(reactScriptsScriptPath);
|
35 |
|
36 | if (pathIsNotResolved) {
|
37 | var content = _fs.default.readFileSync(reactScriptsScriptPath, 'utf8');
|
38 |
|
39 | var packagePathMatch = content.match(/"\$basedir[\\/]([^\s]+?[\\/]bin[\\/]react-scripts\.js")/i);
|
40 |
|
41 | if (packagePathMatch && packagePathMatch.length > 1) {
|
42 | reactScriptsScriptPath = _path.default.join(appDirectory, '/node_modules/.bin/', packagePathMatch[1]);
|
43 | }
|
44 | }
|
45 | } catch (e) {
|
46 | _nodeLogger.logger.warn(`Error occurred during react-scripts package path resolving: ${e}`);
|
47 | }
|
48 |
|
49 | reactScriptsPath = _path.default.join(reactScriptsScriptPath, '../..');
|
50 |
|
51 | var scriptsPkgJson = _path.default.join(reactScriptsPath, 'package.json');
|
52 |
|
53 | if (!_fs.default.existsSync(scriptsPkgJson)) {
|
54 | reactScriptsPath = 'react-scripts';
|
55 | }
|
56 |
|
57 | return reactScriptsPath;
|
58 | }
|
59 |
|
60 | function isReactScriptsInstalled(requiredVersion = '2.0.0') {
|
61 | try {
|
62 |
|
63 | var reactScriptsJson = require(_path.default.join(getReactScriptsPath(), 'package.json'));
|
64 |
|
65 | return !_semver.default.gtr(requiredVersion, reactScriptsJson.version);
|
66 | } catch (e) {
|
67 | return false;
|
68 | }
|
69 | } |
\ | No newline at end of file |