-
Notifications
You must be signed in to change notification settings - Fork 115
/
Gulpfile.js
102 lines (94 loc) · 2.51 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
var gulp = require('gulp');
var replace = require('gulp-replace');
var svgo = require('gulp-svgo');
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',
gulp.series('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'));
})
);
gulp.task(
'cp',
gulp.series('res', function() {
return gulp
.src(['./src/*', '!./src/coplay.js'])
.pipe(gulp.dest('./extensions/chrome'))
.pipe(gulp.dest('./extensions/firefox'));
})
);
gulp.task(
'pack-chrome-extension',
gulp.series('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.chrome.zip -@",
{
cwd: 'extensions/chrome'
},
function(error) {
if (error) {
return cb(error);
} else {
cb();
}
}
);
})
);
gulp.task(
'pack-firefox-addon',
gulp.series('cp', function(cb) {
var manifestPath = './extensions/firefox/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.firefox.zip -@",
{
cwd: 'extensions/firefox'
},
function(error) {
if (error) {
return cb(error);
} else {
cb();
}
}
);
})
);
gulp.task(
'extensions',
gulp.series('pack-chrome-extension', 'pack-firefox-addon')
);
gulp.task('default', gulp.series('extensions'));