-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
179 lines (153 loc) · 4.38 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
/**
* Gulp tasks.
*/
'use strict';
let app = (path) => {
return './app/' + (path || '');
};
let src = (path) => {
return './jsx/' + (path || '');
};
let vendor = (path) => {
return './node_modules/' + (path || '');
};
const
gulp = require('gulp'),
concat = require('gulp-concat'),
babel = require('gulp-babel'),
eslint = require('gulp-eslint'),
packager = require('electron-packager'),
// packBackend = require('./webpack.backend.js'),
packDir = require('pack-dir'),
// webpack = require('webpack'),
paths = {
desktopApp: './build',
css: app('css/'),
js: app('js/'),
src: '',
srcBackend: [
app('*.js'),
'gulpfile.js'
],
srcFiles: [
src('components/*.jsx'),
src('index.jsx')
],
reloadOn: [
app('css/*.css'),
app('js/*.js'),
app('main*.js'),
app('index.html')
]
};
let getPackagerParams = (platform) => {
let pkg = require(app('package.json')),
params = {
arch: 'all',
asar: true,
dir: app(),
icon: app('img/icon512'),
name: pkg.productName,
out: paths.desktopApp,
overwrite: true,
platform: platform,
prune: true,
version: pkg.electronVersion,
'app-version': pkg.version,
'app-copyright': pkg.author,
'build-version': pkg.version
};
if (platform === 'darwin') {
params['app-category-type'] = 'public.app-category.video';
} else if (platform === 'win32') {
params.arch = 'ia32';
params['version-string'] = {
CompanyName: pkg.author,
FileDescription: pkg.description,
InternalName: pkg.productName,
OriginalFilename: pkg.productName + '.exe',
// Deprecated
// FileVersion: pkg.version,
// ProductVersion: pkg.version,
ProductName: pkg.productName
};
}
return params;
};
let packagingDone = (err, appPaths, cb) => {
if (err) {
console.log('Error: ', err);
return cb();
}
if (Array.isArray(appPaths)) {
appPaths.forEach(appPath => packDir.path(appPath));
}
cb();
};
let packaging = (cb, platform) => {
packager(
getPackagerParams(platform),
(err, appPaths) => packagingDone(err, appPaths, cb)
);
};
// let onWebPack = (done) => {
// return function (err, stats) {
// if (err) {
// console.log('Error', err);
// } else {
// console.log(stats.toString());
// }
// if (done) {
// done();
// }
// };
// };
gulp.task('build:ui-vendor-css', () => {
return gulp.src([
vendor('flexboxgrid/dist/flexboxgrid.min.css'),
vendor('material-design-lite/dist/material-grid.min.css')
])
.pipe(concat('vendor.css'))
.pipe(gulp.dest(paths.css));
});
gulp.task('build:ui-vendor-js', () => {
return gulp.src([
vendor('react/dist/react-with-addons.js'),
vendor('react-dom/dist/react-dom.js')
])
.pipe(concat('vendor.js'))
.pipe(gulp.dest(paths.js));
});
gulp.task('build:ui-js', () => {
// process.env.NODE_ENV = 'production';
return gulp.src(paths.srcFiles)
.pipe(concat('index.js'))
.pipe(babel({
sourceRoot: paths.src
}))
.pipe(gulp.dest(paths.js));
});
// gulp.task('build:backend', function (done) {
// webpack(packBackend).run(onWebPack(done));
// });
gulp.task('build:ui-vendor', ['build:ui-vendor-css', 'build:ui-vendor-js']);
gulp.task('build:ui', ['build:ui-vendor', 'build:ui-js']);
gulp.task('clean:app', () => {
let del = require('del');
return del([
paths.desktopApp + '/**/*'
]);
});
gulp.task('lint', ['build:ui-js'], () => {
return gulp.src(['app/js/index.js'])
.pipe(eslint())
.pipe(eslint.format())
;
});
gulp.task('build:app:osx', (cb) => packaging(cb, 'darwin'));
gulp.task('build:app:win', (cb) => packaging(cb, 'win32'));
gulp.task('build:app', ['clean:app', 'build:app:osx', 'build:app:win']);
gulp.task('build', ['build:ui', 'build:app']);
gulp.task('build:osx', ['clean:app', 'build:ui', 'build:app:osx']);
gulp.task('build:win', ['clean:app', 'build:ui', 'build:app:win']);
gulp.task('default', ['build']);