Remove the `start` CLI command and dependencies (#613)

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
This commit is contained in:
William Chargin 2018-08-07 11:00:09 -07:00 committed by GitHub
parent 9c781fcfee
commit 7a4401e3ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 91 deletions

View File

@ -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(

View File

@ -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"

View File

@ -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;
}

View File

@ -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();
}