Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/cmd/pkg-cmd.ts
6450 views
1
/*
2
* pkg-cmd.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { Command } from "cliffy/command/mod.ts";
8
import { join } from "../../../src/deno_ral/path.ts";
9
10
import { group } from "../../../src/tools/github.ts";
11
12
import { configurationAST, printConfiguration } from "../common/config.ts";
13
14
import {
15
Configuration,
16
kValidArch,
17
kValidOS,
18
readConfiguration,
19
} from "../common/config.ts";
20
import { logPandocJson } from "../../../src/core/log.ts";
21
22
export const kLogLevel = "logLevel";
23
export const kVersion = "setVersion";
24
25
export function packageCommand(run: (config: Configuration) => Promise<void>, commandName: string) {
26
return new Command().option(
27
"-sv, --set-version [version:string]",
28
"Version to set when preparing this distribution",
29
).option(
30
"-o, --os [os:string]",
31
"Operating system for this command (" + kValidOS.join(", ") + ")",
32
)
33
.option(
34
"-a, --arch [arch:string]",
35
"Architecture for this command (" + kValidArch.join(", ") + ")",
36
)
37
// deno-lint-ignore no-explicit-any
38
.action(async (args: Record<string, any>) => {
39
const version = args[kVersion];
40
const os = args["os"];
41
const arch = args["arch"];
42
43
// Read the version and configuration
44
const config = readConfiguration(version, os, arch);
45
46
// Set up the bin and share environment for any downstream code
47
Deno.env.set("QUARTO_BIN_PATH", config.directoryInfo.bin);
48
Deno.env.set(
49
"QUARTO_SHARE_PATH",
50
join(config.directoryInfo.src, "resources"),
51
);
52
Deno.env.set("QUARTO_DEBUG", "true");
53
54
// Print the configuration
55
await group("Configuration info", async () => {
56
try {
57
await logPandocJson(configurationAST(config));
58
} catch (e) {
59
printConfiguration(config);
60
}
61
});
62
63
await group(commandName, async () => {
64
// Run the command
65
await run(config);
66
});
67
}).name(commandName);
68
}
69
70