Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/run/run.ts
6448 views
1
/*
2
* run.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { Command } from "cliffy/command/command.ts";
8
9
import { existsSync } from "../../deno_ral/fs.ts";
10
import { error } from "../../deno_ral/log.ts";
11
import { handlerForScript } from "../../core/run/run.ts";
12
import { exitWithCleanup } from "../../core/cleanup.ts";
13
14
export async function runScript(args: string[], env?: Record<string, string>) {
15
// Check for --dev flag
16
let dev = false;
17
let scriptArgs = args;
18
if (args[0] === "--dev") {
19
dev = true;
20
scriptArgs = args.slice(1);
21
}
22
23
const script = scriptArgs[0];
24
if (!script) {
25
error("quarto run: no script specified");
26
exitWithCleanup(1);
27
throw new Error(); // unreachable
28
}
29
if (!existsSync(script)) {
30
error("quarto run: script '" + script + "' not found");
31
exitWithCleanup(1);
32
throw new Error(); // unreachable
33
}
34
const handler = await handlerForScript(script);
35
if (!handler) {
36
error("quarto run: no handler found for script '" + script + "'");
37
exitWithCleanup(1);
38
throw new Error(); // unreachable
39
}
40
return await handler.run(script, scriptArgs.slice(1), undefined, {
41
env,
42
dev,
43
});
44
}
45
46
// run 'command' (this is a fake command that is here just for docs,
47
// the actual processing of 'run' bypasses cliffy entirely)
48
export const runCommand = new Command()
49
.name("run")
50
.stopEarly()
51
.arguments("[script:string] [...args]")
52
.description(
53
"Run a TypeScript, R, Python, or Lua script.\n\n" +
54
"Run a utility script written in a variety of languages. For details, see:\n" +
55
"https://quarto.org/docs/projects/scripts.html#periodic-scripts",
56
)
57
.option("--dev", "Use development import map (when running from source)", {
58
hidden: true,
59
});
60
61