forked from keraf/NoCoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
196 lines (178 loc) · 4.91 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
const fs = require('fs');
const gulp = require('gulp');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const jeditor = require('gulp-json-editor');
const crx = require('gulp-crx-pack');
const zip = require('gulp-zip');
const del = require('del');
const runSequence = require('run-sequence');
const package = JSON.parse(fs.readFileSync('./package.json'));
const srcFolder = './src';
const buildFolder = './dist/tmp';
const babelConfig = {
presets: ['env'],
plugins: ['transform-object-rest-spread'],
}
// Clean old files
gulp.task('build:clean', () => {
return del(`${buildFolder}/**/*`);
});
// Copy files to build folder
gulp.task('build:copy', () => {
return gulp.src([
`${srcFolder}/**/*`,
`!${srcFolder}/**/*.js`,
`!${srcFolder}/**/*.css`,
`!${srcFolder}/view/background.html`,
`!${srcFolder}/manifest.json`])
.pipe(gulp.dest(buildFolder));
});
gulp.task('build:copy-edge', () => {
return gulp.src([`${srcFolder}/view/background.html`])
.pipe(gulp.dest(`${buildFolder}/view`));
});
// Transform the manifest
gulp.task('build:manifest', () => {
return gulp.src(`${srcFolder}/manifest.json`)
.pipe(jeditor({
'version': package.version,
}))
.pipe(gulp.dest(buildFolder));
});
gulp.task('build:manifest-ff', () => {
return gulp.src(`${srcFolder}/manifest.json`)
.pipe(jeditor({
'version': package.version,
'applications': {
'gecko': {
'id': '{5657c026-efc3-4860-b43b-16e4eaa8a9aa}',
},
},
}))
.pipe(gulp.dest(buildFolder));
});
gulp.task('build:manifest-edge', () => {
return gulp.src(`${srcFolder}/manifest.json`)
.pipe(jeditor({
'version': package.version,
'minimum_edge_version': '33.14281.1000.0',
'-ms-preload': {
'backgroundScript': 'js/backgroundScriptsAPIBridge.js',
'contentScript': 'js/contentScriptsAPIBridge.js',
},
'background': {
'scripts': [],
'page': 'view/background.html',
'persistent': true
},
}))
.pipe(gulp.dest(buildFolder));
});
// Transform the JS files
gulp.task('build:js', () => {
return gulp.src([`${srcFolder}/js/background.js`, `${srcFolder}/js/popup.js`])
.pipe(babel(babelConfig))
.pipe(uglify())
.pipe(gulp.dest(`${buildFolder}/js`));
});
gulp.task('build:js-edge', () => {
return gulp.src([`${srcFolder}/js/backgroundScriptsAPIBridge.js`, `${srcFolder}/js/contentScriptsAPIBridge.js`])
.pipe(babel(babelConfig))
.pipe(uglify())
.pipe(gulp.dest(`${buildFolder}/js`));
});
// Transform the CSS file
gulp.task('build:css', () => {
return gulp.src(`${srcFolder}/styles/popup.css`)
.pipe(cleanCSS())
.pipe(gulp.dest(`${buildFolder}/styles`));
});
// Zip it for FF
gulp.task('pack:firefox', () => {
return gulp.src(`${buildFolder}/**/*`)
.pipe(zip(`nocoin-${package.version}.xpi`))
.pipe(gulp.dest('./dist/firefox'));
});
// Zip it for Chrome
gulp.task('pack:chrome', () => {
return gulp.src(`${buildFolder}/**/*`)
.pipe(zip(`nocoin-${package.version}.zip`))
.pipe(gulp.dest('./dist/chrome'));
});
// Make CRX
gulp.task('pack:chromium', () => {
return gulp.src(`${buildFolder}`)
.pipe(crx({
privateKey: fs.readFileSync('./certs/key.pem', 'utf8'),
filename: `nocoin-${package.version}.crx`,
codebase: 'https://nocoin.ker.af/',
updateXmlFilename: 'update.xml'
}))
.pipe(gulp.dest('./dist/chromium'));
});
// Target platforms
gulp.task('chrome', () => {
return runSequence(
'build:clean',
'build:copy',
[
'build:manifest',
'build:js',
'build:css',
],
[
'pack:chrome',
]
);
});
gulp.task('firefox', () => {
return runSequence(
'build:clean',
'build:copy',
[
'build:manifest-ff',
'build:js',
'build:css',
],
[
'pack:firefox',
]
);
});
gulp.task('chromium', () => {
return runSequence(
'build:clean',
'build:copy',
[
'build:manifest',
'build:js',
'build:css',
],
[
'pack:chromium',
]
);
});
gulp.task('edge', () => {
return runSequence(
'build:clean',
'build:copy',
'build:copy-edge',
[
'build:manifest-edge',
'build:js',
'build:js-edge',
'build:css',
]
);
});
gulp.task('default', () => {
return runSequence(
'chrome',
'firefox',
'chromium',
'edge'
);
});