2018-01-13 14:54:49 +05:30
|
|
|
/*eslint-env node*/
|
|
|
|
|
2018-01-13 23:09:35 +05:30
|
|
|
const fs = require('fs');
|
|
|
|
const gulp = require('gulp');
|
2018-06-16 19:18:24 +05:30
|
|
|
const runSequence = require('run-sequence');
|
2018-01-13 23:09:35 +05:30
|
|
|
const useref = require('gulp-useref');
|
|
|
|
const cleanCSS = require('gulp-clean-css');
|
2018-06-19 10:49:26 +05:30
|
|
|
const rename = require('gulp-rename');
|
|
|
|
const concat = require('gulp-concat');
|
2018-01-13 23:09:35 +05:30
|
|
|
const babelMinify = require('babel-minify');
|
2018-06-16 19:18:24 +05:30
|
|
|
const child_process = require('child_process');
|
|
|
|
const merge = require('merge-stream');
|
2018-06-21 01:01:48 +05:30
|
|
|
const zip = require('gulp-zip');
|
2018-06-23 09:42:42 +05:30
|
|
|
var packageJson = JSON.parse(fs.readFileSync('./package.json'));
|
2017-11-08 01:04:59 +05:30
|
|
|
|
2018-01-13 23:09:35 +05:30
|
|
|
function minifyJs(fileName) {
|
2018-01-22 12:03:06 +05:30
|
|
|
const content = fs.readFileSync(fileName, 'utf8');
|
2018-01-13 23:09:35 +05:30
|
|
|
const minifiedContent = babelMinify(content).code;
|
|
|
|
fs.writeFileSync(fileName, minifiedContent);
|
2018-01-22 12:03:06 +05:30
|
|
|
console.log(
|
|
|
|
`[${fileName}]: ${content.length}kb -> ${minifiedContent.length}kb`
|
|
|
|
);
|
2018-01-13 23:09:35 +05:30
|
|
|
}
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('runWebpack', function() {
|
2018-06-16 19:18:24 +05:30
|
|
|
return child_process.execSync('yarn run build');
|
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('copyFiles', function() {
|
2018-06-16 19:18:24 +05:30
|
|
|
return merge(
|
|
|
|
gulp
|
2018-06-19 10:49:26 +05:30
|
|
|
.src('src/lib/codemirror/theme/*')
|
|
|
|
.pipe(gulp.dest('app/lib/codemirror/theme')),
|
2018-06-16 19:18:24 +05:30
|
|
|
gulp
|
2018-06-19 10:49:26 +05:30
|
|
|
.src('src/lib/codemirror/mode/**/*')
|
|
|
|
.pipe(gulp.dest('app/lib/codemirror/mode')),
|
2018-06-16 19:18:24 +05:30
|
|
|
gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers')),
|
|
|
|
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib')),
|
2018-06-22 21:39:29 +05:30
|
|
|
gulp.src('icons/*').pipe(gulp.dest('app/icons')),
|
2018-07-31 01:03:38 +05:30
|
|
|
gulp.src('src/assets/*').pipe(gulp.dest('app/assets')),
|
2018-07-31 01:16:26 +05:30
|
|
|
gulp.src('src/templates/*').pipe(gulp.dest('app/templates')),
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp
|
|
|
|
.src([
|
|
|
|
'src/preview.html',
|
|
|
|
'src/detached-window.js',
|
|
|
|
'src/icon-48.png',
|
|
|
|
'src/icon-128.png',
|
2018-06-22 12:38:00 +05:30
|
|
|
'manifest.json'
|
2018-06-19 10:49:26 +05:30
|
|
|
])
|
|
|
|
.pipe(gulp.dest('app')),
|
|
|
|
|
|
|
|
gulp
|
|
|
|
.src('build/bundle.*.js')
|
|
|
|
.pipe(rename('script.js'))
|
|
|
|
.pipe(gulp.dest('app')),
|
|
|
|
gulp
|
|
|
|
.src('build/vendor.*.js')
|
|
|
|
.pipe(rename('vendor.js'))
|
|
|
|
.pipe(gulp.dest('app')),
|
|
|
|
|
|
|
|
// Following CSS are copied to build/ folder where they'll be referenced by
|
|
|
|
// useRef plugin to concat into one.
|
|
|
|
gulp
|
|
|
|
.src('src/lib/codemirror/lib/codemirror.css')
|
|
|
|
.pipe(gulp.dest('build/lib/codemirror/lib')),
|
|
|
|
gulp
|
|
|
|
.src('src/lib/codemirror/addon/hint/show-hint.css')
|
|
|
|
.pipe(gulp.dest('build/lib/codemirror/addon/hint')),
|
|
|
|
gulp
|
|
|
|
.src('src/lib/codemirror/addon/fold/foldgutter.css')
|
|
|
|
.pipe(gulp.dest('build/lib/codemirror/addon/fold')),
|
|
|
|
gulp
|
|
|
|
.src('src/lib/codemirror/addon/dialog/dialog.css')
|
|
|
|
.pipe(gulp.dest('build/lib/codemirror/addon/dialog')),
|
2018-06-16 19:18:24 +05:30
|
|
|
gulp.src('src/lib/hint.min.css').pipe(gulp.dest('build/lib')),
|
|
|
|
gulp.src('src/lib/inlet.css').pipe(gulp.dest('build/lib')),
|
|
|
|
gulp.src('src/style.css').pipe(gulp.dest('build')),
|
|
|
|
|
|
|
|
gulp
|
2018-06-19 10:49:26 +05:30
|
|
|
.src([
|
|
|
|
'src/FiraCode.ttf',
|
|
|
|
'src/FixedSys.ttf',
|
|
|
|
'src/Inconsolata.ttf',
|
|
|
|
'src/Monoid.ttf'
|
|
|
|
])
|
|
|
|
.pipe(gulp.dest('app'))
|
2018-06-16 19:18:24 +05:30
|
|
|
);
|
2017-11-08 01:04:59 +05:30
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('useRef', function() {
|
2018-01-13 14:55:39 +05:30
|
|
|
return gulp
|
2018-06-16 19:18:24 +05:30
|
|
|
.src('build/index.html')
|
2018-01-13 14:55:39 +05:30
|
|
|
.pipe(useref())
|
|
|
|
.pipe(gulp.dest('app'));
|
2017-11-08 01:04:59 +05:30
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('concatSwRegistration', function() {
|
|
|
|
gulp
|
2018-06-19 10:59:46 +05:30
|
|
|
.src(['src/service-worker-registration.js', 'app/script.js'])
|
2018-06-19 10:49:26 +05:30
|
|
|
.pipe(concat('script.js'))
|
|
|
|
.pipe(gulp.dest('app'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('minify', function() {
|
|
|
|
minifyJs('app/script.js');
|
2018-06-19 11:01:39 +05:30
|
|
|
minifyJs('app/vendor.js');
|
2018-01-14 11:33:14 +05:30
|
|
|
minifyJs('app/lib/screenlog.js');
|
2018-01-13 23:09:35 +05:30
|
|
|
|
2018-01-22 12:03:06 +05:30
|
|
|
gulp
|
|
|
|
.src('app/*.css')
|
|
|
|
.pipe(
|
2018-06-19 10:49:26 +05:30
|
|
|
cleanCSS(
|
|
|
|
{
|
|
|
|
debug: true
|
|
|
|
},
|
|
|
|
details => {
|
|
|
|
console.log(`${details.name}: ${details.stats.originalSize}`);
|
|
|
|
console.log(`${details.name}: ${details.stats.minifiedSize}`);
|
|
|
|
}
|
|
|
|
)
|
2018-01-22 12:03:06 +05:30
|
|
|
)
|
2018-01-13 23:09:35 +05:30
|
|
|
.pipe(gulp.dest('app'));
|
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('fixIndex', function() {
|
2018-06-16 19:18:24 +05:30
|
|
|
var contents = fs.readFileSync('build/index.html', 'utf8');
|
2018-06-19 10:49:26 +05:30
|
|
|
// Replace hashed-filename script tags with unhashed ones
|
|
|
|
contents = contents.replace(
|
|
|
|
/\<\!\-\- SCRIPT-TAGS \-\-\>[\S\s]*?\<\!\-\- END-SCRIPT-TAGS \-\-\>/,
|
|
|
|
'<script defer src="vendor.js"></script><script defer src="script.js"></script>'
|
|
|
|
);
|
|
|
|
|
|
|
|
// vendor.hash.js gets created outside our markers, so remove it
|
|
|
|
contents = contents.replace(
|
|
|
|
/\<script src="\/vendor\.[\S\s]*?\<\/script\>/,
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
2018-06-16 19:18:24 +05:30
|
|
|
fs.writeFileSync('build/index.html', contents, 'utf8');
|
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('generate-service-worker', function(callback) {
|
2017-11-19 23:47:02 +05:30
|
|
|
var swPrecache = require('sw-precache');
|
|
|
|
var rootDir = 'app';
|
2017-11-08 01:04:59 +05:30
|
|
|
|
2017-11-19 23:47:02 +05:30
|
|
|
swPrecache.write(
|
2018-06-19 10:49:26 +05:30
|
|
|
`${rootDir}/service-worker.js`,
|
|
|
|
{
|
2017-11-19 23:47:02 +05:30
|
|
|
staticFileGlobs: [
|
|
|
|
rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'
|
|
|
|
],
|
2018-01-14 00:39:03 +05:30
|
|
|
stripPrefix: `${rootDir}/`,
|
|
|
|
|
|
|
|
// has to be increased to around 2.8mb for sass.worker.js
|
|
|
|
maximumFileSizeToCacheInBytes: 2900000
|
2017-11-19 23:47:02 +05:30
|
|
|
},
|
|
|
|
callback
|
|
|
|
);
|
2017-11-08 01:04:59 +05:30
|
|
|
});
|
|
|
|
|
2018-06-21 01:01:48 +05:30
|
|
|
gulp.task('packageExtension', function() {
|
|
|
|
child_process.execSync('cp -R app extension/');
|
|
|
|
child_process.execSync('cp src/manifest.json extension');
|
|
|
|
child_process.execSync('cp src/options.js extension');
|
|
|
|
child_process.execSync('cp src/options.html extension');
|
|
|
|
child_process.execSync('cp src/eventPage.js extension');
|
|
|
|
child_process.execSync('cp src/icon-16.png extension');
|
|
|
|
child_process.execSync(
|
|
|
|
'rm -rf extension/service-worker.js extension/partials'
|
|
|
|
);
|
|
|
|
return merge(
|
|
|
|
gulp
|
|
|
|
.src('build/bundle.*.js')
|
|
|
|
.pipe(rename('script.js'))
|
|
|
|
.pipe(gulp.dest('extension')),
|
|
|
|
gulp
|
|
|
|
.src('build/vendor.*.js')
|
|
|
|
.pipe(rename('vendor.js'))
|
|
|
|
.pipe(gulp.dest('extension')),
|
|
|
|
|
|
|
|
gulp
|
2018-06-23 12:12:36 +05:30
|
|
|
.src('extension/**/*')
|
2018-06-23 09:42:42 +05:30
|
|
|
.pipe(zip(`extension-${packageJson.version}.zip`))
|
2018-06-21 01:01:48 +05:30
|
|
|
.pipe(gulp.dest('./'))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('cleanup', function() {
|
2018-06-16 19:18:24 +05:30
|
|
|
return child_process.execSync('rm -rf build');
|
|
|
|
});
|
|
|
|
|
2018-06-19 10:49:26 +05:30
|
|
|
gulp.task('release', function(callback) {
|
2018-06-16 19:18:24 +05:30
|
|
|
runSequence(
|
|
|
|
'runWebpack',
|
|
|
|
'copyFiles',
|
|
|
|
'fixIndex',
|
|
|
|
'useRef',
|
2018-06-19 10:49:26 +05:30
|
|
|
'concatSwRegistration',
|
2018-06-16 19:18:24 +05:30
|
|
|
'minify',
|
|
|
|
'generate-service-worker',
|
2018-06-21 01:01:48 +05:30
|
|
|
'packageExtension',
|
2018-06-16 19:18:24 +05:30
|
|
|
'cleanup',
|
2018-06-19 10:49:26 +05:30
|
|
|
function(error) {
|
2018-06-16 19:18:24 +05:30
|
|
|
if (error) {
|
|
|
|
console.log(error.message);
|
|
|
|
} else {
|
|
|
|
console.log('RELEASE FINISHED SUCCESSFULLY');
|
|
|
|
}
|
|
|
|
callback(error);
|
2018-06-19 10:49:26 +05:30
|
|
|
}
|
|
|
|
);
|
2018-06-16 19:18:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
// gulp.task('default', ['generate-service-worker']);
|