TeaSpeak-Client/installer/package_windows.ts

89 lines
3.4 KiB
TypeScript
Raw Normal View History

2019-10-25 19:51:40 -04:00
import * as packager from "./package";
import * as deployer from "./deploy";
import {parse_version, Version} from "../modules/shared/version";
const fs = require("fs-extra");
const path = require("path");
const util = require('util');
const cproc = require('child_process');
const proc = require('process');
const ejs = require('ejs');
const exec = util.promisify(cproc.exec);
const ejs_render = util.promisify(ejs.renderFile);
const filename_update = "TeaClient-windows-x64.tar.gz";
const filename_installer = "TeaClient-windows-x64.exe";
const package_path = "build/TeaClient-win32-x64/";
const symbol_pdb_path = "native/build/symbols/";
const symbol_binary_path = package_path + "/resources/natives/";
let dest_path = undefined;
let info;
let version: Version;
async function make_template() : Promise<string> {
const content = await ejs_render("installer/WinInstall.ejs", {
source_dir: path.resolve(package_path) + "/*",
dest_dir: path.resolve(dest_path),
icon_file: path.resolve("resources/logo.ico"),
version: info["version"],
executable_name: filename_installer.substr(0, filename_installer.length - 4) //Remove the .exe
}, {});
await fs.mkdirs(dest_path);
fs.writeFileSync(dest_path + "/" + "installer.iss", content);
return dest_path + "/" + "installer.iss";
}
async function make_installer(path: string) {
console.log("Compiling path %s", path);
const { stdout, stderr } = await exec("\"C:\\Program Files (x86)\\Inno Setup 6\\iscc.exe\" " + path, {maxBuffer: 1024 * 1024 * 1024}); //FIXME relative path?
2019-10-25 19:51:40 -04:00
}
if(process.argv.length < 3) {
console.error("Missing build channel!");
process.exit(1);
}
packager.pack_info(package_path).then(async _info => {
info = _info;
version = parse_version(_info["version"]);
dest_path = "build/output/" + process.argv[2] + "/" + version.toString() + "/";
await packager.pack_update(package_path, dest_path + "TeaClient-windows-x64.tar.gz");
}).then(async () => {
await packager.write_info(dest_path + "info.json", "win32", "x64", filename_update, filename_installer)
}).then(async () => {
await packager.write_version("build/output/version.json", "win32", "x64", process.argv[2], version);
}).then(async () => await make_template())
.then(async path => await make_installer(path))
.then(async () => {
console.log("Deploying PDB files");
const files = [];
for(const file of await fs.readdir(symbol_binary_path)) {
if(!file.endsWith(".node"))
continue;
let file_name = path.basename(file);
if(file_name.endsWith(".node"))
file_name = file_name.substr(0, file_name.length - 5);
const binary_path = path.join(symbol_binary_path, file);
const pdb_path = path.join(symbol_pdb_path, file_name + ".pdb");
if(!fs.existsSync(pdb_path)) {
console.warn("Missing PDB file for binary %s", file);
continue;
}
files.push({
binary: binary_path,
pdb: pdb_path
});
}
await deployer.deploy_win_dbg_files(files, version);
console.log("PDB files deployed");
})
.then(async () => {
console.log("Deploying build");
await packager.deploy("win32", "x64", process.argv[2], version, dest_path + filename_update, dest_path + filename_installer, "exe");
}).then(() => {
console.log("Succeed");
proc.exit(0);
}).catch(error => {
console.log(error);
proc.exit(1);
});