-
Notifications
You must be signed in to change notification settings - Fork 91
/
gulpfile.js
94 lines (83 loc) · 4.25 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
var gulp = require('gulp');
var zip = require('gulp-zip');
var gulpif = require('gulp-if');
var wait = require('gulp-wait');
var shell = require('gulp-shell');
var clean = require('gulp-clean');
var change = require('gulp-change');
var gulpFilter = require('gulp-filter');
var runSequence = require('run-sequence');
/* ------------------------------ */
/* ------------ Clean ----------- */
/* ------------------------------ */
gulp.task('clean', function () {
return gulp.src(['builds/unpacked/chrome/*', 'builds/unpacked/firefox/*'], {read: false}).pipe(clean());
});
/* ------------------------------ */
/* -------- Chrome Build -------- */
/* ------------------------------ */
gulp.task('chrome-build', function () {
gulp.src(['src/**/*']).pipe(gulpFilter(function (f) {
if (f.relative.indexOf('firefox') !== -1) return false;
if (f.relative.indexOf('safari') !== -1) return false;
if (f.relative.indexOf('package.json') !== -1) return false;
if (f.relative.indexOf('Info.plist') !== -1) return false;
if (f.relative.indexOf('icon16-mac') !== -1) return false;
if (f.relative.indexOf('Settings.plist') !== -1) return false;
if (f.relative.indexOf('update.plist') !== -1) return false;
if (f.relative.indexOf('Icon-64.png') !== -1) return false;
if (f.relative.indexOf('dictionary.safariextz') !== -1) return false;
if (f.relative.indexOf('.DS_Store') !== -1 || f.relative.indexOf('Thumbs.db') !== -1) return false;
return true;
}))
.pipe(gulpif(function (f) {return f.path.indexOf('.js') !== -1 && f.path.indexOf('.json') === -1}, change(function (content) {
return content.replace(/\/\*\*[\s\S]*\\*\*\*\/(\r\n)*/m, '');
})))
.pipe(gulpif(function (f) {return f.path.indexOf('.html') !== -1}, change(function (content) {
return content.replace(/.*popup\.js.*/, ' <script src="chrome/chrome.js"></script>\n <script src="popup.js"></script>').replace(/.*options\.js.*/, ' <script src="chrome/chrome.js"></script>\n <script src="options.js"></script>');
})))
.pipe(gulp.dest('builds/unpacked/chrome')).pipe(zip('chrome.zip')).pipe(gulp.dest('builds/packed'));
});
gulp.task('chrome-install', function () {
gulp.src('')
.pipe(wait(1000))
.pipe(shell([
'"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" --load-and-launch-app="<%= file.path %>\\builds\\unpacked\\chrome"'
], {cwd: './builds/unpacked/chrome'}));
});
/* ------------------------------ */
/* ------- FireFox Build -------- */
/* ------------------------------ */
gulp.task('firefox-build', function () {
gulp.src(['src/**/*']).pipe(gulpFilter(function (f) {
if (f.relative.indexOf('safari') !== -1) return false;
if (f.relative.indexOf('manifest.json') !== -1) return false;
if (f.relative.indexOf('Info.plist') !== -1) return false;
if (f.relative.indexOf('icon16-mac') !== -1) return false;
if (f.relative.indexOf('Settings.plist') !== -1) return false;
if (f.relative.indexOf('update.plist') !== -1) return false;
if (f.relative.indexOf('Icon-64.png') !== -1) return false;
if (f.relative.indexOf('dictionary.safariextz') !== -1) return false;
if (f.relative.indexOf('.DS_Store') !== -1 || f.relative.indexOf('Thumbs.db') !== -1) return false;
if (f.relative.indexOf('chrome') !== -1 && f.relative !== 'chrome.manifest' && f.relative.indexOf('firefox/chrome') === -1) return false;
return true;
}))
.pipe(gulpif(function (f) {return f.path.indexOf('.html') !== -1}, change(function (content) {
return content.replace(/(\r\n)*.*options\.js.*/, '').replace(/(\r\n)*.*popup\.js.*/, '');
}))).pipe(gulp.dest('builds/unpacked/firefox'));
});
/* ------------------------------ */
/* -------- FireFox Pack -------- */
/* ------------------------------ */
gulp.task('firefox-pack', function () {
gulp.src('').pipe(wait(1000)).pipe(shell(['jpm xpi', 'mv *.xpi ../../packed/firefox.xpi', 'jpm post --post-url http://localhost:8888/'], {cwd: './builds/unpacked/firefox'}));
});
/* ------------------------------ */
/* ------------ RUN ------------- */
/* ------------------------------ */
gulp.task('chrome', function (callback) {
runSequence('clean', 'chrome-build', 'chrome-install', callback);
});
gulp.task('firefox', function (callback) {
runSequence('clean', 'firefox-build', 'firefox-pack', callback);
});