Skip to content

Commit 775b4c2

Browse files
committed
Refactor by using a default handler
1 parent 9d31369 commit 775b4c2

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/command/render/project.ts

+32-28
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 { ProjectConfig as ProjectConfig_Project } from "../../resources/types/schema-types.ts";
84+
import { RunHandlerOptions } from "../../core/run/types.ts";
8485

8586
const noMutationValidations = (
8687
projType: ProjectType,
@@ -976,35 +977,38 @@ 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+
};
989995

990-
const result = await handler.run(script, args.splice(1), undefined, {
991-
cwd: projDir,
992-
stdout: quiet ? "piped" : "inherit",
993-
env,
994-
});
995-
if (!result.success) {
996-
throw new Error();
997-
}
998-
} else {
999-
const result = await execProcess({
1000-
cmd: args,
1001-
cwd: projDir,
1002-
stdout: quiet ? "piped" : "inherit",
1003-
env,
1004-
});
1005-
if (!result.success) {
1006-
throw new Error();
1007-
}
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+
}
1004+
1005+
const result = await handler.run(script, args.slice(1), undefined, {
1006+
cwd: projDir,
1007+
stdout: quiet ? "piped" : "inherit",
1008+
env,
1009+
});
1010+
if (!result.success) {
1011+
throw new Error();
10081012
}
10091013
}
10101014
if (scripts.length > 0) {

0 commit comments

Comments
 (0)