Skip to content

Improve pre/post render script logging #12444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 47 additions & 37 deletions src/command/render/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { fileExecutionEngine } from "../../execute/engine.ts";
import { projectContextForDirectory } from "../../project/project-context.ts";
import { ProjectType } from "../../project/types/types.ts";
import { ProjectConfig as ProjectConfig_Project } from "../../resources/types/schema-types.ts";
import { RunHandlerOptions } from "../../core/run/types.ts";

const noMutationValidations = (
projType: ProjectType,
Expand Down Expand Up @@ -957,51 +958,60 @@ async function runScripts(
quiet: boolean,
env?: { [key: string]: string },
) {
// initialize the environment if needed
if (env) {
env = {
...env,
};
} else {
env = {};
}
if (!env) throw new Error("should never get here");

// Pass some argument as environment
env["QUARTO_PROJECT_SCRIPT_PROGRESS"] = progress ? "1" : "0";
env["QUARTO_PROJECT_SCRIPT_QUIET"] = quiet ? "1" : "0";

for (let i = 0; i < scripts.length; i++) {
const args = parseShellRunCommand(scripts[i]);
const script = args[0];

if (progress && !quiet) {
info(colors.bold(colors.blue(`${script}`)));
info(colors.bold(colors.blue(`Running script '${script}'`)));
}

const handler = handlerForScript(script);
if (handler) {
if (env) {
env = {
...env,
};
} else {
env = {};
}
if (!env) throw new Error("should never get here");
const input = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES");
const output = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES");
if (input) {
env["QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES"] = input;
}
if (output) {
env["QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES"] = output;
}
const handler = handlerForScript(script) ?? {
run: async (
script: string,
args: string[],
_stdin?: string,
options?: RunHandlerOptions,
) => {
return await execProcess({
cmd: [script, ...args],
cwd: options?.cwd,
stdout: options?.stdout,
env: options?.env,
});
},
};

const result = await handler.run(script, args.splice(1), undefined, {
cwd: projDir,
stdout: quiet ? "piped" : "inherit",
env,
});
if (!result.success) {
throw new Error();
}
} else {
const result = await execProcess({
cmd: args,
cwd: projDir,
stdout: quiet ? "piped" : "inherit",
env,
});
if (!result.success) {
throw new Error();
}
const input = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES");
const output = Deno.env.get("QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES");
if (input) {
env["QUARTO_USE_FILE_FOR_PROJECT_INPUT_FILES"] = input;
}
if (output) {
env["QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES"] = output;
}

const result = await handler.run(script, args.slice(1), undefined, {
cwd: projDir,
stdout: quiet ? "piped" : "inherit",
env,
});
if (!result.success) {
throw new Error();
}
}
if (scripts.length > 0) {
Expand Down
Loading