|
|
|
@ -4,7 +4,6 @@ const {lstatSync, readdirSync, readFileSync, writeFileSync} = require('fs');
|
|
|
|
|
|
|
|
|
|
const {ensureDirSync} = require('fs-extra');
|
|
|
|
|
const gulp = require('gulp');
|
|
|
|
|
const gulpSeq = require('gulp-sequence');
|
|
|
|
|
const htmlmin = require('gulp-htmlmin');
|
|
|
|
|
const svgmin = require('gulp-svgmin');
|
|
|
|
|
const babel = require('gulp-babel');
|
|
|
|
@ -15,7 +14,6 @@ const jsonMerge = require('gulp-merge-json');
|
|
|
|
|
const jsonmin = require('gulp-jsonmin');
|
|
|
|
|
const svg2png = require('svg2png');
|
|
|
|
|
const imagemin = require('gulp-imagemin');
|
|
|
|
|
const dedent = require('dedent');
|
|
|
|
|
|
|
|
|
|
const targetEnv = process.env.TARGET_ENV || 'firefox';
|
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
@ -37,32 +35,35 @@ gulp.task('js:webpack', function(done) {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('js:babel', function() {
|
|
|
|
|
return gulp
|
|
|
|
|
gulp.task('js:babel', function(done) {
|
|
|
|
|
gulp
|
|
|
|
|
.src(['src/content/**/*.js'], {base: '.'})
|
|
|
|
|
.pipe(babel())
|
|
|
|
|
.pipe(gulp.dest(distDir));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('js', ['js:webpack', 'js:babel']);
|
|
|
|
|
gulp.task('js', gulp.parallel('js:webpack', 'js:babel'));
|
|
|
|
|
|
|
|
|
|
gulp.task('html', function() {
|
|
|
|
|
return gulp
|
|
|
|
|
gulp.task('html', function(done) {
|
|
|
|
|
gulp
|
|
|
|
|
.src('src/**/*.html', {base: '.'})
|
|
|
|
|
.pipe(gulpif(isProduction, htmlmin({collapseWhitespace: true})))
|
|
|
|
|
.pipe(gulp.dest(distDir));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('css', function() {
|
|
|
|
|
return gulp
|
|
|
|
|
gulp.task('css', function(done) {
|
|
|
|
|
gulp
|
|
|
|
|
.src(['src/solve/style.css'], {
|
|
|
|
|
base: '.'
|
|
|
|
|
})
|
|
|
|
|
.pipe(postcss())
|
|
|
|
|
.pipe(gulp.dest(distDir));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('icons', async function() {
|
|
|
|
|
gulp.task('icons', async function(done) {
|
|
|
|
|
ensureDirSync(`${distDir}/src/icons/app`);
|
|
|
|
|
const iconSvg = readFileSync('src/icons/app/icon.svg');
|
|
|
|
|
const appIconSizes = [16, 19, 24, 32, 38, 48, 64, 96, 128];
|
|
|
|
@ -75,16 +76,17 @@ gulp.task('icons', async function() {
|
|
|
|
|
gulp
|
|
|
|
|
.src(`${distDir}/src/icons/**/*.png`, {base: '.'})
|
|
|
|
|
.pipe(imagemin())
|
|
|
|
|
.pipe(gulp.dest(''));
|
|
|
|
|
.pipe(gulp.dest('.'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gulp
|
|
|
|
|
.src('node_modules/ext-contribute/src/assets/*.svg')
|
|
|
|
|
.pipe(gulpif(isProduction, svgmin()))
|
|
|
|
|
.pipe(gulp.dest(`${distDir}/src/contribute/assets`));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('fonts', function() {
|
|
|
|
|
gulp.task('fonts', function(done) {
|
|
|
|
|
gulp
|
|
|
|
|
.src('src/fonts/roboto.css', {base: '.'})
|
|
|
|
|
.pipe(postcss())
|
|
|
|
@ -92,9 +94,10 @@ gulp.task('fonts', function() {
|
|
|
|
|
gulp
|
|
|
|
|
.src('node_modules/typeface-roboto/files/roboto-latin-@(400|500|700).woff2')
|
|
|
|
|
.pipe(gulp.dest(`${distDir}/src/fonts/files`));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('locale', function() {
|
|
|
|
|
gulp.task('locale', function(done) {
|
|
|
|
|
const localesRootDir = path.join(__dirname, 'src/_locales');
|
|
|
|
|
const localeDirs = readdirSync(localesRootDir).filter(function(file) {
|
|
|
|
|
return lstatSync(path.join(localesRootDir, file)).isDirectory();
|
|
|
|
@ -102,10 +105,13 @@ gulp.task('locale', function() {
|
|
|
|
|
localeDirs.forEach(function(localeDir) {
|
|
|
|
|
const localePath = path.join(localesRootDir, localeDir);
|
|
|
|
|
gulp
|
|
|
|
|
.src([
|
|
|
|
|
path.join(localePath, 'messages.json'),
|
|
|
|
|
path.join(localePath, `messages-${targetEnv}.json`)
|
|
|
|
|
])
|
|
|
|
|
.src(
|
|
|
|
|
[
|
|
|
|
|
path.join(localePath, 'messages.json'),
|
|
|
|
|
path.join(localePath, `messages-${targetEnv}.json`)
|
|
|
|
|
],
|
|
|
|
|
{allowEmpty: true}
|
|
|
|
|
)
|
|
|
|
|
.pipe(
|
|
|
|
|
jsonMerge({
|
|
|
|
|
fileName: 'messages.json',
|
|
|
|
@ -124,10 +130,11 @@ gulp.task('locale', function() {
|
|
|
|
|
.pipe(gulpif(isProduction, jsonmin()))
|
|
|
|
|
.pipe(gulp.dest(path.join(distDir, '_locales', localeDir)));
|
|
|
|
|
});
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('manifest', function() {
|
|
|
|
|
return gulp
|
|
|
|
|
gulp.task('manifest', function(done) {
|
|
|
|
|
gulp
|
|
|
|
|
.src('src/manifest.json')
|
|
|
|
|
.pipe(
|
|
|
|
|
jsonMerge({
|
|
|
|
@ -157,38 +164,49 @@ gulp.task('manifest', function() {
|
|
|
|
|
)
|
|
|
|
|
.pipe(gulpif(isProduction, jsonmin()))
|
|
|
|
|
.pipe(gulp.dest(distDir));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('license', function() {
|
|
|
|
|
gulp.task('license', function(done) {
|
|
|
|
|
let year = 2018;
|
|
|
|
|
const currentYear = new Date().getFullYear();
|
|
|
|
|
if (year !== currentYear) {
|
|
|
|
|
year = `${year}-${currentYear}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const notice = dedent`
|
|
|
|
|
Buster: Captcha Solver for Humans
|
|
|
|
|
Copyright (c) ${year} Armin Sebastian
|
|
|
|
|
const notice = `Buster: Captcha Solver for Humans
|
|
|
|
|
Copyright (c) ${year} Armin Sebastian
|
|
|
|
|
|
|
|
|
|
This software is released under the terms of the GNU General Public License v3.0.
|
|
|
|
|
See the LICENSE file for further information.
|
|
|
|
|
`;
|
|
|
|
|
This software is released under the terms of the GNU General Public License v3.0.
|
|
|
|
|
See the LICENSE file for further information.
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
writeFileSync(`${distDir}/NOTICE`, notice);
|
|
|
|
|
gulp.src(['LICENSE']).pipe(gulp.dest(distDir));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('copy', function() {
|
|
|
|
|
gulp.task('copy', function(done) {
|
|
|
|
|
gulp
|
|
|
|
|
.src('node_modules/ext-contribute/src/assets/*.@(jpg|png)')
|
|
|
|
|
.pipe(gulp.dest(`${distDir}/src/contribute/assets`));
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task(
|
|
|
|
|
'build',
|
|
|
|
|
gulpSeq(
|
|
|
|
|
gulp.series(
|
|
|
|
|
'clean',
|
|
|
|
|
['js', 'html', 'css', 'icons', 'fonts', 'locale', 'manifest', 'license'],
|
|
|
|
|
gulp.parallel(
|
|
|
|
|
'js',
|
|
|
|
|
'html',
|
|
|
|
|
'css',
|
|
|
|
|
'icons',
|
|
|
|
|
'fonts',
|
|
|
|
|
'locale',
|
|
|
|
|
'manifest',
|
|
|
|
|
'license'
|
|
|
|
|
),
|
|
|
|
|
'copy'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
@ -215,4 +233,4 @@ gulp.task('inspect', function(done) {
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('default', ['build']);
|
|
|
|
|
gulp.task('default', gulp.series('build'));
|
|
|
|
|