-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathdeno.ts
More file actions
138 lines (128 loc) · 3.4 KB
/
deno.ts
File metadata and controls
138 lines (128 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* deno.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*
*/
import { execProcess } from "../../../src/core/process.ts";
import { info } from "../../../src/deno_ral/log.ts";
import { isWindows } from "../../../src/deno_ral/platform.ts";
import { Configuration } from "../common/config.ts";
// TODO in we only use the bundler for quarto.ts
// so we hardcode it in the new esbuild-based bundler
export async function bundle(
configuration: Configuration,
) {
// Bundle source code
const denoBundleCmd: string[] = [];
const denoExecPath = Deno.env.get("QUARTO_DENO");
if (!denoExecPath) {
throw Error("QUARTO_DENO is not defined");
}
denoBundleCmd.push("run");
denoBundleCmd.push("--allow-all");
denoBundleCmd.push("../tools/deno-esbuild-bundle.ts");
/*
denoBundleCmd.push("--log-level");
denoBundleCmd.push("debug");
*/
// denoBundleCmd.push(input);
// denoBundleCmd.push(output);
const status = await execProcess({
cmd: denoExecPath,
args: denoBundleCmd,
cwd: configuration.directoryInfo.src,
});
if (status.code !== 0) {
throw Error(`Failure to bundle src/quarto.ts`);
}
}
export async function compile(
input: string,
output: string,
flags: string[],
configuration: Configuration,
) {
const denoBundleCmd: string[] = [];
const denoExecPath = Deno.env.get("QUARTO_DENO");
if (!denoExecPath) {
throw Error("QUARTO_DENO is not defined");
}
denoBundleCmd.push("compile");
denoBundleCmd.push("--unstable-kv");
denoBundleCmd.push("--unstable-ffi");
denoBundleCmd.push(
"--importmap=" + configuration.importmap,
);
denoBundleCmd.push("--output");
denoBundleCmd.push(output);
denoBundleCmd.push(...flags);
denoBundleCmd.push(input);
const status = await execProcess({
cmd: denoExecPath,
args: denoBundleCmd,
});
if (status.code !== 0) {
throw Error(`Failure to compile ${input}`);
}
}
export async function install(
input: string,
flags: string[],
configuration: Configuration,
) {
const denoBundleCmd: string[] = [];
const denoExecPath = Deno.env.get("QUARTO_DENO");
if (!denoExecPath) {
throw Error("QUARTO_DENO is not defined");
}
denoBundleCmd.push("install");
denoBundleCmd.push("--unstable-kv");
denoBundleCmd.push("--unstable-ffi");
denoBundleCmd.push(
"--importmap=" + configuration.importmap,
);
denoBundleCmd.push(...flags);
denoBundleCmd.push(input);
const status = await execProcess({
cmd: denoExecPath,
args: denoBundleCmd,
stdout: "piped",
});
if (status.code !== 0) {
throw Error(`Failure to install ${input}`);
}
if (status.stdout) {
// Forward the output
info(status.stdout);
const match = status.stdout.match(/Successfully installed.*\n(.*)/);
if (match) {
return match[1];
}
}
return undefined;
}
export function updateDenoPath(installPath: string, _config: Configuration) {
// Fix up the path to deno
if (installPath) {
info("Updating install script deno path");
const installTxt = Deno.readTextFileSync(installPath);
const denoExecPath = Deno.env.get("QUARTO_DENO");
if (!denoExecPath) {
throw Error("QUARTO_DENO is not defined");
}
const finalTxt = isWindows
? installTxt.replace(
/deno.exe /g,
denoExecPath + " ",
)
: installTxt.replace(
/deno /g,
denoExecPath + " ",
);
Deno.writeTextFileSync(
installPath,
finalTxt,
);
}
}