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(path, needsSlash) {
|
23 | const hasSlash = path.endsWith('/');
|
24 | if (hasSlash && !needsSlash) {
|
25 | return path.substr(path, path.length - 1);
|
26 | } else if (!hasSlash && needsSlash) {
|
27 | return `${path}/`;
|
28 | } else {
|
29 | return path;
|
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 | appBuild: resolveApp('build'),
|
53 | appPublic: resolveApp('public'),
|
54 | appHtml: resolveApp('public/index.html'),
|
55 | appIndexJs: resolveApp('src/index.js'),
|
56 | appPackageJson: resolveApp('package.json'),
|
57 | appSrc: resolveApp('src'),
|
58 | yarnLockFile: resolveApp('yarn.lock'),
|
59 | testsSetup: resolveApp('src/setupTests.js'),
|
60 | appNodeModules: resolveApp('node_modules'),
|
61 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
62 | servedPath: getServedPath(resolveApp('package.json')),
|
63 | };
|
64 |
|
65 |
|
66 | const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
|
67 |
|
68 |
|
69 | module.exports = {
|
70 | dotenv: resolveApp('.env'),
|
71 | appPath: resolveApp('.'),
|
72 | appBuild: resolveApp('build'),
|
73 | appPublic: resolveApp('public'),
|
74 | appHtml: resolveApp('public/index.html'),
|
75 | appIndexJs: resolveApp('src/index.js'),
|
76 | appPackageJson: resolveApp('package.json'),
|
77 | appSrc: resolveApp('src'),
|
78 | yarnLockFile: resolveApp('yarn.lock'),
|
79 | testsSetup: resolveApp('src/setupTests.js'),
|
80 | appNodeModules: resolveApp('node_modules'),
|
81 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
82 | servedPath: getServedPath(resolveApp('package.json')),
|
83 |
|
84 | ownPath: resolveOwn('.'),
|
85 | ownNodeModules: resolveOwn('node_modules'),
|
86 | };
|
87 |
|
88 | const ownPackageJson = require('../package.json');
|
89 | const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
90 | const reactScriptsLinked =
|
91 | fs.existsSync(reactScriptsPath) &&
|
92 | fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
93 |
|
94 |
|
95 | if (
|
96 | !reactScriptsLinked &&
|
97 | __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
|
98 | ) {
|
99 | module.exports = {
|
100 | dotenv: resolveOwn('template/.env'),
|
101 | appPath: resolveApp('.'),
|
102 | appBuild: resolveOwn('../../build'),
|
103 | appPublic: resolveOwn('template/public'),
|
104 | appHtml: resolveOwn('template/public/index.html'),
|
105 | appIndexJs: resolveOwn('template/src/index.js'),
|
106 | appPackageJson: resolveOwn('package.json'),
|
107 | appSrc: resolveOwn('template/src'),
|
108 | yarnLockFile: resolveOwn('template/yarn.lock'),
|
109 | testsSetup: resolveOwn('template/src/setupTests.js'),
|
110 | appNodeModules: resolveOwn('node_modules'),
|
111 | publicUrl: getPublicUrl(resolveOwn('package.json')),
|
112 | servedPath: getServedPath(resolveOwn('package.json')),
|
113 |
|
114 | ownPath: resolveOwn('.'),
|
115 | ownNodeModules: resolveOwn('node_modules'),
|
116 | };
|
117 | }
|
118 |
|