forked from inbasic/ignotifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
131 lines (128 loc) · 3.67 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
'use strict';
var gulp = require('gulp');
var change = require('gulp-change');
var babel = require('gulp-babel');
var gulpif = require('gulp-if');
var gulpFilter = require('gulp-filter');
var shell = require('gulp-shell');
var wait = require('gulp-wait');
var clean = require('gulp-clean');
var zip = require('gulp-zip');
var rename = require('gulp-rename');
var util = require('gulp-util');
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('.DS_Store') !== -1 || f.relative.indexOf('Thumbs.db') !== -1) {
return false;
}
if (f.relative.indexOf('firefox') !== -1 && f.relative.indexOf('firefox.png') === -1) {
return false;
}
if (f.path.indexOf('/locale') !== -1) {
return false;
}
if (f.relative.indexOf('safari') !== -1) {
return false;
}
if (f.relative.split('/').length === 1) {
return f.relative === 'manifest.json' ? true : false;
}
return true;
}))
.pipe(gulpif(function (f) {
return f.path.indexOf('.js') !== -1 && f.path.indexOf('.json') === -1;
}, change(function (content) {
return content.replace(/\/\*\* wrapper[\s\S]*\\*\*\*\//m, '');
})))
.pipe(gulpif(function (f) {
return f.path.indexOf('.html') !== -1;
}, change(function (content) {
return content.replace(/.*shadow_index\.js.*/, ' <script src="chrome/chrome.js"></script>\n <script src="index.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([
'"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --load-and-launch-app=`pwd` &'
], {
cwd: './builds/unpacked/chrome'
}));
});
/* firefox build */
gulp.task('firefox-build', function () {
gulp.src([
'src/**/*'
])
.pipe(gulpFilter(function (f) {
if (f.relative.indexOf('.DS_Store') !== -1 || f.relative.indexOf('Thumbs.db') !== -1) {
return false;
}
if (f.path.indexOf('_locales') !== -1) {
return false;
}
if (f.relative.indexOf('chrome') !== -1 &&
f.relative !== 'chrome.manifest' &&
f.relative.indexOf('chrome.png') === -1 &&
f.relative.indexOf('firefox/chrome') === -1
) {
return false;
}
if (f.relative.indexOf('shadow_index.js') !== -1) {
return false;
}
if (f.relative.indexOf('safari') !== -1) {
return false;
}
if (f.relative.split('/').length === 1) {
return ['package.json', 'chrome.manifest'].indexOf(f.relative) !== -1;
}
return true;
}))
.pipe(gulpif(function (f) {
return f.path.indexOf('.html') !== -1;
}, change(function (content) {
return content.replace(/\n.*shadow_index\.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'
}))
.pipe(shell([
'zip firefox.xpi install.rdf icon.png icon64.png',
], {
cwd: './builds/packed'
}));
});
/* */
gulp.task('chrome', function (callback) {
runSequence('clean', 'chrome-build', 'chrome-install', callback);
});
gulp.task('firefox', function (callback) {
runSequence('clean', 'firefox-build', 'firefox-pack', callback);
});