Skip to content

Commit

Permalink
Added ES6 build
Browse files Browse the repository at this point in the history
  • Loading branch information
vitmalina committed Sep 24, 2021
1 parent e23f35d commit 4e45f80
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 66 deletions.
92 changes: 61 additions & 31 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,44 @@ const del = require('del')
// const babel = require('gulp-babel')
// const { exec } = require('child_process')
const comments = {
w2ui : '/* w2ui 2.0.x (nightly) ('+ (new Date()).toLocaleDateString('en-us') +') (c) http://w2ui.com, vitmalina@gmail.com */\n'
w2ui : '/* w2ui 2.0.x (nightly) ('+ (new Date()).toLocaleString('en-us') +') (c) http://w2ui.com, vitmalina@gmail.com */\n'
}

const legacy_code = `
// Compatibility with CommonJS and AMD modules
(function(global, w2ui) {
if (typeof define == 'function' && define.amd) {
return define(() => w2ui)
}
if (typeof exports != 'undefined') {
if (typeof module != 'undefined' && module.exports) {
return exports = module.exports = w2ui
}
global = exports
}
if (global) {
Object.keys(w2ui).forEach(key => {
global[key] = w2ui[key]
})
}
})(self, { w2ui, w2locale, w2utils, w2popup, w2alert, w2confirm, w2prompt, w2field, w2form, w2grid,
w2layout, w2sidebar, w2tabs, w2toolbar, addType, removeType })`

const files_js = [
'src/w2event.js', // order of files is important
'src/w2locale.js',
'src/w2utils.js',
'src/w2grid.js',
'src/w2layout.js',
'src/w2popup.js',
'src/w2tabs.js',
'src/w2toolbar.js',
'src/w2sidebar.js',
'src/w2field.js',
'src/w2form.js',
'src/w2compat.js' // must be last
]

let tasks = {

clean(cb) {
Expand Down Expand Up @@ -46,44 +81,39 @@ let tasks = {
},

pack(cb) {
console.log(' -- update only dist/w2ui.js')
return gulp
.src([
'src/w2event.js', // order of files is important
'src/w2locale.js',
'src/w2utils.js',
'src/w2grid.js',
'src/w2layout.js',
'src/w2popup.js',
'src/w2tabs.js',
'src/w2toolbar.js',
'src/w2sidebar.js',
'src/w2field.js',
'src/w2form.js',
'src/w2compat.js' // must be last
])
.src(files_js)
.pipe(concat('w2ui.js'))
.pipe(replace(/^(import.*'|export.*}|module\.exports.*})$\n/gm, ''))
.pipe(replace('\n\n', '\n'))
.pipe(header(comments.w2ui))
.pipe(gulp.dest('dist/'))
.on('end', () => {
cb()
})
},

build(cb) {
gulp.src([
'src/w2event.js', // order of files is important
'src/w2locale.js',
'src/w2utils.js',
'src/w2grid.js',
'src/w2layout.js',
'src/w2popup.js',
'src/w2tabs.js',
'src/w2toolbar.js',
'src/w2sidebar.js',
'src/w2field.js',
'src/w2form.js',
'src/w2compat.js' // must be last
])
return gulp
.src(files_js)
.pipe(concat('w2ui.js'))
.pipe(replace(/^(import.*'|export.*}|module\.exports.*})$\n/gm, ''))
.pipe(replace('\n\n', '\n'))
.pipe(replace(`export { w2ui, w2locale, w2utils, w2popup, w2alert, w2confirm, w2prompt, w2field, w2form, w2grid,
w2layout, w2sidebar, w2tabs, w2toolbar, addType, removeType }`, legacy_code))
.pipe(header(comments.w2ui))
.pipe(gulp.dest('dist/'))
.on('end', () => {
cb()
})
},

build_es6(cb) {
gulp.src(files_js)
.pipe(concat('w2ui.es6.js'))
.pipe(replace(/^(import.*'|export.*}|module\.exports.*})$\n/gm, ''))
.pipe(replace('\n\n', '\n'))
// .pipe(babel())
.pipe(header(comments.w2ui))
.pipe(gulp.dest('dist/'))
Expand Down Expand Up @@ -237,9 +267,9 @@ let tasks = {
}

exports.default = gulp.series(tasks.clean, tasks.less, tasks.locales, tasks.build)
exports.build = tasks.build
exports.build = gulp.series(tasks.build_es6, tasks.build)
exports.dev = tasks.watch
exports.clean = tasks.clean
exports.less = gulp.series(tasks.clean, tasks.less)
exports.icons = gulp.series(tasks.icons, tasks.less)
exports.locales = tasks.locales
exports.locales = tasks.locales
36 changes: 2 additions & 34 deletions src/w2compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1493,37 +1493,5 @@ import { w2toolbar } from './w2toolbar.js'

})(jQuery);

// Compatibility with CommonJS and AMD modules
(function(global, w2ui) {
if (typeof define == 'function' && define.amd) {
return define(() => w2ui)
}
if (typeof exports != 'undefined') {
if (typeof module != 'undefined' && module.exports) {
return exports = module.exports = w2ui
}
global = exports
}
if (global) {
Object.keys(w2ui).forEach(key => {
global[key] = w2ui[key]
})
}
})(self, {
w2ui,
w2locale,
w2utils,
w2popup,
w2alert,
w2confirm,
w2prompt,
w2field,
w2form,
w2grid,
w2layout,
w2sidebar,
w2tabs,
w2toolbar,
addType,
removeType
})
export { w2ui, w2locale, w2utils, w2popup, w2alert, w2confirm, w2prompt, w2field, w2form, w2grid,
w2layout, w2sidebar, w2tabs, w2toolbar, addType, removeType }
1 change: 0 additions & 1 deletion src/w2event.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/************************************************************************
* Part of w2ui 2.0 library
* - Dependencies: jQuery, w2utils
*
**/

import { w2utils } from './w2utils.js'
Expand Down

0 comments on commit 4e45f80

Please sign in to comment.