aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.babel.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r--gulpfile.babel.js131
1 files changed, 131 insertions, 0 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js
new file mode 100644
index 000000000..d947974b3
--- /dev/null
+++ b/gulpfile.babel.js
@@ -0,0 +1,131 @@
1/* eslint max-len: 0 */
2import gulp from 'gulp';
3import babel from 'gulp-babel';
4import sass from 'gulp-sass';
5import server from 'gulp-server-livereload';
6import del from 'del';
7import { exec } from 'child_process';
8import dotenv from 'dotenv';
9import sassVariables from 'gulp-sass-variables';
10
11import config from './package.json';
12
13dotenv.config();
14
15const paths = {
16 src: 'src',
17 dest: 'build',
18 tmp: '.tmp',
19 package: `out/${config.version}`,
20 html: {
21 src: 'src/**/*.html',
22 dest: 'build/',
23 watch: 'src/**/*.html',
24 },
25 styles: {
26 src: 'src/styles/main.scss',
27 dest: 'build/styles',
28 watch: 'src/styles/**/*.scss',
29 },
30 scripts: {
31 src: 'src/**/*.js',
32 dest: 'build/',
33 watch: 'src/**/*.js',
34 },
35};
36
37function _shell(cmd, cb) {
38 exec(cmd, {
39 cwd: paths.dest,
40 }, (error, stdout, stderr) => {
41 if (error) {
42 console.error(`exec error: ${error}`);
43 return;
44 }
45 console.log(`stdout: ${stdout}`);
46 console.log(`stderr: ${stderr}`);
47
48 cb();
49 });
50}
51
52const clean = () => del([paths.tmp, paths.dest]);
53export { clean };
54
55export function mvSrc() {
56 return gulp.src(
57 [
58 `${paths.src}/*`,
59 `${paths.src}/*/**`,
60 `!${paths.scripts.watch}`,
61 `!${paths.src}/styles/**`,
62 ], { since: gulp.lastRun(mvSrc) })
63 .pipe(gulp.dest(paths.dest));
64}
65
66export function mvPackageJson() {
67 return gulp.src(
68 [
69 './package.json',
70 ])
71 .pipe(gulp.dest(paths.dest));
72}
73
74export function html() {
75 return gulp.src(paths.html.src, { since: gulp.lastRun(html) })
76 .pipe(gulp.dest(paths.html.dest));
77}
78
79export function styles() {
80 return gulp.src(paths.styles.src)
81 .pipe(sassVariables({
82 $env: process.env.NODE_ENV === 'development' ? 'development' : 'production',
83 }))
84 .pipe(sass({
85 includePaths: [
86 './node_modules',
87 '../node_modules',
88 ],
89 }).on('error', sass.logError))
90 .pipe(gulp.dest(paths.styles.dest));
91}
92
93export function scripts() {
94 return gulp.src(paths.scripts.src, { since: gulp.lastRun(scripts) })
95 .pipe(babel({
96 comments: false,
97 }))
98 .pipe(gulp.dest(paths.scripts.dest));
99}
100
101export function watch() {
102 gulp.watch(paths.scripts.watch, scripts);
103 gulp.watch(paths.styles.watch, styles);
104
105 gulp.watch([
106 paths.src,
107 `${paths.scripts.src}`,
108 `${paths.styles.src}`,
109 ], mvSrc);
110}
111
112export function webserver() {
113 gulp.src(paths.dest)
114 .pipe(server({
115 livereload: true,
116 }));
117}
118
119export function sign(done) {
120 _shell(`codesign --verbose=4 --deep --strict --force --sign "${process.env.SIGNING_IDENTITY}" "${__dirname}/node_modules/electron/dist/Electron.app"`, done);
121}
122
123const build = gulp.series(
124 clean,
125 gulp.parallel(mvSrc, mvPackageJson),
126 gulp.parallel(html, scripts, styles),
127);
128export { build };
129
130const dev = gulp.series(build, gulp.parallel(webserver, watch));
131export { dev };