Skip to content

Commit

Permalink
Added production package build
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-spiridonov committed Jan 19, 2017
1 parent 8f59a4f commit 16b6a35
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
webapp/
webapp/
release/
2 changes: 1 addition & 1 deletion .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"isCDN": false
"isCDN": false,
"output": "webapp",
"release": "release",
"pem": "release/gta.pem"
}
48 changes: 37 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ const gulpIf = require('gulp-if');
const del = require('del');
const webpack = require('webpack');
const jshint = require('gulp-jshint');
const zip = require('gulp-zip');
const path = require('path');
const cp = require('child_process');

const config = require('./config');

const isDevelopment = !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
const dest = config['output'];

if (!isDevelopment) {
console.log('Gulp: executing a production build!');
}

gulp.task('static', function () {
return gulp.src('src/*.{css,png,json}', {buffer: false, since: gulp.lastRun('static')}).pipe(debug())
.pipe(gulp.dest('webapp')).pipe(debug());
.pipe(gulp.dest(dest)).pipe(debug());
});

gulp.task('html', function () { // TODO: rewrite using jsdom parser and using external config for lib-to-cdn links mapping
let htmlDir = config.isCDN ? 'src/html-cdn/' : 'src/html/';
console.log(htmlDir + '*.html');

return gulp.src(htmlDir + '*.html', {buffer: false, since: gulp.lastRun('html')}).pipe(debug())
.pipe(gulp.dest('webapp')).pipe(debug());
.pipe(gulp.dest(dest)).pipe(debug());
});

gulp.task('webpack', function (callback) {
Expand All @@ -44,12 +48,34 @@ gulp.task('webpack', function (callback) {
});

gulp.task('clean', function () {
return del('webapp');
return del(dest);
});

gulp.task('crx', function (callback) {
console.log(`Packaging extension ${path.join(__dirname, dest)} with key ${path.join(__dirname, config.pem)}...`);

return cp.spawn('chrome', [`--pack-extension=${path.join(__dirname, dest)}`,
`--pack-extension-key=${path.join(__dirname, config.pem)}`,
`--artifacts-dir=${path.join(__dirname, 'release/')}`],
{cwd: path.join(__dirname, 'release/')})
.on('error', function (err) {
console.error(err);
callback();
}).on('close', function(code) {
return cp.spawn('mv', [`${dest}.crx`, `${path.join(config.release,'gta.crx')}`]);
});


});

gulp.task('zip', function () {
return gulp.src(dest + '/**/*').pipe(debug()).pipe(zip('gta.zip')).pipe(debug())
.pipe(gulp.dest(config.release));
});

gulp.task('build', gulp.series(
'clean',
gulp.parallel('static', 'html', 'webpack')
'clean',
gulp.parallel('static', 'html', 'webpack')
));


Expand All @@ -74,20 +100,20 @@ if (isDevelopment) {
gulp.task('default', gulp.series('build', 'watch'));

} else {
gulp.task('default', gulp.series('build'));
gulp.task('default', gulp.series('build', 'crx'));
}


gulp.task('jshint', function () {
return gulp.src('src/*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
// .pipe(jshint.reporter('fail'));
});

gulp.task('js', function () { // TODO: write webpack analogue in gulp
return gulp.src('src/*.js')
.pipe(gulpIf(isDevelopment, sourcemaps.init()))
.pipe(gulpIf(isDevelopment, sourcemaps.write()))
.pipe(gulp.dest('webapp'));
.pipe(gulpIf(isDevelopment, sourcemaps.init()))
.pipe(gulpIf(isDevelopment, sourcemaps.write()))
.pipe(gulp.dest(dest));
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
"gulp-newer": "^1.3.0",
"gulp-sourcemaps": "^2.4.0",
"gulp-util": "^3.0.8",
"gulp-zip": "^3.2.0",
"jshint": "^2.9.4",
"jshint-loader": "^0.8.3",
"jshint-stylish": "^2.2.1",
"path": "^0.12.7",
"stream-combiner2": "^1.1.1",
"style-loader": "^0.13.1",
"webpack": "^1.14.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "gulp static && webpack",
"prod": "cross-env NODE_ENV=production gulp static html && cross-env NODE_ENV=production webpack",
"prod": "cross-env NODE_ENV=production gulp static html && cross-env NODE_ENV=production webpack && gulp crx",
"jshint": "jshint src/ --reporter=./node_modules/jshint-stylish || true",
"eslint": "eslint src/ || true"
},
Expand Down
4 changes: 2 additions & 2 deletions src/GTASelect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global NODE_ENV */
/* global isCDN */
"use strict";

// Rely on CDN version in production. NODE_ENV resolved via webpack.
const template = NODE_ENV === 'development' ? require('lodash/template') : _.template;
const template = isCDN ? _.template : require('lodash/template');

// const db = require('./db').db;

Expand Down
3 changes: 1 addition & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
},
"permissions": [
"tabs",
"bookmarks",
"*://*/*"
"bookmarks"
],
"web_accessible_resources": [
"*.js.map"
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ module.exports = {

plugins: [
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(isDevelopment ? "development" : "production") // use NODE_ENV as constant in code
NODE_ENV: JSON.stringify(isDevelopment ? "development" : "production"), // use NODE_ENV as constant in code
isCDN: config.isCDN
}),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({ // webpack will add require on free $ variable
Expand Down

0 comments on commit 16b6a35

Please sign in to comment.