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 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
21 |
|
22 | const envPublicUrl = process.env.PUBLIC_URL;
|
23 |
|
24 | function ensureSlash(path, needsSlash) {
|
25 | const hasSlash = path.endsWith('/');
|
26 | if (hasSlash && !needsSlash) {
|
27 | return path.substr(path, path.length - 1);
|
28 | } else if (!hasSlash && needsSlash) {
|
29 | return `${path}/`;
|
30 | } else {
|
31 | return path;
|
32 | }
|
33 | }
|
34 |
|
35 | const getPublicUrl = appPackageJson =>
|
36 | envPublicUrl || require(appPackageJson).homepage;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | function getServedPath(appPackageJson) {
|
45 | const publicUrl = getPublicUrl(appPackageJson);
|
46 | const servedUrl = envPublicUrl ||
|
47 | (publicUrl ? url.parse(publicUrl).pathname : '/');
|
48 | return ensureSlash(servedUrl, true);
|
49 | }
|
50 |
|
51 |
|
52 | module.exports = {
|
53 | dotenv: resolveApp('.env'),
|
54 | appBuild: resolveApp('build'),
|
55 | appPublic: resolveApp('public'),
|
56 | appHtml: resolveApp('public/index.html'),
|
57 | appIndexJs: resolveApp('src/index.js'),
|
58 | appPackageJson: resolveApp('package.json'),
|
59 | appSrc: resolveApp('src'),
|
60 | yarnLockFile: resolveApp('yarn.lock'),
|
61 | testsSetup: resolveApp('src/setupTests.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 | appNodeModules: resolveApp('node_modules'),
|
83 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
84 | servedPath: getServedPath(resolveApp('package.json')),
|
85 |
|
86 | ownPath: resolveOwn('.'),
|
87 | ownNodeModules: resolveOwn('node_modules'),
|
88 | };
|
89 |
|
90 | const ownPackageJson = require('../package.json');
|
91 | const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
92 | const reactScriptsLinked = fs.existsSync(reactScriptsPath) &&
|
93 | fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
94 |
|
95 |
|
96 | if (
|
97 | !reactScriptsLinked &&
|
98 | __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
|
99 | ) {
|
100 | module.exports = {
|
101 | dotenv: resolveOwn('template/.env'),
|
102 | appPath: resolveApp('.'),
|
103 | appBuild: resolveOwn('../../build'),
|
104 | appPublic: resolveOwn('template/public'),
|
105 | appHtml: resolveOwn('template/public/index.html'),
|
106 | appIndexJs: resolveOwn('template/src/index.js'),
|
107 | appPackageJson: resolveOwn('package.json'),
|
108 | appSrc: resolveOwn('template/src'),
|
109 | yarnLockFile: resolveOwn('template/yarn.lock'),
|
110 | testsSetup: resolveOwn('template/src/setupTests.js'),
|
111 | appNodeModules: resolveOwn('node_modules'),
|
112 | publicUrl: getPublicUrl(resolveOwn('package.json')),
|
113 | servedPath: getServedPath(resolveOwn('package.json')),
|
114 |
|
115 | ownPath: resolveOwn('.'),
|
116 | ownNodeModules: resolveOwn('node_modules'),
|
117 | };
|
118 | }
|
119 |
|