This repository was archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgulpfile.js
More file actions
210 lines (180 loc) · 5.49 KB
/
gulpfile.js
File metadata and controls
210 lines (180 loc) · 5.49 KB
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
const gulp = require('gulp');
const sh = require('shelljs');
const runSequence = require('run-sequence');
const _ = require('lodash');
const childProcess = require('child_process');
const jetpack = require('fs-jetpack');
const stylus = require('gulp-stylus');
const autoprefixer = require('gulp-autoprefixer');
const merge = require('merge-stream');
const googleWebFonts = require('gulp-google-webfonts');
const ffbinaries = require('ffbinaries');
const path = require('path');
require('gulp-task-list')(gulp);
const pkg = jetpack.read('./package.json', 'json');
const bundle = require('./tasks/bundle');
const SRC_DIR = 'src';
const RELEASE_IGNORE_PKGS = Object.keys(pkg.devDependencies).join('|');
const RELEASE_IMAGE_ICON = __dirname + '/src/ui/images/app.icns';
const STYLUSOPTIONS = {
compress: false,
paths: ['src/styles', 'node_modules/bootstrap-styl/bootstrap'],
urlfunc: 'embedurl',
};
const projectDir = jetpack;
const srcDir = jetpack.cwd('./src');
const destDir = jetpack.cwd('./build');
const buildPath = 'build';
const releasePath = 'release';
const _init = function _init(stream) {
stream.setMaxListeners(0);
return stream;
};
gulp.task('?', (next) => {
sh.exec('gulp task-list');
next();
});
gulp.task('clean', (next) => {
sh.rm('-rf', buildPath);
sh.rm('-rf', releasePath);
next();
});
gulp.task('bundle', () => {
return Promise.all([
bundle(srcDir.path('browser/main.js'), destDir.path('browser.js'), pkg),
bundle(srcDir.path('renderer/main.js'), destDir.path('renderer.js'), pkg),
]);
});
gulp.task('css', () => {
return merge(['application', 'bootstrap', 'remote'].map((x)=>{
return gulp.src(SRC_DIR + '/styles/' + x + '.styl')
.pipe(stylus(STYLUSOPTIONS))
.pipe(autoprefixer({
browsers: ['last 1 version']
}))
.pipe(gulp.dest(SRC_DIR + '/ui/css'));
}));
});
gulp.task('ffmpeg', (next) => {
const destination = path.join(__dirname, 'node_modules', 'ffmpeg');
console.log(`Downloading ffplay and ffprobe binaries for osx to ${destination}`);
ffbinaries.downloadFiles(
['ffmpeg', 'ffprobe'],
{
platform: 'osx',
destination,
}, (err, data) => {
if (err) {
console.error(err);
throw(err);
}
console.log(`Downloaded ffplay and ffprobe binaries for osx to ${destination}`);
next();
});
});
gulp.task('electron-settings', () => {
return gulp.src('./node_modules/electron-settings/**')
.pipe(gulp.dest(releasePath + '/Playa-darwin-x64/Playa.app/Contents/Resources/app/node_modules/electron-settings'));
});
gulp.task('fonts', () => {
return gulp.src('./fonts.list')
.pipe(googleWebFonts({}))
.pipe(gulp.dest('src/ui/fonts'));
});
gulp.task('font-awesome', () => {
return gulp.src('./node_modules/font-awesome/**')
.pipe(gulp.dest('src/ui/vendor/font-awesome'));
});
gulp.task('assets', () => {
return gulp.src('src/ui/**')
.pipe(gulp.dest(buildPath + '/ui'));
});
gulp.task('pkg', () => {
return gulp.src('package.json')
.pipe(gulp.dest(buildPath));
});
gulp.task('lib', () => {
return gulp.src('src/lib/**')
.pipe(gulp.dest(buildPath + '/lib'));
});
gulp.task('pre-release', (next) => {
runSequence('build', 'prod-sym-links', next);
});
gulp.task('release-electron', ['pre-release'], (next) => {
const env = Object.assign({}, process.env);
env.NODE_ENV = 'production';
const packageArgs = [
'.',
pkg.productName,
'--out',
releasePath,
'--platform',
'darwin',
'--arch',
'x64',
'--electron-version',
pkg.devDependencies.electron,
'--ignore', ('node_modules/(' + RELEASE_IGNORE_PKGS + ')'),
'--icon',
RELEASE_IMAGE_ICON,
'--appPath',
'build/browser.js'
];
const child = childProcess.spawn('./node_modules/.bin/electron-packager', packageArgs, {
env: env
});
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 release task') : null);
});
});
gulp.task('release', (next) => {
runSequence('release-electron', 'electron-settings', next);
});
gulp.task('prod-sym-links', (next) => {
childProcess.exec('make createProductionSymLinks', (err, stdout, stderr) => {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (err !== null) {
console.log('exec error: ' + err);
}
return next(err);
});
});
gulp.task('dev-sym-links', () => {
childProcess.exec('make createDevelopmentSymLinks', (error, stdout, stderr) => {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
});
gulp.task('build', ['clean', 'fonts', 'font-awesome', 'css', 'ffmpeg', 'bundle', 'dev-sym-links', 'lib', 'pkg', 'assets']);
gulp.task('watch', () => {
gulp.watch(SRC_DIR + '/styles/*.styl', ['css']);
gulp.watch([
SRC_DIR + '/**/*.js',
SRC_DIR + '/**/*.jsx'
], ['bundle']);
});
gulp.task('serve', ['watch', 'build'], (next) => {
const env = Object.assign({}, process.env);
const child = childProcess.spawn('./node_modules/.bin/electron', ['./'], {
env: env
});
child.stdout.on('data', (data) => {
console.log('tail output: ' + data);
});
child.on('exit', (exitCode) => {
console.log('Child exited with code: ' + exitCode);
if (exitCode === 1) {
return next(new Error('Error running serve task'));
}
process.exit(0);
});
});
gulp.task('default', ['serve']);