1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var path = require('path');
|
14 | var fs = require('fs');
|
15 | var url = require('url');
|
16 |
|
17 |
|
18 |
|
19 | var 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 | var nodePaths = (process.env.NODE_PATH || '')
|
40 | .split(process.platform === 'win32' ? ';' : ':')
|
41 | .filter(Boolean)
|
42 | .filter(folder => !path.isAbsolute(folder))
|
43 | .map(resolveApp);
|
44 |
|
45 | var envPublicUrl = process.env.PUBLIC_URL;
|
46 |
|
47 | function ensureSlash(path, needsSlash) {
|
48 | var 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 | var publicUrl = getPublicUrl(appPackageJson);
|
70 | var servedUrl = envPublicUrl || (
|
71 | publicUrl ? url.parse(publicUrl).pathname : '/'
|
72 | );
|
73 | return ensureSlash(servedUrl, true);
|
74 | }
|
75 |
|
76 |
|
77 | module.exports = {
|
78 | appBuild: resolveApp('build'),
|
79 | appPublic: resolveApp('public'),
|
80 | appHtml: resolveApp('public/index.html'),
|
81 | appIndexJs: resolveApp('src/index.js'),
|
82 | appPackageJson: resolveApp('package.json'),
|
83 | appSrc: resolveApp('src'),
|
84 | yarnLockFile: resolveApp('yarn.lock'),
|
85 | testsSetup: resolveApp('src/setupTests.js'),
|
86 | appNodeModules: resolveApp('node_modules'),
|
87 | nodePaths: nodePaths,
|
88 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
89 | servedPath: getServedPath(resolveApp('package.json'))
|
90 | };
|
91 |
|
92 |
|
93 | function resolveOwn(relativePath) {
|
94 | return path.resolve(__dirname, '..', relativePath);
|
95 | }
|
96 |
|
97 |
|
98 | module.exports = {
|
99 | appPath: resolveApp('.'),
|
100 | appBuild: resolveApp('build'),
|
101 | appPublic: resolveApp('public'),
|
102 | appHtml: resolveApp('public/index.html'),
|
103 | appIndexJs: resolveApp('src/index.js'),
|
104 | appPackageJson: resolveApp('package.json'),
|
105 | appSrc: resolveApp('src'),
|
106 | yarnLockFile: resolveApp('yarn.lock'),
|
107 | testsSetup: resolveApp('src/setupTests.js'),
|
108 | appNodeModules: resolveApp('node_modules'),
|
109 | nodePaths: nodePaths,
|
110 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
111 | servedPath: getServedPath(resolveApp('package.json')),
|
112 |
|
113 | ownPath: resolveOwn('.'),
|
114 | ownNodeModules: resolveOwn('node_modules'),
|
115 | };
|
116 |
|
117 | var ownPackageJson = require('../package.json');
|
118 | var reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
119 | var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
120 |
|
121 |
|
122 | if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
|
123 | module.exports = {
|
124 | appPath: resolveApp('.'),
|
125 | appBuild: resolveOwn('../../build'),
|
126 | appPublic: resolveOwn('template/public'),
|
127 | appHtml: resolveOwn('template/public/index.html'),
|
128 | appIndexJs: resolveOwn('template/src/index.js'),
|
129 | appPackageJson: resolveOwn('package.json'),
|
130 | appSrc: resolveOwn('template/src'),
|
131 | yarnLockFile: resolveOwn('template/yarn.lock'),
|
132 | testsSetup: resolveOwn('template/src/setupTests.js'),
|
133 | appNodeModules: resolveOwn('node_modules'),
|
134 | nodePaths: nodePaths,
|
135 | publicUrl: getPublicUrl(resolveOwn('package.json')),
|
136 | servedPath: getServedPath(resolveOwn('package.json')),
|
137 |
|
138 | ownPath: resolveOwn('.'),
|
139 | ownNodeModules: resolveOwn('node_modules'),
|
140 | };
|
141 | }
|
142 |
|