Skip to content

Commit 33ff1d9

Browse files
committed
Refactor by using a default handler
1 parent c01594e commit 33ff1d9

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/command/render/project.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import { fileExecutionEngine } from "../../execute/engine.ts";
8181
import { projectContextForDirectory } from "../../project/project-context.ts";
8282
import { ProjectType } from "../../project/types/types.ts";
8383
import { Zod } from "../../resources/types/zod/schema-types.ts";
84+
import { RunHandlerOptions } from "../../core/run/types.ts";
8485

8586
const noMutationValidations = (
8687
projType: ProjectType,
@@ -976,16 +977,30 @@ async function runScripts(
976977
env["QUARTO_PROJECT_SCRIPT_PROGRESS"] = "1";
977978
}
978979

979-
const handler = handlerForScript(script);
980-
if (handler) {
981-
const input = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES");
982-
const output = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES");
983-
if (input) {
984-
env["QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES"] = input;
985-
}
986-
if (output) {
987-
env["QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES"] = output;
988-
}
980+
const handler = handlerForScript(script) ?? {
981+
run: async (
982+
script: string,
983+
args: string[],
984+
_stdin?: string,
985+
options?: RunHandlerOptions,
986+
) => {
987+
return await execProcess({
988+
cmd: [script, ...args],
989+
cwd: options?.cwd,
990+
stdout: options?.stdout,
991+
env: options?.env,
992+
});
993+
},
994+
};
995+
996+
const input = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES");
997+
const output = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES");
998+
if (input) {
999+
env["QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES"] = input;
1000+
}
1001+
if (output) {
1002+
env["QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES"] = output;
1003+
}
9891004

9901005
const result = await handler.run(script, args.splice(1), undefined, {
9911006
cwd: projDir,
@@ -997,8 +1012,7 @@ async function runScripts(
9971012
}
9981013
} else {
9991014
const result = await execProcess({
1000-
cmd: args[0],
1001-
args: args.slice(1),
1015+
cmd: args,
10021016
cwd: projDir,
10031017
stdout: quiet ? "piped" : "inherit",
10041018
env,

0 commit comments

Comments
 (0)