73 lines
2.8 KiB
JavaScript
73 lines
2.8 KiB
JavaScript
const path = require("path");
|
|
const fs = require("fs");
|
|
const url = require("url");
|
|
|
|
// Make sure any symlinks in the project folder are resolved:
|
|
// https://github.com/facebookincubator/create-react-app/issues/637
|
|
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;
|
|
|
|
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
|
// "public path" at which the app is served.
|
|
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
|
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
|
// We can't use a relative path in HTML because we don't want to load something
|
|
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
|
function getServedPath(appPackageJson) {
|
|
const publicUrl = getPublicUrl(appPackageJson);
|
|
const servedUrl =
|
|
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : "/");
|
|
return ensureSlash(servedUrl, true);
|
|
}
|
|
|
|
// config after eject: we're in ./config/
|
|
module.exports = {
|
|
dotenv: resolveApp(".env"),
|
|
appBuild: resolveApp("build"),
|
|
appPublic: resolveApp("src/plugins/artifact/editor/public"),
|
|
appHtml: resolveApp("src/plugins/artifact/editor/public/index.html"),
|
|
appIndexJs: resolveApp("src/plugins/artifact/editor/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")),
|
|
|
|
backendBuild: resolveApp("bin"),
|
|
// This object should have one key-value pair per entry point. For
|
|
// each key, the value should be the path to the entry point for the
|
|
// source file, and the key will be the filename of the bundled entry
|
|
// point within the build directory.
|
|
backendEntryPoints: {
|
|
"commands/combine": resolveApp("src/cli/commands/combine.js"),
|
|
"commands/graph": resolveApp("src/cli/commands/graph.js"),
|
|
"commands/plugin-graph": resolveApp("src/cli/commands/pluginGraph.js"),
|
|
sourcecred: resolveApp("src/cli/sourcecred.js"),
|
|
fetchAndPrintGithubRepo: resolveApp(
|
|
"src/plugins/github/bin/fetchAndPrintGithubRepo.js"
|
|
),
|
|
createExampleRepo: resolveApp("src/plugins/git/bin/createExampleRepo.js"),
|
|
loadAndPrintGitRepository: resolveApp(
|
|
"src/plugins/git/bin/loadAndPrintRepository.js"
|
|
),
|
|
},
|
|
};
|