2020-10-26 15:18:23 +03:00
|
|
|
import fs from 'fs';
|
|
|
|
import gulp from 'gulp';
|
|
|
|
import gutil from 'gulp-util';
|
|
|
|
import jade from 'gulp-pug';
|
|
|
|
import rename from 'gulp-rename';
|
|
|
|
import zip from 'gulp-zip';
|
|
|
|
import webpack from 'webpack';
|
|
|
|
import mocha from 'gulp-mocha';
|
|
|
|
import crdv from 'chromedriver';
|
|
|
|
import devConfig from './webpack/dev.config';
|
|
|
|
import prodConfig from './webpack/prod.config';
|
|
|
|
import wrapConfig from './webpack/wrap.config';
|
|
|
|
|
|
|
|
function copy(dest) {
|
|
|
|
gulp.src('./src/assets/**/*').pipe(gulp.dest(dest));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* common tasks
|
|
|
|
*/
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('replace-webpack-code', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
const replaceTasks = [
|
|
|
|
{
|
|
|
|
from: './webpack/replace/JsonpMainTemplate.runtime.js',
|
|
|
|
to: './node_modules/webpack/lib/JsonpMainTemplate.runtime.js',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: './webpack/replace/log-apply-result.js',
|
|
|
|
to: './node_modules/webpack/hot/log-apply-result.js',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
replaceTasks.forEach((task) =>
|
|
|
|
fs.writeFileSync(task.to, fs.readFileSync(task.from))
|
|
|
|
);
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dev tasks
|
|
|
|
*/
|
|
|
|
|
|
|
|
gulp.task('webpack:dev', (callback) => {
|
|
|
|
webpack(devConfig, (err, stats) => {
|
|
|
|
if (err) {
|
|
|
|
throw new gutil.PluginError('webpack:dev', err);
|
|
|
|
}
|
|
|
|
gutil.log('[webpack:dev]', stats.toString({ colors: true }));
|
|
|
|
});
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('views:dev', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
gulp
|
|
|
|
.src('./src/browser/views/*.pug')
|
|
|
|
.pipe(
|
|
|
|
jade({
|
|
|
|
locals: { env: 'dev' },
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest('./dev'));
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('copy:dev', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
gulp
|
|
|
|
.src('./src/browser/extension/manifest.json')
|
|
|
|
.pipe(rename('manifest.json'))
|
|
|
|
.pipe(gulp.dest('./dev'));
|
|
|
|
copy('./dev');
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* build tasks
|
|
|
|
*/
|
|
|
|
|
|
|
|
gulp.task('webpack:build:extension', (callback) => {
|
|
|
|
function webpackProcess(config) {
|
|
|
|
return new Promise((resolve, reject) =>
|
|
|
|
webpack(config, (err, stats) => {
|
|
|
|
if (err) {
|
|
|
|
reject(new gutil.PluginError('webpack:build', err));
|
|
|
|
}
|
|
|
|
gutil.log('[webpack:build]', stats.toString({ colors: true }));
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
webpackProcess(wrapConfig)
|
|
|
|
.then(() => webpackProcess(prodConfig))
|
|
|
|
.then(() => {
|
|
|
|
const dest = './build/extension';
|
|
|
|
fs.rename(
|
|
|
|
`${dest}/js/redux-devtools-extension.bundle.js`,
|
|
|
|
`${dest}/js/redux-devtools-extension.js`,
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('views:build:extension', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
gulp
|
|
|
|
.src(['./src/browser/views/*.pug'])
|
|
|
|
.pipe(
|
|
|
|
jade({
|
|
|
|
locals: { env: 'prod' },
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest('./build/extension'));
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('copy:build:extension', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
gulp
|
|
|
|
.src('./src/browser/extension/manifest.json')
|
|
|
|
.pipe(rename('manifest.json'))
|
|
|
|
.pipe(gulp.dest('./build/extension'));
|
|
|
|
copy('./build/extension');
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* compress task
|
|
|
|
*/
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('compress:extension', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
gulp
|
|
|
|
.src('build/extension/**')
|
|
|
|
.pipe(zip('extension.zip'))
|
|
|
|
.pipe(gulp.dest('./build'));
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task('compress:firefox', (done) => {
|
2020-10-26 15:18:23 +03:00
|
|
|
gulp
|
|
|
|
.src('build/firefox/**')
|
|
|
|
.pipe(zip('firefox.zip'))
|
|
|
|
.pipe(gulp.dest('./build'));
|
2020-10-31 15:51:20 +03:00
|
|
|
done();
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watch tasks
|
|
|
|
*/
|
|
|
|
|
|
|
|
gulp.task('views:watch', () => {
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.watch('./src/browser/views/*.pug', gulp.series('views:dev'));
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('copy:watch', () => {
|
|
|
|
gulp.watch(
|
|
|
|
['./src/browser/extension/manifest.json', './src/assets/**/*'],
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.series('copy:dev')
|
2020-10-26 15:18:23 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('test:chrome', () => {
|
|
|
|
crdv.start();
|
|
|
|
return gulp
|
|
|
|
.src('./test/chrome/*.spec.js')
|
|
|
|
.pipe(mocha({ require: ['babel-polyfill', 'co-mocha'] }))
|
|
|
|
.on('end', () => crdv.stop());
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('test:electron', () => {
|
|
|
|
crdv.start();
|
|
|
|
return gulp
|
|
|
|
.src('./test/electron/*.spec.js')
|
|
|
|
.pipe(mocha({ require: ['babel-polyfill', 'co-mocha'] }))
|
|
|
|
.on('end', () => crdv.stop());
|
|
|
|
});
|
|
|
|
|
2020-10-31 15:51:20 +03:00
|
|
|
gulp.task(
|
|
|
|
'default',
|
|
|
|
gulp.parallel(
|
|
|
|
'replace-webpack-code',
|
|
|
|
'webpack:dev',
|
|
|
|
'views:dev',
|
|
|
|
'copy:dev',
|
|
|
|
'views:watch',
|
|
|
|
'copy:watch'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
gulp.task(
|
|
|
|
'build:extension',
|
|
|
|
gulp.parallel(
|
|
|
|
'replace-webpack-code',
|
|
|
|
'webpack:build:extension',
|
|
|
|
'views:build:extension',
|
|
|
|
'copy:build:extension'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
gulp.task(
|
|
|
|
'copy:build:firefox',
|
|
|
|
gulp.series('build:extension', (done) => {
|
|
|
|
gulp
|
|
|
|
.src([
|
|
|
|
'./build/extension/**',
|
|
|
|
'!./build/extension/js/redux-devtools-extension.js',
|
|
|
|
])
|
|
|
|
.pipe(gulp.dest('./build/firefox'))
|
|
|
|
.on('finish', function () {
|
|
|
|
gulp
|
|
|
|
.src('./src/browser/firefox/manifest.json')
|
|
|
|
.pipe(gulp.dest('./build/firefox'));
|
|
|
|
});
|
|
|
|
copy('./build/firefox');
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
gulp.task('build:firefox', gulp.series('copy:build:firefox'));
|