generated from nicross/syngen-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Gulpfile.js
173 lines (151 loc) · 3.46 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
const cleancss = require('gulp-clean-css')
const concat = require('gulp-concat')
const electron = require('gulp-run-electron')
const gulp = require('gulp')
const header = require('gulp-header')
const gulpif = require('gulp-if')
const iife = require('gulp-iife')
const merge = require('merge-stream')
const package = require('./package.json')
const packager = require('electron-packager')
const rename = require('gulp-rename')
const uglify = require('gulp-uglify-es').default
const zip = require('gulp-zip')
const argv = require('yargs').argv,
isDebug = argv.debug === true
gulp.task('build-css', () => {
return gulp.src(
getCss()
).pipe(
concat('styles.min.css')
).pipe(
gulpif(!isDebug, cleancss())
).pipe(
gulp.dest('public')
)
})
gulp.task('build-js', () => {
return gulp.src(
getJs()
).pipe(
concat('scripts.min.js')
).pipe(
gulpif(!isDebug, iife(), header("'use strict';\n\n"))
).pipe(
gulp.dest('public')
).pipe(
gulpif(!isDebug, uglify())
).pipe(
gulp.dest('public')
)
})
gulp.task('build', gulp.series('build-css', 'build-js'))
gulp.task('dist-electron', async () => {
// Builds only for current platform, e.g. must build separately on Windows and Linux
const platforms = [process.platform]
const paths = await packager({
arch: 'x64',
asar: true,
dir: '.',
icon: 'assets/icon/icon',
ignore: [
'.gitignore',
'.gitmodules',
'assets',
'dist',
'docs',
'Gulpfile.js',
'node_modules',
'package-lock.json',
'README.md',
'src',
],
out: 'dist',
overwrite: true,
platform: platforms,
})
// XXX: Archives have no root directory
paths.forEach((path) => {
const build = gulp.src(path + '/**/*')
const manual = gulp.src([
'public/favicon.png',
'public/img/splash/logo.png',
'public/manual.html'
], {base: 'public'}).pipe(
rename((path) => {
path.dirname = '/documentation/' + path.dirname
})
)
merge(build, manual).pipe(
zip(path.replace('dist\\', '') + '.zip')
).pipe(
gulp.dest('dist')
)
})
})
gulp.task('dist-html5', () => {
// XXX: Archive has no root directory
return gulp.src([
'public/favicon.png',
'public/img/splash/interact.png',
'public/img/splash/logo.png',
'public/index.html',
'public/manual.html',
'public/scripts.min.js',
'public/styles.min.css',
], {base: 'public'}).pipe(
zip(package.name + '-html5.zip')
).pipe(
gulp.dest('dist')
)
})
gulp.task('dist', gulp.series('build', 'dist-electron', 'dist-html5'))
gulp.task('electron', () => {
return gulp.src('.').pipe(
electron()
)
})
gulp.task('electron-build', gulp.series('build', 'electron'))
gulp.task('watch', () => {
gulp.watch('src/**', gulp.series('build'))
})
function getCss() {
const srcs = [
'src/css/reset.css',
'src/css/main.css',
'src/css/*.css',
'src/css/**/*.css',
]
return srcs
}
function getJs() {
return [
...getEngineJs(),
...getContentJs(),
...getAppJs(),
'src/js/main.js',
]
}
function getAppJs() {
const srcs = [
'src/js/app.js',
'src/js/app/*.js',
'src/js/app/*/*.js',
'src/js/app/*/*/*.js',
]
return srcs
}
function getContentJs() {
const srcs = [
'src/js/content.js',
'src/js/content/*.js',
'src/js/content/**/*.js',
]
return srcs
}
function getEngineJs() {
return [
'node_modules/syngen/dist/syngen.js',
'src/js/engine.js',
]
}