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