diff --git a/.gitignore b/.gitignore
index 21d135e..4925da5 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-webapp/
\ No newline at end of file
+webapp/
+release/
\ No newline at end of file
diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index c4c9543..34065d0 100755
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -4,6 +4,6 @@
-
+
\ No newline at end of file
diff --git a/config.json b/config.json
index 64bc92b..93c7886 100755
--- a/config.json
+++ b/config.json
@@ -1,3 +1,6 @@
{
- "isCDN": false
+ "isCDN": false,
+ "output": "webapp",
+ "release": "release",
+ "pem": "release/gta.pem"
}
\ No newline at end of file
diff --git a/gulpfile.js b/gulpfile.js
index cec42f5..49bc5fa 100755
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -9,10 +9,14 @@ 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!');
@@ -20,7 +24,7 @@ if (!isDevelopment) {
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
@@ -28,7 +32,7 @@ gulp.task('html', function () { // TODO: rewrite using jsdom parser and using e
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) {
@@ -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')
));
@@ -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));
});
\ No newline at end of file
diff --git a/package.json b/package.json
index 24babb7..fe66a98 100755
--- a/package.json
+++ b/package.json
@@ -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"
},
diff --git a/src/GTASelect.js b/src/GTASelect.js
index 847d0d3..631f686 100755
--- a/src/GTASelect.js
+++ b/src/GTASelect.js
@@ -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;
diff --git a/src/manifest.json b/src/manifest.json
index a0b514f..7214302 100755
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -9,8 +9,7 @@
},
"permissions": [
"tabs",
- "bookmarks",
- "*://*/*"
+ "bookmarks"
],
"web_accessible_resources": [
"*.js.map"
diff --git a/webpack.config.js b/webpack.config.js
index a9b288d..6cc2cc7 100755
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -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