1
hao
2025-03-27 e610e1c17f62b423a717fadaaa7b139d02857793
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var gulp = require('gulp');
var header = require('gulp-header');
var clean = require('gulp-clean');
var gulpWebpack = require('webpack-stream');
var webpack = require('webpack');
var babel = require("gulp-babel");
var runSequence = require('gulp4-run-sequence');
var fs = require('fs');
 
var settings = require('./settings.json');
var shared = require('./shared.js');
 
gulp.task("clean", gulp.series(function () {
    return gulp.src(["bin/", "dist/"], { read: false })
        .pipe(clean());
}));
 
 
gulp.task("babel", gulp.series(function () {
    return babelFunc();
}));
 
 
function babelFunc() {
    return gulp.src("src/**/*")
        .pipe(babel({
            presets: ['es2015', 'stage-3']
        }))
        .pipe(gulp.dest("bin/"));
}
 
 
gulp.task("webpack", gulp.series(["babel"], function () {
    return webpackFunc();
}));
 
 
function webpackFunc() {
    return gulp.src('bin/JsBarcode.js')
        .pipe(gulpWebpack(
            {
                mode: "none",
                output: {
                    filename: 'JsBarcode.all.js'
                }
            }
            , webpack))
        .pipe(gulp.dest("dist/"));
}
 
 
gulp.task("webpack-min", gulp.series(["babel"], function () {
    return webpackMin('all');
}));
 
 
function webpackMin(name, dest) {
    dest = dest || './';
    return gulp.src('bin/JsBarcode.js')
        .pipe(gulpWebpack(
            {
                mode: "production",
                output: {
                    filename: shared.minifiedFilename(name)
                },
            }
            , webpack))
        .pipe(header(settings.banner, require(settings.baseDir + 'package.json')))
        .pipe(gulp.dest("dist/" + dest));
}
 
 
gulp.task("webpack-all", gulp.series(function (cb) {
    var barcodes = require('./barcode-building.json');
 
    // Move the real barcodes/index.js out of the way while compiling the individual barcodes
    fs.renameSync("src/barcodes/index.js", "src/barcodes/index.tmp.js");
 
    // Take a barcode from the barcodes array, call the functions to compile that
    // format and have a callback when it has finished.
    function loopBarcode(i) {
        if (i < barcodes.length) {
            createBarcodeInclude(barcodes[i], function () {
                loopBarcode(i + 1);
            });
        }
        else {
            fs.renameSync("src/barcodes/index.tmp.js", "src/barcodes/index.js");
            cb(); // Done
        }
    }
 
    loopBarcode(0);
}));
 
 
// Takes information about a barcode formatSize
// Modifies the barcodes/index.js file to only import the specified format
// and then does a recompilation and minifies everything with webpack
function createBarcodeInclude(barcode, callback) {
    var toFile = "";
    toFile += "import {" + barcode.names + "} from '" + barcode.barcodeFile + "'";
    toFile += "\n";
    toFile += "export default {" + barcode.names + "}";
 
    // Write a new barcodes/index file that only includes the specified barcode
    fs.writeFile("src/barcodes/index.js", toFile, function () {
        // Remove the compiled barcodes/index file (if it exist)
        if (fs.existsSync("bin/barcodes/index.js")) {
            fs.unlinkSync("bin/barcodes/index.js");
        }
        // Re-compile with babel and webpack everything
        babelFunc().on('end', function () {
            webpackMin(barcode.name, 'barcodes/').on('end', callback);
        });
    });
}
 
 
gulp.task('compress', gulp.series(function (cb) {
    runSequence(
        "clean",
        "webpack-all",
        "webpack",
        "webpack-min",
        cb
    );
}));
 
gulp.task('compile', gulp.series(['babel']));
 
gulp.task('compile-web', gulp.series(['webpack']));