diff --git a/config/paths.js b/config/paths.js index cbcd68f..f94b4e5 100644 --- a/config/paths.js +++ b/config/paths.js @@ -33,8 +33,5 @@ module.exports = { "src/plugins/github/bin/fetchAndPrintGithubRepo.js" ), createExampleRepo: resolveApp("src/plugins/git/bin/createExampleRepo.js"), - loadAndPrintGitRepository: resolveApp( - "src/plugins/git/bin/loadAndPrintRepository.js" - ), }, }; diff --git a/src/plugins/git/bin/loadAndPrintRepository.js b/src/plugins/git/bin/loadAndPrintRepository.js deleted file mode 100644 index c23e62a..0000000 --- a/src/plugins/git/bin/loadAndPrintRepository.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Command-line utility to load a Git repository into memory and then - * print the resulting JSON representation. - * - * Usage: - * - * node bin/loadAndPrintGitRepository.js PATH [ROOT_REF] - * - * where PATH is the path on disk to a Git repository, and ROOT_REF is - * the revision to load (defaults to HEAD). - */ -// @flow - -import stringify from "json-stable-stringify"; - -import {loadRepository} from "../loadRepository"; - -function parseArgs() { - const argv = process.argv.slice(2); - if (argv.length !== 1 && argv.length !== 2) { - const invocation = process.argv.slice(0, 2).join(" "); - throw new Error(`Usage: ${invocation} PATH`); - } - return { - repositoryPath: argv[0], - rootRef: argv.length > 1 ? argv[1] : "HEAD", - }; -} - -function main() { - const args = parseArgs(); - const result = loadRepository(args.repositoryPath, args.rootRef); - console.log(stringify(result, {space: 4})); -} - -main(); diff --git a/src/plugins/git/example/example-git.json b/src/plugins/git/example/example-git.json index 8cd0c5b..c957c5f 100644 --- a/src/plugins/git/example/example-git.json +++ b/src/plugins/git/example/example-git.json @@ -26,8 +26,7 @@ }, "c2b51945e7457546912a8ce158ed9d294558d294": { "hash": "c2b51945e7457546912a8ce158ed9d294558d294", - "parentHashes": [ - ] + "parentHashes": [] }, "d160cca97611e9dfed642522ad44408d0292e8ea": { "hash": "d160cca97611e9dfed642522ad44408d0292e8ea", diff --git a/src/plugins/git/loadGitData.js b/src/plugins/git/loadGitData.js index 31212de..d01fc80 100644 --- a/src/plugins/git/loadGitData.js +++ b/src/plugins/git/loadGitData.js @@ -2,6 +2,7 @@ import fs from "fs-extra"; import path from "path"; +import stringify from "json-stable-stringify"; import type {Repo} from "../../core/repo"; import cloneAndLoadRepository from "./cloneAndLoadRepository"; @@ -18,7 +19,13 @@ export function loadGitData(options: Options): Promise { const repositories = options.repos.map((r) => cloneAndLoadRepository(r)); const repository = mergeRepository(repositories); const graph = createGraph(repository); - const blob = JSON.stringify(graph); - const outputFilename = path.join(options.outputDirectory, "graph.json"); - return fs.writeFile(outputFilename, blob); + function writeToFile(filename, serializable) { + const blob = stringify(serializable); + const filePath = path.join(options.outputDirectory, filename); + return fs.writeFile(filePath, blob); + } + return Promise.all([ + writeToFile("repository.json", repository), + writeToFile("graph.json", graph), + ]).then(() => undefined); } diff --git a/src/plugins/git/loadRepositoryTest.sh b/src/plugins/git/loadRepositoryTest.sh index 1f7cf70..d091175 100755 --- a/src/plugins/git/loadRepositoryTest.sh +++ b/src/plugins/git/loadRepositoryTest.sh @@ -23,8 +23,11 @@ usage() { fetch() { tmpdir="$(mktemp -d)" - node "${SOURCECRED_BIN:-./bin}/createExampleRepo.js" "${tmpdir}" - node "${SOURCECRED_BIN:-./bin}/loadAndPrintGitRepository.js" "${tmpdir}" + SOURCECRED_DIRECTORY="${tmpdir}" \ + node "${SOURCECRED_BIN:-./bin}/sourcecred.js" \ + load --plugin git \ + sourcecred/example-git + python -m json.tool "${tmpdir}"/data/sourcecred/example-git/git/repository.json rm -rf "${tmpdir}" }