1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 'use strict';
-
- const path = require('path');
- const fs = require('fs');
- const url = require('url');
-
-
-
- const appDirectory = fs.realpathSync(process.cwd());
- const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
-
- const envPublicUrl = process.env.PUBLIC_URL;
-
- function ensureSlash(path, needsSlash) {
- const hasSlash = path.endsWith('/');
- if (hasSlash && !needsSlash) {
- return path.substr(path, path.length - 1);
- } else if (!hasSlash && needsSlash) {
- return `${path}/`;
- } else {
- return path;
- }
- }
-
- const getPublicUrl = appPackageJson =>
- envPublicUrl || require(appPackageJson).homepage;
-
-
-
-
-
-
-
- function getServedPath(appPackageJson) {
- const publicUrl = getPublicUrl(appPackageJson);
- const servedUrl =
- envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
- return ensureSlash(servedUrl, true);
- }
-
-
- module.exports = {
- dotenv: resolveApp('.env'),
- appBuild: resolveApp('build'),
- appPublic: resolveApp('public'),
- appHtml: resolveApp('public/index.html'),
- appIndexJs: resolveApp('src/index.js'),
- appPackageJson: resolveApp('package.json'),
- appSrc: resolveApp('src'),
- yarnLockFile: resolveApp('yarn.lock'),
- testsSetup: resolveApp('src/setupTests.js'),
- appNodeModules: resolveApp('node_modules'),
- publicUrl: getPublicUrl(resolveApp('package.json')),
- servedPath: getServedPath(resolveApp('package.json')),
- };
|