-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathinstaller.ts
More file actions
177 lines (155 loc) · 4.78 KB
/
installer.ts
File metadata and controls
177 lines (155 loc) · 4.78 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { info } from "../../../src/deno_ral/log.ts";
import { basename, dirname, join } from "../../../src/deno_ral/path.ts";
import { Configuration } from "../common/config.ts";
import { runCmd } from "../util/cmd.ts";
import { download, unzip } from "../util/utils.ts";
import { execProcess } from "../../../src/core/process.ts";
import { emptyDirSync, ensureDirSync, existsSync, moveSync, copySync } from "../../../src/deno_ral/fs.ts";
export async function makeInstallerWindows(configuration: Configuration) {
const packageName = `quarto-${configuration.version}-win.msi`;
// Wix information
const wixFullVersion = "3112";
const wixShortVersion = "311";
// Working dir
const workingDir = join(configuration.directoryInfo.out, "working_win");
const wixDir = join(workingDir, "tools", `wix-${wixShortVersion}`);
// Wix commands
const heatCmd = join(wixDir, "heat");
const candleCmd = join(wixDir, "candle");
const lightCmd = join(wixDir, "light");
// Download tools, if necessary
if (
!existsSync(workingDir) || !existsSync(wixDir) ||
!existsSync(heatCmd + ".exe")
) {
emptyDirSync(workingDir);
ensureDirSync(wixDir);
const fileName = `wix${wixShortVersion}-binaries.zip`;
const wixToolsUrl =
`https://github.com/wixtoolset/wix3/releases/download/wix${wixFullVersion}rtm/${fileName}`;
const destZip = join(workingDir, fileName);
// Download the wix tools
info(`Downloading ${wixToolsUrl}`);
info(`to ${destZip}`);
await download(wixToolsUrl, destZip);
// Uncompress the wix tools in the supporting directory
info("Unzipping wix tools...");
await unzip(destZip, wixDir);
// Delete the downloaded zip file
Deno.remove(destZip);
}
// Copy the 'dist' files into a temporary working directory
const tempDir = Deno.makeTempDirSync();
const workingDistPath = join(tempDir, "dist");
const workingBinPath = join(workingDistPath, "bin");
const workingToolsPath = join(workingBinPath, "tools", );
const archToolsPath = join(workingToolsPath, "x86_64");
copySync(configuration.directoryInfo.pkgWorking.root, workingDistPath);
// Create a zip file
info("Creating zip installer");
const zipInput = join(workingDistPath, "*");
const zipOutput = join(
configuration.directoryInfo.out,
`quarto-${configuration.version}-win.zip`,
);
await zip(zipInput, zipOutput);
// Set the installer version
Deno.env.set("QUARTO_INSTALLER_VERSION", configuration.version);
// heat the directory to generate a wix file for it
info("Heating directory");
const heatOutput = join(workingDir, "quarto-frag.wxs");
await runCmd(
heatCmd,
[
"dir",
workingDistPath,
"-var",
"var.SourceDir",
"-gg",
"-sfrag",
"-srd",
"-cg",
"ProductComponents",
"-dr",
"APPLICATIONFOLDER",
"-out",
heatOutput,
],
);
// use candle to build the wixobj file
info("Making the candle");
const candleFiles = [
join(
configuration.directoryInfo.pkg,
"src",
"windows",
"WixUI_Advanced_Custom.wxs",
),
join(configuration.directoryInfo.pkg, "src", "windows", "quarto.wxs"),
heatOutput,
];
const candleOutput: string[] = [];
await Promise.all(candleFiles.map(async (candleInput) => {
const outputFileName = basename(candleInput, ".wxs");
const outputPath = join(workingDir, outputFileName + ".wixobj");
candleOutput.push(outputPath);
return await runCmd(
candleCmd,
[
`-dSourceDir=${workingDistPath}`,
"-arch",
"x64",
"-out",
outputPath,
candleInput,
],
);
}));
info("Lighting the candle");
const licenseRtf = join(
configuration.directoryInfo.pkg,
"src",
"windows",
"license.rtf",
);
const lightOutput = join(workingDir, packageName);
const lightArgs = ["-out", lightOutput, ...candleOutput];
lightArgs.push("-ext");
lightArgs.push("WixUtilExtension");
lightArgs.push("-ext");
lightArgs.push("WixUIExtension");
lightArgs.push(`-dWixUILicenseRtf=${licenseRtf}`);
await runCmd(lightCmd, lightArgs);
Deno.env.delete("QUARTO_INSTALLER_VERSION");
info(
`Moving ${lightOutput} to ${configuration.directoryInfo.out}`,
);
moveSync(
lightOutput,
join(configuration.directoryInfo.out, basename(lightOutput)),
{ overwrite: true },
);
// Clean up the working directory
Deno.remove(workingDir, { recursive: true });
Deno.remove(workingDistPath, { recursive: true });
}
export function zip(input: string, output: string) {
const dir = dirname(input);
const cmd = "powershell";
const args = [
"Compress-Archive",
"-Force",
input,
"-DestinationPath",
output,
];
info(cmd);
return execProcess(
{
cmd,
args,
cwd: dir,
stdout: "piped",
},
);
}