-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.mjs
78 lines (69 loc) · 2.33 KB
/
gulpfile.mjs
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
import fs from 'fs-extra';
import { src, dest, parallel, series } from 'gulp';
import stylus from 'gulp-stylus';
import pug from 'gulp-pug';
import log from 'gulplog';
import resedit from 'resedit-cli';
import {read} from 'read';
const buildStylus = () =>
src('./src/bundle.styl')
.pipe(stylus({
compress: true,
'include css': true
}))
.pipe(dest('./assets/'));
const buildPug = () =>
src('./src/index.pug')
.pipe(pug({
pretty: false
}))
.pipe(dest('./assets/'));
export const build = parallel(buildStylus, buildPug);
const dumpPfx = () => {
if (!process.env.SIGN_PFX) {
log.warn('❔ \'dumpPfx\': Cannot find PFX certificate in environment variables. Provide it as a local file at ./CoMiGoGames.pfx or set the environment variable SIGN_PFX.');
return Promise.resolve();
}
return fs.writeFile(
'./CoMiGoGames.pfx',
Buffer.from(process.env.SIGN_PFX, 'base64')
);
};
const exePatch = {
sign: true,
p12: './CoMiGoGames.pfx'
};
if (process.env.SIGN_PASSWORD) {
exePatch.password = process.env.SIGN_PASSWORD.replace(/_/g, '');
}
const signInstaller = async () => {
if (!(await fs.pathExists(exePatch.p12))) {
log.warn('⚠️ \'signInstaller\': Cannot find PFX certificate. Continuing without signing.');
delete exePatch.p12;
exePatch.sign = false;
} else if (!process.env.SIGN_PASSWORD) {
log.warn('❔ \'signInstaller\': Cannot find PFX password in the SIGN_PASSWORD environment variable. Assuming manual input.');
const pass = await read({
prompt: 'Enter PFX password: (not shown. timing out in 60 seconds.)',
silent: true,
timeout: 1000 * 60
});
if (!pass) {
log.warn('⚠️ \'signInstaller\': Cannot find PFX password in the SIGN_PASSWORD environment variable. Continuing without signing.');
delete exePatch.p12;
exePatch.sign = false;
} else {
exePatch.password = pass;
}
}
if (!exePatch.sign) {
throw new Error('Cannot find PFX certificate or PFX password.');
}
await resedit({
in: `./dist/ctjsWebInstaller.exe`,
out: `./dist/ctjsWebInstaller.exe`,
...exePatch
});
};
export const sign = series(dumpPfx, signInstaller);
export default build;