|
| 1 | +/* global require, exports */ |
| 2 | +const { series, src, dest } = require('gulp'); |
| 3 | +const babel = require('gulp-babel'); |
| 4 | +const minify = require('gulp-minify'); |
| 5 | +const sass = require('gulp-sass'); |
| 6 | +const cleanCSS = require('gulp-clean-css'); |
| 7 | +const rename = require('gulp-rename'); |
| 8 | +const header = require('gulp-header'); |
| 9 | +const footer = require('gulp-footer'); |
| 10 | +const pkg = require('./package.json'); |
| 11 | + |
| 12 | + |
| 13 | +let header_banner_strict = ['', |
| 14 | + '\'use strict\';', |
| 15 | + ''].join('\n'); |
| 16 | + |
| 17 | +let header_banner = ['/**', |
| 18 | + ' * jsPanel - <%= pkg.description %>', |
| 19 | + ' * @version v<%= pkg.version %>', |
| 20 | + ' * @homepage <%= pkg.homepage %>', |
| 21 | + ' * @license <%= pkg.license %>', |
| 22 | + ' * @author <%= pkg.author.name %> - <%= pkg.author.email %>', |
| 23 | + ' * @github <%= pkg.repository.url %>', |
| 24 | + ' */', |
| 25 | + ''].join('\n'); |
| 26 | + |
| 27 | +let header_banner_es6_export = '\nexport '; |
| 28 | + |
| 29 | +let header_banner_es6_import = '\nimport {jsPanel} from \'../../jspanel.js\';\n\n'; |
| 30 | + |
| 31 | +let footer_banner = ['\n', |
| 32 | + '// Add CommonJS module exports, so it can be imported using require() in Node.js', |
| 33 | + '// https://nodejs.org/docs/latest/api/modules.html', |
| 34 | + 'if (typeof module !== \'undefined\') { module.exports = jsPanel; }', |
| 35 | + ''].join('\n'); |
| 36 | + |
| 37 | +function scss() { |
| 38 | + return src('source/**/*.sass') |
| 39 | + .pipe(sass().on('error', sass.logError)) |
| 40 | + .pipe(header(header_banner, { pkg : pkg } )) |
| 41 | + .pipe(dest('dist/')) |
| 42 | + .pipe(dest('es6module/')) |
| 43 | + .pipe(cleanCSS()) |
| 44 | + .pipe(rename({ suffix: '.min' })) |
| 45 | + .pipe(dest('dist/')) |
| 46 | + .pipe(dest('es6module/')); |
| 47 | +} |
| 48 | + |
| 49 | +function jspanel() { |
| 50 | + // calendar extension excluded because it's only experimental |
| 51 | + return src('source/**/*.js') |
| 52 | + .pipe(babel({ |
| 53 | + presets: [ |
| 54 | + ['@babel/env', { |
| 55 | + 'modules': false |
| 56 | + }] |
| 57 | + ] |
| 58 | + })) |
| 59 | + .pipe(header(header_banner_strict, { pkg : pkg } )) |
| 60 | + .pipe(header(header_banner, { pkg : pkg } )) |
| 61 | + .pipe(footer(footer_banner, { pkg : pkg } )) |
| 62 | + .pipe(dest('dist')) |
| 63 | + .pipe(minify({ |
| 64 | + ext:{ min:'.min.js' } |
| 65 | + })) |
| 66 | + .pipe(dest('dist')); |
| 67 | +} |
| 68 | +function jspanel_es6() { |
| 69 | + return src('source/jspanel.js') |
| 70 | + .pipe(header(header_banner_es6_export, { pkg : pkg } )) |
| 71 | + .pipe(header(header_banner, { pkg : pkg } )) |
| 72 | + .pipe(dest('es6module/')) |
| 73 | + .pipe(minify({ |
| 74 | + ext:{ min:'.min.js' } |
| 75 | + })) |
| 76 | + .pipe(dest('es6module/')); |
| 77 | +} |
| 78 | +// don't merge jspanel_es6 with jspanel_extensions_es6 because extensions don't export anything but need the import statement |
| 79 | +function jspanel_extensions_es6() { |
| 80 | + // calendar extension excluded because it's only experimental |
| 81 | + return src('source/extensions/**/*.js') |
| 82 | + .pipe(header(header_banner_es6_import, { pkg : pkg } )) |
| 83 | + .pipe(header(header_banner, { pkg : pkg } )) |
| 84 | + .pipe(dest('es6module/extensions/')) |
| 85 | + .pipe(minify({ |
| 86 | + ext:{ min:'.min.js' } |
| 87 | + })) |
| 88 | + .pipe(dest('es6module/extensions/')); |
| 89 | +} |
| 90 | + |
| 91 | +function template() { |
| 92 | + return src('template_standard.html') |
| 93 | + .pipe(rename('index.html')) |
| 94 | + .pipe(dest('dist/')); |
| 95 | +} |
| 96 | +function templateES6() { |
| 97 | + return src('template_es6module.html') |
| 98 | + .pipe(rename('index.html')) |
| 99 | + .pipe(dest('es6module/')); |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +exports.default = series(jspanel, jspanel_es6, jspanel_extensions_es6, scss, template, templateES6); |
0 commit comments