1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | const path = require('path');
|
14 | const fs = require('fs');
|
15 | const url = require('url');
|
16 |
|
17 |
|
18 |
|
19 | const appDirectory = fs.realpathSync(process.cwd());
|
20 | function resolveApp(relativePath) {
|
21 | return path.resolve(appDirectory, relativePath);
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const nodePaths = (process.env.NODE_PATH || '')
|
40 | .split(process.platform === 'win32' ? ';' : ':')
|
41 | .filter(Boolean)
|
42 | .filter(folder => !path.isAbsolute(folder))
|
43 | .map(resolveApp);
|
44 |
|
45 | const envPublicUrl = process.env.PUBLIC_URL;
|
46 |
|
47 | function ensureSlash(path, needsSlash) {
|
48 | const hasSlash = path.endsWith('/');
|
49 | if (hasSlash && !needsSlash) {
|
50 | return path.substr(path, path.length - 1);
|
51 | } else if (!hasSlash && needsSlash) {
|
52 | return `${path}/`;
|
53 | } else {
|
54 | return path;
|
55 | }
|
56 | }
|
57 |
|
58 | function getPublicUrl(appPackageJson) {
|
59 | return envPublicUrl || require(appPackageJson).homepage;
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | function getServedPath(appPackageJson) {
|
69 | const publicUrl = getPublicUrl(appPackageJson);
|
70 | const servedUrl = envPublicUrl ||
|
71 | (publicUrl ? url.parse(publicUrl).pathname : '/');
|
72 | return ensureSlash(servedUrl, true);
|
73 | }
|
74 |
|
75 |
|
76 | module.exports = {
|
77 | appBuild: resolveApp('build'),
|
78 | appPublic: resolveApp('public'),
|
79 | appHtml: resolveApp('public/index.html'),
|
80 | appIndexJs: resolveApp('src/index.js'),
|
81 | appPackageJson: resolveApp('package.json'),
|
82 | appSrc: resolveApp('src'),
|
83 | yarnLockFile: resolveApp('yarn.lock'),
|
84 | testsSetup: resolveApp('src/setupTests.js'),
|
85 | appNodeModules: resolveApp('node_modules'),
|
86 | nodePaths: nodePaths,
|
87 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
88 | servedPath: getServedPath(resolveApp('package.json')),
|
89 | };
|
90 |
|
91 |
|
92 | function resolveOwn(relativePath) {
|
93 | return path.resolve(__dirname, '..', relativePath);
|
94 | }
|
95 |
|
96 |
|
97 | module.exports = {
|
98 | appPath: resolveApp('.'),
|
99 | appBuild: resolveApp('build'),
|
100 | appPublic: resolveApp('public'),
|
101 | appHtml: resolveApp('public/index.html'),
|
102 | appIndexJs: resolveApp('src/index.js'),
|
103 | appPackageJson: resolveApp('package.json'),
|
104 | appSrc: resolveApp('src'),
|
105 | yarnLockFile: resolveApp('yarn.lock'),
|
106 | testsSetup: resolveApp('src/setupTests.js'),
|
107 | appNodeModules: resolveApp('node_modules'),
|
108 | nodePaths: nodePaths,
|
109 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
110 | servedPath: getServedPath(resolveApp('package.json')),
|
111 |
|
112 | ownPath: resolveOwn('.'),
|
113 | ownNodeModules: resolveOwn('node_modules'),
|
114 | };
|
115 |
|
116 | const ownPackageJson = require('../package.json');
|
117 | const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
118 | const reactScriptsLinked = fs.existsSync(reactScriptsPath) &&
|
119 | fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
120 |
|
121 |
|
122 | if (
|
123 | !reactScriptsLinked &&
|
124 | __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
|
125 | ) {
|
126 | module.exports = {
|
127 | appPath: resolveApp('.'),
|
128 | appBuild: resolveOwn('../../build'),
|
129 | appPublic: resolveOwn('template/public'),
|
130 | appHtml: resolveOwn('template/public/index.html'),
|
131 | appIndexJs: resolveOwn('template/src/index.js'),
|
132 | appPackageJson: resolveOwn('package.json'),
|
133 | appSrc: resolveOwn('template/src'),
|
134 | yarnLockFile: resolveOwn('template/yarn.lock'),
|
135 | testsSetup: resolveOwn('template/src/setupTests.js'),
|
136 | appNodeModules: resolveOwn('node_modules'),
|
137 | nodePaths: nodePaths,
|
138 | publicUrl: getPublicUrl(resolveOwn('package.json')),
|
139 | servedPath: getServedPath(resolveOwn('package.json')),
|
140 |
|
141 | ownPath: resolveOwn('.'),
|
142 | ownNodeModules: resolveOwn('node_modules'),
|
143 | };
|
144 | }
|
145 |
|