sourcecred/config/paths.js
William Chargin ca5346b524
Create a bridge for the V1 and V3 apps (#448)
Summary:
Our build system doesn’t make it easy to have two separate React
applications, which we would like to have for the V1 and V3 branches.
Instead, we’ll implement a bridge to maintain compatibility.

The plan looks like this:

 1. Change the app from pointing to V1 to pointing to a bridge
 2. Move the router into the bridge and move the V1 app from the `/`
    route to the `/v1` route (e.g., `/v1/explorer`)
 3. Add a V3 app under the `/v3` route
 4. ???
 5. Delete the V1 app and remove it from the bridge
 6. Delete the bridge and move the V3 app from the `/v3` route to `/`

This commit implements Step 1.

Test Plan:
To verify that the bridge is in fact showing, apply

```diff
diff --git a/src/bridge/app/index.js b/src/bridge/app/index.js
index 379e289..72e784c 100644
--- a/src/bridge/app/index.js
+++ b/src/bridge/app/index.js
@@ -9,5 +9,11 @@ const root = document.getElementById("root");
 if (root == null) {
   throw new Error("Unable to find root element!");
 }
-ReactDOM.render(<V1App />, root);
+ReactDOM.render(
+  <React.Fragment>
+    <h1>Hello</h1>
+    <V1App />
+  </React.Fragment>,
+  root
+);
 registerServiceWorker();
```

and say “hello” back to the app.

wchargin-branch: bridge
2018-06-29 13:09:39 -07:00

86 lines
3.2 KiB
JavaScript

// @flow
const path = require("path");
const fs = require("fs");
// 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 /*: string */, needsSlash /*: bool */) {
const hasSlash = path.endsWith("/");
if (hasSlash && !needsSlash) {
return path.substr(0, path.length - 1);
} else if (!hasSlash && needsSlash) {
return `${path}/`;
} else {
return path;
}
}
const getPublicUrl = () => envPublicUrl || "/";
// We use `PUBLIC_URL` environment variable field to infer "public path" at
// which the app is served. Defaults to "/"
// 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() {
return ensureSlash(getPublicUrl(), true);
}
// config after eject: we're in ./config/
module.exports = {
dotenv: resolveApp(".env"),
appBuild: resolveApp("build"),
appPublic: resolveApp("src/bridge/app/public"),
appHtml: resolveApp("src/bridge/app/public/index.html"),
appIndexJs: resolveApp("src/bridge/app/index.js"),
appPackageJson: resolveApp("package.json"),
appSrc: resolveApp("src"),
yarnLockFile: resolveApp("yarn.lock"),
testsSetup: resolveApp("src/v1/setupTests.js"),
appNodeModules: resolveApp("node_modules"),
publicUrl: getPublicUrl(),
servedPath: getServedPath(),
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: {
sourcecred: resolveApp("src/v1/cli/sourcecred.js"),
"commands/combine": resolveApp("src/v1/cli/commands/combine.js"),
"commands/graph": resolveApp("src/v1/cli/commands/graph.js"),
"commands/plugin-graph": resolveApp("src/v1/cli/commands/pluginGraph.js"),
"commands/start": resolveApp("src/v1/cli/commands/start.js"),
apiApp: resolveApp("src/v1/app/apiApp.js"),
//
sourcecredV3: resolveApp("src/v3/cli/sourcecred.js"),
"commands/load-plugin-v3": resolveApp("src/v3/cli/commands/loadPlugin.js"),
//
fetchAndPrintGithubRepo: resolveApp(
"src/v1/plugins/github/bin/fetchAndPrintGithubRepo.js"
),
fetchAndPrintGithubRepoV3: resolveApp(
"src/v3/plugins/github/bin/fetchAndPrintGithubRepo.js"
),
createExampleRepo: resolveApp(
"src/v1/plugins/git/bin/createExampleRepo.js"
),
createExampleRepoV3: resolveApp(
"src/v3/plugins/git/bin/createExampleRepo.js"
),
loadAndPrintGitRepository: resolveApp(
"src/v1/plugins/git/bin/loadAndPrintRepository.js"
),
loadAndPrintGitRepositoryV3: resolveApp(
"src/v3/plugins/git/bin/loadAndPrintRepository.js"
),
},
};