forked from CelestinaDragoni/livesplit-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
156 lines (122 loc) · 4.26 KB
/
gulpfile.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
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
var gulp = require('gulp');
var watch = require('node-watch');
var combiner = require('stream-combiner2');
var os = require('os');
let cleanCSS = require('gulp-clean-css');
var execSync = require('child_process').execSync;
let fs = require('fs');
function taskError(e) {
console.error(e);
}
function sectionOutput(message) {
const time = new Date().toUTCString();
console.log('----------------------------------------------------');
console.log(`[${time}] ${message}`);
console.log('----------------------------------------------------');
}
function taskBuildLinux() {
if (os.platform() !== 'linux') {
taskError("Try this command again while you're in linux chief.");
return;
}
sectionOutput('Start Building (Linux)');
let version = 0;
let unstable = '';
const versionFile = fs.openSync('app/version', 'r');
version = fs.readFileSync(versionFile, 'UTF-8');
fs.closeSync(versionFile);
sectionOutput('Cleaning Artifacts');
execSync('rm -Rfv ./dist/', {stdio: 'inherit'});
sectionOutput('Building Package');
execSync('yarn build', {stdio: 'inherit'});
if (process.arch === 'x64') {
execSync('mv ./dist/linux-unpacked ./dist/livesplit-electron', {stdio: 'inherit'});
} else {
execSync('mv ./dist/linux-ia32-unpacked ./dist/livesplit-electron', {stdio: 'inherit'});
}
sectionOutput('Copying Icon');
execSync('cp ./app/icons/icon.png ./dist/livesplit-electron/icon.png', {stdio: 'inherit'});
sectionOutput('Compressing Package');
if (process.arch === 'x64') {
execSync(`tar czvf ./dist/livesplit-electron-${version}${unstable}-x64-linux.tar.gz -C ./dist livesplit-electron`, {stdio: 'inherit'});
} else {
execSync(`tar czvf ./dist/livesplit-electron-${version}${unstable}-x86-linux.tar.gz -C ./dist livesplit-electron`, {stdio: 'inherit'});
}
sectionOutput('Build Finished');
}
function taskBuildWindows() {
if (os.platform() !== 'win32') {
taskError("Try this command again while you're in windows chief.");
return;
}
sectionOutput('Start Building (Win32)');
let version = 0;
let unstable = '';
const versionFile = fs.openSync('app/version', 'r');
version = fs.readFileSync(versionFile, 'UTF-8');
fs.closeSync(versionFile);
sectionOutput('Cleaning Artifacts');
try {
execSync('rmdir /S /Q .\\dist', {stdio: 'inherit'});
} catch {
console.log('No dist directory to delete. Moving on...');
}
sectionOutput('Building Package');
execSync('yarn build', {stdio: 'inherit'});
if (process.arch === 'x64') {
execSync('rename .\\dist\\win-unpacked livesplit-electron', {stdio: 'inherit'});
} else {
execSync('rename .\\dist\\win-ia32-unpacked livesplit-electron', {stdio: 'inherit'});
}
sectionOutput('Compressing Package');
if (process.arch === 'x64') {
execSync(`tools\\windows\\7zip\\7za.exe a -r .\\dist\\livesplit-electron-${version}${unstable}-x64-windows.zip .\\dist\\livesplit-electron`, {stdio: 'inherit'});
} else {
execSync(`tools\\windows\\7zip\\7za.exe a -r .\\dist\\livesplit-electron-${version}${unstable}-x86-windows.zip .\\dist\\livesplit-electron`, {stdio: 'inherit'});
}
sectionOutput('Build Finished');
}
function taskBuildDarwin() {
if (os.platform() !== 'darwin') {
taskError("Try this command again while you're in macOS chief.");
return;
}
sectionOutput('Start Building (Darwin/macOS)');
let version = 0;
let unstable = '';
const versionFile = fs.openSync('app/version', 'r');
version = fs.readFileSync(versionFile, 'UTF-8');
fs.closeSync(versionFile);
sectionOutput('Cleaning Artifacts');
execSync('rm -Rfv ./dist/', {stdio: 'inherit'});
sectionOutput('Building Package');
execSync('yarn build', {stdio: 'inherit'});
sectionOutput('Renaming Package');
execSync(`mv ./dist/*.zip ./dist/livesplit-electron-${version}${unstable}-x64-mac.zip`, {stdio: 'inherit'});
sectionOutput('Build Finished');
}
gulp.task('build', function(cb) {
const platform = os.platform();
if (platform === 'win32') {
taskBuildWindows();
} else if (platform === 'linux') {
taskBuildLinux();
} else if (platform === 'darwin') {
taskBuildDarwin();
} else {
console.error('Unsupported Platform');
}
cb();
});
gulp.task('build-linux', function(cb) {
taskBuildLinux();
cb();
});
gulp.task('build-windows', function(cb) {
taskBuildWindows();
cb();
});
gulp.task('build-darwin', function(cb) {
taskBuildDarwin();
cb();
});