-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (61 loc) · 1.72 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
const { src, dest, series, parallel } = require('gulp');
const spawn = require('child_process').spawn;
const maps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const css = require('gulp-css');
const electron = require('electron'); // Use Electron's provided path
/* Build Tasks */
function buildCss() {
return src('src/**/*.css')
.pipe(css())
.pipe(dest('app/'));
}
function buildJs() {
return src(['main.js', 'src/**/*.js', '!src/**/*.test.js'])
.pipe(maps.init())
.pipe(babel())
.pipe(maps.write('.'))
.pipe(dest('app/'));
}
const build = parallel(buildCss, buildJs);
/* Copy Tasks */
function copyHtml() {
return src('src/*.html').pipe(dest('app/'));
}
function copyAssets() {
return src('src/assets/**/*').pipe(dest('app/assets'));
}
const copy = parallel(copyHtml, copyAssets);
/* Helper to Execute a Command */
function execute(command, args = ['.']) {
return new Promise((resolve, reject) => {
spawn(command, args, { stdio: 'inherit' })
.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(`Command failed with exit code ${code}`);
}
});
});
}
/* Execute Tasks */
function startTask() {
// Use Electron's provided binary path
return execute(electron);
}
function releaseTask() {
const builderCmd = 'node_modules/.bin/electron-builder';
return execute(builderCmd);
}
function testTask() {
const jestCmd = 'node_modules/.bin/jest';
return execute(jestCmd);
}
/* Exported Tasks */
exports.build = build;
exports.copy = copy;
exports.start = series(copy, build, startTask);
exports.release = series(copy, build, releaseTask);
exports.test = series(copy, build, testTask);
exports.default = exports.start;