Skip to content

Commit

Permalink
Added compiling of single barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed May 14, 2016
1 parent fc6b9cd commit 96c92f6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 11 deletions.
32 changes: 32 additions & 0 deletions barcode-building.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"filename": "JsBarcode.code39.min.js",
"names": "CODE39",
"barcodeFile": "./CODE39"
},
{
"filename": "JsBarcode.code128.min.js",
"names": ["CODE128, CODE128A, CODE128B, CODE128C"],
"barcodeFile": "./CODE128"
},
{
"filename": "JsBarcode.ean-upc.min.js",
"names": "EAN13, EAN8, EAN5, EAN2, UPC",
"barcodeFile": "./EAN_UPC"
},
{
"filename": "JsBarcode.itf-14.min.js",
"names": "ITF14",
"barcodeFile": "./ITF14"
},
{
"filename": "JsBarcode.msi.min.js",
"names": "MSI, MSI10, MSI11, MSI1010, MSI1110",
"barcodeFile": "./MSI"
},
{
"filename": "JsBarcode.pharmacode.min.js",
"names": "pharmacode",
"barcodeFile": "./pharmacode"
}
]
73 changes: 62 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,93 @@ var clean = require('gulp-clean');
var gulpWebpack = require('webpack-stream');
var webpack = require('webpack');

var fs = require('fs');

gulp.task("clean", function(){
return gulp.src("bin/", {read: false})
.pipe(clean());
});

gulp.task("babel", function () {
return babelFunc();
});

function babelFunc(){
return gulp.src("src/**/*")
.pipe(babel({
presets: ['es2015'],
plugins: [["transform-es2015-classes", {loose: true}]]
}))
}))
.pipe(gulp.dest("bin/node/"));
});
}

gulp.task("webpack", ["babel"], function () {
return gulp.src('bin/node/JsBarcode.js')
return webpackFunc();
});

function webpackFunc(){
return gulp.src('bin/node/JsBarcode.js')
.pipe(gulpWebpack(
{
output: {
filename: 'JsBarcode.js',
filename: 'JsBarcode.all.js',
}
}
, webpack))

.pipe(gulp.dest("bin/browser/"));
});
}

gulp.task("webpack-min", ["babel"], function () {
return gulp.src('bin/node/JsBarcode.js')
return webpackMin('JsBarcode.all.min.js');
});

function webpackMin(filename){
return gulp.src('bin/node/JsBarcode.js')
.pipe(gulpWebpack(
{
output: {
filename: 'JsBarcode.min.js',
filename: filename,
},
plugins: [new webpack.optimize.UglifyJsPlugin()],
}
, webpack))

.pipe(gulp.dest("bin/browser/"));
}

gulp.task("webpack-all", function (cb) {
var barcodes = require('./barcode-building.json');

fs.renameSync("src/barcodes/index.js", "src/barcodes/index.tmp.js");

function createBarcodeInclude(barcode, callback){
var toFile = "";
toFile += "import {" + barcode.names + "} from '" + barcode.barcodeFile + "'";
toFile += "\n";
toFile += "export default {" + barcode.names + "}";

fs.writeFile("src/barcodes/index.js", toFile, function(){
if(fs.existsSync("bin/node/barcodes/index.js")){
fs.unlinkSync("bin/node/barcodes/index.js");
}
babelFunc().on('end', function(){
webpackMin("barcodes/" + barcode.filename).on('end', callback);
});
});
}

var i = 0;
(function loopBarcodes(){
createBarcodeInclude(barcodes[i], function(){
i++;
if(i < barcodes.length){
loopBarcodes();
}
else{
fs.renameSync("src/barcodes/index.tmp.js", "src/barcodes/index.js");
cb(); // Done
}
});
})();
});

gulp.task('watch', ['compile'], function() {
Expand All @@ -64,8 +109,14 @@ gulp.task('watch-web', ['webpack'], function() {
gulp.watch("src/**/*", ['webpack']);
});

gulp.task('compress', ["webpack", "webpack-min"], function() {
var pkg = require('./package.json');
gulp.task('compress', function(cb) {
runSequence(
"clean",
"webpack-all",
"webpack",
"webpack-min",
cb
);
});


Expand Down

0 comments on commit 96c92f6

Please sign in to comment.