From 7a4401e3efdc2c1619cd56302046e8363e092b1d Mon Sep 17 00:00:00 2001 From: William Chargin Date: Tue, 7 Aug 2018 11:00:09 -0700 Subject: [PATCH] Remove the `start` CLI command and dependencies (#613) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: We never use the `node ./bin/sourcecred.js start` command. This command contains an Express server to combine the static files with the build output, which duplicates the logic in our Webpack config, which we actually use (with `yarn start`). Once we actually want the command line entry point to be a useful tool for end users, we can consider reimplementing it the right way, whatever that may be. Until then, it’s simply one more thing to keep in sync. Test Plan: Running `yarn test --full` passes; the `load` CLI command still works; running `yarn start` still works. wchargin-branch: remove-start --- config/makeWebpackConfig.js | 1 - config/paths.js | 3 -- src/app/apiApp.js | 15 -------- src/cli/commands/start.js | 72 ------------------------------------- 4 files changed, 91 deletions(-) delete mode 100644 src/app/apiApp.js delete mode 100644 src/cli/commands/start.js diff --git a/config/makeWebpackConfig.js b/config/makeWebpackConfig.js index b33d272..481e694 100644 --- a/config/makeWebpackConfig.js +++ b/config/makeWebpackConfig.js @@ -43,7 +43,6 @@ function makeConfig(mode /*: "production" | "development" */) { devServer: { inline: false, before: (app /*: ExpressApp */) => { - // TODO(@wchargin): De-duplicate this code. app.use( "/api/v1/data", express.static( diff --git a/config/paths.js b/config/paths.js index ada7bc7..b3e9e89 100644 --- a/config/paths.js +++ b/config/paths.js @@ -53,11 +53,8 @@ module.exports = { // source file, and the key will be the filename of the bundled entry // point within the build directory. backendEntryPoints: { - apiApp: resolveApp("src/app/apiApp.js"), - // sourcecred: resolveApp("src/cli/sourcecred.js"), "commands/load": resolveApp("src/cli/commands/load.js"), - "commands/start": resolveApp("src/cli/commands/start.js"), // fetchAndPrintGithubRepo: resolveApp( "src/plugins/github/bin/fetchAndPrintGithubRepo.js" diff --git a/src/app/apiApp.js b/src/app/apiApp.js deleted file mode 100644 index 8835f0c..0000000 --- a/src/app/apiApp.js +++ /dev/null @@ -1,15 +0,0 @@ -// @flow - -import express from "express"; - -export default function apiApp( - sourcecredDirectory: string, - staticFiles?: string -) { - const app = express(); - app.use("/api/v1/data", express.static(sourcecredDirectory)); - if (staticFiles != null) { - app.use(express.static(staticFiles)); - } - return app; -} diff --git a/src/cli/commands/start.js b/src/cli/commands/start.js deleted file mode 100644 index 1bed719..0000000 --- a/src/cli/commands/start.js +++ /dev/null @@ -1,72 +0,0 @@ -// @flow - -import {Command} from "@oclif/command"; -import chalk from "chalk"; -import fs from "fs"; -import {choosePort} from "react-dev-utils/WebpackDevServerUtils"; - -import apiApp from "../../app/apiApp"; -import {sourcecredDirectoryFlag} from "../common"; - -const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 4000; -const HOST = process.env.HOST || "0.0.0.0"; - -export default class StartCommand extends Command { - static description = "start a web server to explore the contribution graph"; - - static flags = { - "sourcecred-directory": sourcecredDirectoryFlag(), - }; - - async run() { - const { - flags: {"sourcecred-directory": sourcecredDirectory}, - } = this.parse(StartCommand); - startServer(sourcecredDirectory); - } -} - -async function startServer(sourcecredDirectory: string) { - let server; - function cleanup() { - if (server && server.listening) { - server.close(); - } - } - - let shuttingDown = false; - ["SIGINT", "SIGTERM"].forEach((signal) => { - process.on(signal, () => { - if (shuttingDown) { - // Force shut-down. - process.exit(2); - } else { - shuttingDown = true; - console.log("\nShutting down."); - cleanup(); - } - }); - }); - - const staticFiles = "./build/"; - if (!fs.existsSync(staticFiles)) { - console.error("Build output not found. Did you run `yarn build`?"); - } - - console.log(chalk.bold("Starting Express...")); - const expressApp = apiApp(sourcecredDirectory, staticFiles); - server = await new Promise(async (resolve, _unused_reject) => { - const port = await choosePort(HOST, DEFAULT_PORT); - let server = expressApp.listen(port, () => { - resolve(server); - }); - }); - server.on("close", () => { - console.log(chalk.bold("Express server closed.")); - cleanup(); - }); - console.log( - chalk.green(`Server listening on port ${server.address().port}.`) - ); - console.log(); -}