From f51dff6a792fa7d78156ec03fc3a4f6cae7685a4 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:44:02 -0500 Subject: [PATCH] view: Add --customBuildOnly option When specified, this prevents falling back to running from build files in Auspice's root directory, which can be unintentional when running from an external project. --- cli/view.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/view.js b/cli/view.js index 5c60c8746..303e1bc4f 100644 --- a/cli/view.js +++ b/cli/view.js @@ -24,6 +24,7 @@ const addParser = (parser) => { subparser.addArgument('--handlers', {action: "store", metavar: "JS", help: "Overwrite the provided server handlers for client requests. See documentation for more details."}); subparser.addArgument('--datasetDir', {metavar: "PATH", help: "Directory where datasets (JSONs) are sourced. This is ignored if you define custom handlers."}); subparser.addArgument('--narrativeDir', {metavar: "PATH", help: "Directory where narratives (Markdown files) are sourced. This is ignored if you define custom handlers."}); + subparser.addArgument('--customBuildOnly', {action: "storeTrue", help: "Error if a custom build is not found."}); /* there are some options which we deliberately do not document via `--help`. */ subparser.addArgument('--gh-pages', {action: "store", help: SUPPRESS}); /* related to the "static-site-generation" or "github-pages" */ }; @@ -74,14 +75,14 @@ const loadAndAddHandlers = ({app, handlersArg, datasetDir, narrativeDir}) => { `Looking for datasets in ${datasetsPath}\nLooking for narratives in ${narrativesPath}`; }; -const getAuspiceBuild = () => { +const getAuspiceBuild = (customBuildOnly) => { const cwd = path.resolve(process.cwd()); const sourceDir = path.resolve(__dirname, ".."); // Default to current working directory. let baseDir = cwd; if (!hasAuspiceBuild(cwd)) { - if (cwd === sourceDir) { + if (cwd === sourceDir || customBuildOnly) { utils.error(`Auspice build files not found under ${cwd}. Did you run \`auspice build\` in this directory?`); process.exit(1); } @@ -115,7 +116,7 @@ const run = (args) => { app.use(compression()); app.use(nakedRedirect({reverse: true})); /* redirect www.name.org to name.org */ - const auspiceBuild = getAuspiceBuild(); + const auspiceBuild = getAuspiceBuild(args.customBuildOnly); utils.verbose(`Serving favicon from "${auspiceBuild.baseDir}"`); utils.verbose(`Serving index and built javascript from "${auspiceBuild.distDir}"`); app.get("/favicon.png", (req, res) => {res.sendFile(path.join(auspiceBuild.baseDir, "favicon.png"));});