diff --git a/src/cli2/merge.js b/src/cli2/merge.js deleted file mode 100644 index e35e5b0..0000000 --- a/src/cli2/merge.js +++ /dev/null @@ -1,53 +0,0 @@ -// @flow - -import fs from "fs-extra"; -import stringify from "json-stable-stringify"; -import {join as pathJoin} from "path"; - -import {LoggingTaskReporter} from "../util/taskReporter"; -import type {Command} from "./command"; -import {makePluginDir, loadInstanceConfig} from "./common"; -import { - toJSON as weightedGraphToJSON, - fromJSON as weightedGraphFromJSON, - type WeightedGraph, - merge, -} from "../core/weightedGraph"; - -function die(std, message) { - std.err("fatal: " + message); - return 1; -} - -const mergeCommand: Command = async (args, std) => { - if (args.length !== 0) { - return die(std, "usage: sourcecred merge"); - } - const taskReporter = new LoggingTaskReporter(); - taskReporter.start("merge"); - const baseDir = process.cwd(); - const config = await loadInstanceConfig(baseDir); - const graphOutputPrefix = ["output", "graphs"]; - - async function loadGraph(pluginName): Promise { - const outputDir = makePluginDir(baseDir, graphOutputPrefix, pluginName); - const outputPath = pathJoin(outputDir, "graph.json"); - const graphJSON = JSON.parse(await fs.readFile(outputPath)); - return weightedGraphFromJSON(graphJSON); - } - - const pluginNames = Array.from(config.bundledPlugins.keys()); - const graphs = await Promise.all(pluginNames.map(loadGraph)); - - // TODO: Support identity merging. - // TODO: Support weight overrides. - const combinedGraph = merge(graphs); - - const outputPath = pathJoin(baseDir, "output", "graph.json"); - const serializedGraph = stringify(weightedGraphToJSON(combinedGraph)); - await fs.writeFile(outputPath, serializedGraph); - taskReporter.finish("merge"); - return 0; -}; - -export default mergeCommand; diff --git a/src/cli2/score.js b/src/cli2/score.js index a0fee82..daddd81 100644 --- a/src/cli2/score.js +++ b/src/cli2/score.js @@ -5,9 +5,10 @@ import stringify from "json-stable-stringify"; import {join as pathJoin} from "path"; import type {Command} from "./command"; -import {loadInstanceConfig} from "./common"; +import {makePluginDir, loadInstanceConfig} from "./common"; import {fromJSON as weightedGraphFromJSON} from "../core/weightedGraph"; import {defaultParams} from "../analysis/timeline/params"; +import {type WeightedGraph, merge} from "../core/weightedGraph"; import {LoggingTaskReporter} from "../util/taskReporter"; import { compute, @@ -34,9 +35,17 @@ const scoreCommand: Command = async (args, std) => { const baseDir = process.cwd(); const config = await loadInstanceConfig(baseDir); - const graphFilePath = pathJoin(baseDir, "output", "graph.json"); - const graphJSON = JSON.parse(await fs.readFile(graphFilePath)); - const graph = weightedGraphFromJSON(graphJSON); + const graphOutputPrefix = ["output", "graphs"]; + async function loadGraph(pluginName): Promise { + const outputDir = makePluginDir(baseDir, graphOutputPrefix, pluginName); + const outputPath = pathJoin(outputDir, "graph.json"); + const graphJSON = JSON.parse(await fs.readFile(outputPath)); + return weightedGraphFromJSON(graphJSON); + } + + const pluginNames = Array.from(config.bundledPlugins.keys()); + const graphs = await Promise.all(pluginNames.map(loadGraph)); + const combinedGraph = merge(graphs); const plugins = Array.from(config.bundledPlugins.values()); const declarations = plugins.map((x) => x.declaration()); @@ -44,7 +53,7 @@ const scoreCommand: Command = async (args, std) => { // TODO: Support loading params from config. const params = defaultParams(); - const credResult = await compute(graph, params, declarations); + const credResult = await compute(combinedGraph, params, declarations); const compressed = compressByThreshold(credResult, CRED_THRESHOLD); const credJSON = stringify(credResultToJSON(compressed)); const outputPath = pathJoin(baseDir, "output", "credResult.json"); diff --git a/src/cli2/sourcecred.js b/src/cli2/sourcecred.js index b5a5d3f..6b41e35 100644 --- a/src/cli2/sourcecred.js +++ b/src/cli2/sourcecred.js @@ -4,7 +4,6 @@ import type {Command} from "./command"; import load from "./load"; import graph from "./graph"; -import merge from "./merge"; import score from "./score"; const sourcecred: Command = async (args, std) => { @@ -17,8 +16,6 @@ const sourcecred: Command = async (args, std) => { return load(args.slice(1), std); case "graph": return graph(args.slice(1), std); - case "merge": - return merge(args.slice(1), std); case "score": return score(args.slice(1), std); default: