-
Notifications
You must be signed in to change notification settings - Fork 214
/
gulpfile.js
260 lines (224 loc) · 7.12 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
'use strict';
const babel = require('gulp-babel');
const childProcess = require('child_process');
const electron = require('electron-prebuilt');
const electronPackager = require('electron-packager');
const fs = require('fs');
const gulp = require('gulp');
const jsdoc = require('gulp-jsdoc3');
const jshint = require('gulp-jshint');
const less = require('gulp-less');
const runSequence = require('run-sequence');
const symlink = require('gulp-symlink');
const _ = require('underscore');
const appConfig = require('./src/config/appConfig');
const packageJson = require('./package.json');
require('gulp-task-list')(gulp);
/* =========================================================================
* Constants
* ========================================================================= */
const SRC_DIR = 'src';
const DOCS_DIR = 'docs';
const RELEASE_IGNORE_PKGS = _.keys(packageJson.devDependencies);
const RELEASE_IMAGE_ICON = __dirname + '/resources/icon/logo_icon';
const RELEASE_OSX_IMAGE_ICON = RELEASE_IMAGE_ICON + '.icns';
const RELEASE_WIN_IMAGE_ICON = RELEASE_IMAGE_ICON + '.ico';
const RELEASE_SETTINGS = {
dir: '.',
name: appConfig.name,
out: appConfig.releasePath,
version: '0.36.0',
'app-version': appConfig.version,
'version-string': {
ProductVersion: appConfig.version,
ProductName: appConfig.name,
},
ignore: '/node_modules/(' + RELEASE_IGNORE_PKGS.join('|') + ')',
appPath: 'build/browser/main.js',
overwrite: true,
force: true,
asar: true,
prune: true
};
const LESSOPTIONS = {
compress: false
};
const JSDOC_SETTINGS = {
access: 'all', //show all access levels (public, private, protected)
// configure: './conf.json',
source: {
exclude: ['src/ui/vendor']
},
opts: {
destination: './docs/jsdocs'
},
tags: {
allowUnknownTags: true
}
};
/* =========================================================================
* Tasks
* ========================================================================= */
/**
* List gulp tasks
*/
gulp.task('?', ['task-list']);
gulp.task('clean', next => {
childProcess.exec(`rm -rf ${appConfig.releasePath} && rm -rf ${appConfig.buildPath}`, next);
});
gulp.task('css', () => {
return gulp.src(SRC_DIR + '/ui/less/main.less')
.pipe(less(LESSOPTIONS))
.pipe(gulp.dest(SRC_DIR + '/ui/css'));
});
gulp.task('site-css', () => {
return gulp.src(DOCS_DIR + '/less/docs.less')
.pipe(less(LESSOPTIONS))
.pipe(gulp.dest(DOCS_DIR + '/css'));
});
gulp.task('fonts', () => {
const fontcustom = require('fontcustom');
return fontcustom({
path: 'resources/font-glyphs',
output: 'src/ui/font-glyphs',
noisy: true,
force: true
});
});
/* ------------------------------------------------
* Code Quality
* ------------------------------------------------ */
gulp.task('jshint', () => {
return _init(gulp.src(['src/**/*.js', '!src/ui/vendor/**/*.js']))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
/* ------------------------------------------------
* Jsdocs
* ------------------------------------------------ */
gulp.task('jsdoc', next => {
gulp.src(['README.md', './src/**/*.js'], {
read: false
})
.pipe(jsdoc(JSDOC_SETTINGS, next));
});
gulp.task('open-jsdoc', ['jsdoc'], next => {
childProcess.exec('open ./docs/jsdocs/index.html', next);
});
/* ------------------------------------------------
* Release
* ------------------------------------------------ */
gulp.task('pre-release', next => {
// Build Steps:
//-------------------------------------
// run build to cleanup dirs and compile less
// run babel to compile ES6 => ES5
// run prod-sym-links to change symlinks in node_modules that point to src dir to the build dir (which will contain the compiled ES5 code)
//-------------------------------------
runSequence('build', 'babel', 'prod-sym-links', next);
});
gulp.task('release-osx', ['pre-release'], (next) => {
electronPackager(_.extend(RELEASE_SETTINGS, {
platform: 'darwin',
arch: 'x64',
icon: RELEASE_OSX_IMAGE_ICON,
}), next);
});
gulp.task('release-win', ['pre-release'], (next) => {
electronPackager(_.extend(RELEASE_SETTINGS, {
platform: 'win32',
arch: 'all',
icon: RELEASE_WIN_IMAGE_ICON,
}), next);
});
gulp.task('release-lin', ['pre-release'], (next) => {
electronPackager(_.extend(RELEASE_SETTINGS, {
platform: 'linux',
arch: 'all',
}), next);
});
gulp.task('release', ['pre-release'], (next) => {
electronPackager(_.extend(RELEASE_SETTINGS, {
platform: 'all',
arch: 'all',
icon: RELEASE_IMAGE_ICON,
}), next);
});
gulp.task('babel', () => {
return gulp.src('./src/**/*.js')
.pipe(babel({
presets: ['es2015'],
ignore: 'src/ui/vendor/*'
}))
.pipe(gulp.dest(appConfig.buildPath));
});
/* ------------------------------------------------
* Sym Links
* ------------------------------------------------ */
gulp.task('remove-link-src', next => {
unlink('./node_modules/src', next);
});
gulp.task('remove-link-lib', next => {
unlink('./node_modules/lib', next);
});
gulp.task('remove-link-tests', next => {
unlink('./node_modules/tests', next);
});
gulp.task('prod-sym-links', ['remove-link-src', 'remove-link-lib'], () => {
return gulp.src(['build/', 'build/lib/', 'package.json'])
.pipe(symlink(['./node_modules/src', './node_modules/lib', './node_modules/package.json'], {
force: true
}));
});
gulp.task('dev-sym-links', ['remove-link-src', 'remove-link-lib', 'remove-link-tests'], () => {
return gulp.src(['src/', 'src/lib/', 'tests/', 'package.json'])
.pipe(symlink(['./node_modules/src', './node_modules/lib', './node_modules/tests', './node_modules/package.json'], {
force: true
}));
});
/* ------------------------------------------------
* Build
* ------------------------------------------------ */
gulp.task('build', ['clean', 'css', 'dev-sym-links']);
/* ------------------------------------------------
* Run
* ------------------------------------------------ */
gulp.task('run', ['build'], next => {
var child = childProcess.spawn(electron, ['./']);
child.stdout.on('data', (data) => {
console.log(`tail output: ${data}`);
});
child.on('exit', (exitCode) => {
console.log('Child exited with code: ' + exitCode);
return next(exitCode === 1 ? new Error('Error running run task') : null);
});
});
/* ------------------------------------------------
* Run Project Site
* ------------------------------------------------ */
gulp.task('run-site', ['site-css'], () => {
gulp.watch(DOCS_DIR + '/less/*.less', () => {
gulp.src(DOCS_DIR + '/less/docs.less')
.pipe(less(LESSOPTIONS))
.pipe(gulp.dest(DOCS_DIR + '/css'));
});
});
gulp.task('default', ['run']);
/* =========================================================================
* Helper Functions
* ========================================================================= */
function _init(stream) {
stream.setMaxListeners(0);
return stream;
}
function unlink(symlink, next) {
fs.lstat(symlink, (lerr, lstat) => {
if (lerr || !lstat.isSymbolicLink()) {
return next();
}
fs.unlink(symlink, () => {
return next();
});
});
}