-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.js
86 lines (72 loc) · 2.38 KB
/
build.js
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
const { MSICreator } = require("electron-wix-msi");
const { exec } = require("child_process");
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});
const path = require("path");
const fs = require("fs");
const rimraf = require("rimraf");
const { create } = require("domain");
function packageInstaller(installer) {
const outputDir = "./LiveCSS-win32-x64";
if (fs.existsSync(outputDir)) {
console.log("old build found, overwriting...");
rimraf(outputDir, function () {
console.log("Removed " + outputDir);
});
}
console.log("packaging...");
exec(`npm run package`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
}
if (stderr) {
console.log(`stderr: ${stderr}`);
}
console.log(`stdout: ${stdout}`);
console.log("packaging finished");
if (installer == true) {
createInstaller();
}
});
}
//create installer
function createInstaller() {
console.log("Creating installer...");
// 2. Define input and output directory.
// Important: the directories must be absolute, not relative e.g
// appDirectory: "C:\\Users\sdkca\Desktop\OurCodeWorld-win32-x64",
const APP_DIR = path.resolve(__dirname, "./LiveCSS-win32-x64");
// outputDirectory: "C:\\Users\sdkca\Desktop\windows_installer",
const OUT_DIR = path.resolve(__dirname, "./windows_installer");
// 3. Instantiate the MSICreator
const msiCreator = new MSICreator({
appDirectory: APP_DIR,
outputDirectory: OUT_DIR,
// Configure metadata
description: "CSS editor",
exe: "LiveCSS",
name: "LiveCSS",
manufacturer: "Verion",
version: "1.0.0",
// Configure installer User Interface
ui: {
chooseDirectory: true,
},
});
// 4. Create a .wxs template file
msiCreator.create().then(function () {
// Step 5: Compile the template to a .msi file
msiCreator.compile();
});
}
console.log("Just package or create installer as well? (default: package)");
readline.question(`"i" for installer, "p" for package:`, (input) => {
readline.close();
if (input.toLowerCase() == "i") {
packageInstaller(true);
} else {
packageInstaller(false);
}
});