forked from Justineo/coplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
74 lines (66 loc) · 2.31 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
var gulp = require('gulp');
var replace = require('gulp-replace');
var svgo = require('gulp-svgo');
var Datauri = require('datauri');
var fs = require('fs');
var exec = require('child_process').exec;
var pack = require('./package.json');
var version = pack.version;
gulp.task('icons', function () {
return gulp.src('./assets/icons/*.svg')
.pipe(svgo())
.pipe(gulp.dest('./dist/icons'));
});
var svgPattern = /\.svg$/
gulp.task('res', ['icons'], function () {
var iconData = fs.readdirSync('./dist/icons').reduce(function (icons, file) {
if (!file.match(svgPattern)) {
return
}
var name = file.replace(svgPattern, '');
icons[name] = fs.readFileSync('./dist/icons/' + file, 'utf8');
return icons;
}, {});
return gulp.src('./src/coplay.js')
.pipe(replace('\'__ICONS__\'', JSON.stringify(iconData)))
.pipe(gulp.dest('./extensions/chrome'))
.pipe(gulp.dest('./extensions/firefox/data'));
});
gulp.task('cp', ['res'], function () {
return gulp.src(['./src/*', '!./src/coplay.js'])
.pipe(gulp.dest('./extensions/chrome'))
.pipe(gulp.dest('./extensions/firefox/data'));
});
gulp.task('pack-chrome-extension', ['cp'], function (cb) {
var manifestPath = './extensions/chrome/manifest.json';
var manifest = JSON.parse(fs.readFileSync(manifestPath, { encoding: 'utf8' }));
manifest.version = version;
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, ' '));
exec('find . -path \'*/.*\' -prune -o -type f -print | zip ../packed/coplay.zip -@', {
cwd: 'extensions/chrome'
}, function (error, stdout, stderr) {
if (error) {
return cb(error);
} else {
cb();
}
});
});
gulp.task('pack-firefox-addon', ['cp'], function (cb) {
var fxPackPath = './extensions/firefox/package.json';
var fxPack = JSON.parse(fs.readFileSync(fxPackPath, { encoding: 'utf8' }));
fxPack.version = version;
fs.writeFileSync(fxPackPath, JSON.stringify(fxPack, null, ' '));
exec('jpm xpi', {
cwd: 'extensions/firefox'
}, function (error, stdout, stderr) {
if (error) {
return cb(error);
} else {
fs.renameSync('./extensions/firefox/' + pack.name + '.xpi', './extensions/packed/' + pack.name + '.xpi');
cb();
}
});
});
gulp.task('extensions', ['pack-chrome-extension', 'pack-firefox-addon']);
gulp.task('default', ['extensions']);