1 | 'use strict';
|
2 |
|
3 | const path = require('path');
|
4 | const fs = require('fs');
|
5 | const url = require('url');
|
6 |
|
7 |
|
8 |
|
9 | const appDirectory = fs.realpathSync(process.cwd());
|
10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
11 |
|
12 | const envPublicUrl = process.env.PUBLIC_URL;
|
13 |
|
14 | function ensureSlash(path, needsSlash) {
|
15 | const hasSlash = path.endsWith('/');
|
16 | if (hasSlash && !needsSlash) {
|
17 | return path.substr(path, path.length - 1);
|
18 | } else if (!hasSlash && needsSlash) {
|
19 | return `${path}/`;
|
20 | } else {
|
21 | return path;
|
22 | }
|
23 | }
|
24 |
|
25 | const getPublicUrl = appPackageJson =>
|
26 | envPublicUrl || require(appPackageJson).homepage;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function getServedPath(appPackageJson) {
|
35 | const publicUrl = getPublicUrl(appPackageJson);
|
36 | const servedUrl =
|
37 | envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
38 | return ensureSlash(servedUrl, true);
|
39 | }
|
40 |
|
41 |
|
42 | module.exports = {
|
43 | dotenv: resolveApp('.env'),
|
44 | appBuild: resolveApp('build'),
|
45 | appPublic: resolveApp('public'),
|
46 | appHtml: resolveApp('public/index.html'),
|
47 | appIndexJs: resolveApp('src/index.web.js'),
|
48 | appPackageJson: resolveApp('package.json'),
|
49 | appSrc: resolveApp('src'),
|
50 | yarnLockFile: resolveApp('yarn.lock'),
|
51 | appNodeModules: resolveApp('node_modules'),
|
52 | publicUrl: getPublicUrl(resolveApp('package.json')),
|
53 | servedPath: getServedPath(resolveApp('package.json')),
|
54 | };
|