Add load CLI command (#470)
The `load` command replaces `plugin-load`. By default, it loads data for all plugins, and does so in parallel using execDependencyGraph. If passed the optional `--plugin` flag, then it will load data just for that plugin. As an implementation detail, when loading all plugins, load calls itself with the plugin flag set. Usage: `node bin/sourcecred.js load repoOwner repoName` Test plan: Tested by hand; I blew away my SourceCred directory and then loaded the example-github repository.
This commit is contained in:
parent
bb75cc54cd
commit
addaf4e2a8
|
@ -61,7 +61,7 @@ module.exports = {
|
||||||
apiApp: resolveApp("src/bridge/app/apiApp.js"),
|
apiApp: resolveApp("src/bridge/app/apiApp.js"),
|
||||||
//
|
//
|
||||||
sourcecredV3: resolveApp("src/v3/cli/sourcecred.js"),
|
sourcecredV3: resolveApp("src/v3/cli/sourcecred.js"),
|
||||||
"commands/load-plugin-v3": resolveApp("src/v3/cli/commands/loadPlugin.js"),
|
"commands/load": resolveApp("src/v3/cli/commands/load.js"),
|
||||||
//
|
//
|
||||||
fetchAndPrintGithubRepo: resolveApp(
|
fetchAndPrintGithubRepo: resolveApp(
|
||||||
"src/v1/plugins/github/bin/fetchAndPrintGithubRepo.js"
|
"src/v1/plugins/github/bin/fetchAndPrintGithubRepo.js"
|
||||||
|
|
|
@ -6,10 +6,17 @@ import path from "path";
|
||||||
|
|
||||||
import {loadGithubData} from "../../plugins/github/loadGithubData";
|
import {loadGithubData} from "../../plugins/github/loadGithubData";
|
||||||
import {loadGitData} from "../../plugins/git/loadGitData";
|
import {loadGitData} from "../../plugins/git/loadGitData";
|
||||||
import {pluginNames, sourcecredDirectoryFlag} from "../common";
|
import {
|
||||||
|
pluginNames,
|
||||||
|
nodeMaxOldSpaceSizeFlag,
|
||||||
|
sourcecredDirectoryFlag,
|
||||||
|
} from "../common";
|
||||||
|
|
||||||
|
const execDependencyGraph = require("../../../tools/execDependencyGraph")
|
||||||
|
.default;
|
||||||
|
|
||||||
export default class PluginGraphCommand extends Command {
|
export default class PluginGraphCommand extends Command {
|
||||||
static description = "load data required for a single plugin";
|
static description = "load data required for SourceCred";
|
||||||
|
|
||||||
static args = [
|
static args = [
|
||||||
{
|
{
|
||||||
|
@ -26,11 +33,12 @@ export default class PluginGraphCommand extends Command {
|
||||||
|
|
||||||
static flags = {
|
static flags = {
|
||||||
plugin: flags.string({
|
plugin: flags.string({
|
||||||
description: "plugin whose data to load",
|
description: "plugin whose data to load (loads all plugins if not set)",
|
||||||
required: true,
|
required: false,
|
||||||
options: pluginNames(),
|
options: pluginNames(),
|
||||||
}),
|
}),
|
||||||
"sourcecred-directory": sourcecredDirectoryFlag(),
|
"sourcecred-directory": sourcecredDirectoryFlag(),
|
||||||
|
"max-old-space-size": nodeMaxOldSpaceSizeFlag(),
|
||||||
"github-token": flags.string({
|
"github-token": flags.string({
|
||||||
description:
|
description:
|
||||||
"a GitHub API token, as generated at " +
|
"a GitHub API token, as generated at " +
|
||||||
|
@ -46,13 +54,57 @@ export default class PluginGraphCommand extends Command {
|
||||||
flags: {
|
flags: {
|
||||||
"github-token": githubToken,
|
"github-token": githubToken,
|
||||||
"sourcecred-directory": basedir,
|
"sourcecred-directory": basedir,
|
||||||
|
"max-old-space-size": maxOldSpaceSize,
|
||||||
plugin,
|
plugin,
|
||||||
},
|
},
|
||||||
} = this.parse(PluginGraphCommand);
|
} = this.parse(PluginGraphCommand);
|
||||||
loadPlugin({basedir, plugin, repoOwner, repoName, githubToken});
|
if (!plugin) {
|
||||||
|
loadAllPlugins({
|
||||||
|
basedir,
|
||||||
|
plugin,
|
||||||
|
repoOwner,
|
||||||
|
repoName,
|
||||||
|
githubToken,
|
||||||
|
maxOldSpaceSize,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
loadPlugin({basedir, plugin, repoOwner, repoName, githubToken});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadAllPlugins({repoOwner, repoName, githubToken, maxOldSpaceSize}) {
|
||||||
|
if (githubToken == null) {
|
||||||
|
// TODO: This check should be abstracted so that plugins can
|
||||||
|
// specify their argument dependencies and get nicely
|
||||||
|
// formatted errors.
|
||||||
|
console.error("fatal: No GitHub token specified. Try `--help'.");
|
||||||
|
process.exitCode = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tasks = [
|
||||||
|
...pluginNames().map((pluginName) => ({
|
||||||
|
id: `load-${pluginName}`,
|
||||||
|
cmd: [
|
||||||
|
"node",
|
||||||
|
`--max_old_space_size=${maxOldSpaceSize}`,
|
||||||
|
"./bin/sourcecred.js",
|
||||||
|
"load",
|
||||||
|
repoOwner,
|
||||||
|
repoName,
|
||||||
|
"--plugin",
|
||||||
|
pluginName,
|
||||||
|
"--github-token",
|
||||||
|
githubToken,
|
||||||
|
],
|
||||||
|
deps: [],
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
execDependencyGraph(tasks, {taskPassLabel: "DONE"}).then(({success}) => {
|
||||||
|
process.exitCode = success ? 0 : 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function loadPlugin({basedir, plugin, repoOwner, repoName, githubToken}) {
|
function loadPlugin({basedir, plugin, repoOwner, repoName, githubToken}) {
|
||||||
const outputDirectory = path.join(
|
const outputDirectory = path.join(
|
||||||
basedir,
|
basedir,
|
Loading…
Reference in New Issue