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