forked from RadicalZoey/open-joystick-display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
212 lines (166 loc) · 5.45 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
var gulp = require('gulp');
var watch = require('node-watch');
var less = require('gulp-less');
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 taskCSS(){
return combiner.obj([
gulp.src('./app/stylesheets/less/main.less'),
less(),
cleanCSS(),
gulp.dest('./app/stylesheets')
]).on('error', console.error.bind(console));
}
function taskWatch() {
watch('./app/stylesheets/less', { recursive: true }, function(evt, name) {
console.log(`Updated: ${name}`);
taskCSS()
});
}
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 = '';
sectionOutput('Transforming LESS Files');
taskCSS();
sectionOutput('Rebuilding Electron');
taskRebuildElectron();
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/open-joystick-display', {stdio: 'inherit'});
} else {
execSync('mv ./dist/linux-ia32-unpacked ./dist/open-joystick-display', {stdio: 'inherit'});
}
sectionOutput('Copying Icon');
execSync('cp ./app/icons/icon.png ./dist/open-joystick-display/icon.png', {stdio: 'inherit'});
sectionOutput('Compressing Package');
if (process.arch === 'x64') {
execSync(`tar czvf ./dist/open-joystick-display-${version}${unstable}-x64-linux.tar.gz -C ./dist open-joystick-display`, {stdio: 'inherit'});
} else {
execSync(`tar czvf ./dist/open-joystick-display-${version}${unstable}-x86-linux.tar.gz -C ./dist open-joystick-display`, {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 = '';
sectionOutput('Transforming LESS Files');
taskCSS();
sectionOutput('Rebuilding Electron');
taskRebuildElectron();
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 open-joystick-display', {stdio: 'inherit'});
} else {
execSync('rename .\\dist\\win-ia32-unpacked open-joystick-display', {stdio: 'inherit'});
}
sectionOutput('Compressing Package');
if (process.arch === 'x64') {
execSync(`tools\\windows\\7zip\\7za.exe a -r .\\dist\\open-joystick-display-${version}${unstable}-x64-windows.zip .\\dist\\open-joystick-display`, {stdio: 'inherit'});
} else {
execSync(`tools\\windows\\7zip\\7za.exe a -r .\\dist\\open-joystick-display-${version}${unstable}-x86-windows.zip .\\dist\\open-joystick-display`, {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 = '';
sectionOutput('Transforming LESS Files');
taskCSS();
sectionOutput('Rebuilding Electron');
taskRebuildElectron();
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/*.dmg ./dist/open-joystick-display-${version}${unstable}-x64-mac.dmg`, {stdio: 'inherit'});
sectionOutput('Build Finished');
}
function taskRebuildElectron() {
let cmd = '';
if (os.platform() === 'win32') {
cmd = '.\\node_modules\\.bin\\electron-rebuild -p -t "dev,prod,optional"';
} else {
cmd = './node_modules/.bin/electron-rebuild -p -t "dev,prod,optional"';
}
execSync(cmd, {stdio: 'inherit'});
}
gulp.task('default', function(cb) {
taskWatch();
cb();
});
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('rebuild-electron', function(cb) {
taskRebuildElectron();
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();
});