* update for gulp 4.0.0

* added gulp 4.0.0
This commit is contained in:
Pawel Raszewski 2018-12-05 03:35:52 -05:00 committed by Jos de Jong
parent 9ac82e24d2
commit 404fa036f9
3 changed files with 1893 additions and 374 deletions

View File

@ -8,22 +8,22 @@ var mkdirp = require('mkdirp');
var webpack = require('webpack'); var webpack = require('webpack');
var uglify = require('uglify-js'); var uglify = require('uglify-js');
var NAME = 'jsoneditor'; var NAME = 'jsoneditor';
var NAME_MINIMALIST = 'jsoneditor-minimalist'; var NAME_MINIMALIST = 'jsoneditor-minimalist';
var ENTRY = './src/js/JSONEditor.js'; var ENTRY = './src/js/JSONEditor.js';
var HEADER = './src/js/header.js'; var HEADER = './src/js/header.js';
var IMAGE = './src/css/img/jsoneditor-icons.svg'; var IMAGE = './src/css/img/jsoneditor-icons.svg';
var DOCS = './src/docs/*'; var DOCS = './src/docs/*';
var DIST = './dist'; var DIST = './dist';
// generate banner with today's date and correct version // generate banner with today's date and correct version
function createBanner() { function createBanner() {
var today = gutil.date(new Date(), 'yyyy-mm-dd'); // today, formatted as yyyy-mm-dd var today = gutil.date(new Date(), 'yyyy-mm-dd'); // today, formatted as yyyy-mm-dd
var version = require('./package.json').version; // math.js version var version = require('./package.json').version; // math.js version
return String(fs.readFileSync(HEADER)) return String(fs.readFileSync(HEADER))
.replace('@@date', today) .replace('@@date', today)
.replace('@@version', version); .replace('@@version', version);
} }
var bannerPlugin = new webpack.BannerPlugin(createBanner(), { var bannerPlugin = new webpack.BannerPlugin(createBanner(), {
@ -40,11 +40,9 @@ var compiler = webpack({
path: DIST, path: DIST,
filename: NAME + '.js' filename: NAME + '.js'
}, },
plugins: [ bannerPlugin ], plugins: [bannerPlugin],
module: { module: {
loaders: [ loaders: [{ test: /\.json$/, loader: 'json' }]
{ test: /\.json$/, loader: "json" }
]
}, },
cache: true cache: true
}); });
@ -77,7 +75,7 @@ function minify(name) {
}); });
if (result.error) { if (result.error) {
throw result.error throw result.error;
} }
var fileMin = DIST + '/' + name + '.min.js'; var fileMin = DIST + '/' + name + '.min.js';
@ -91,109 +89,149 @@ function minify(name) {
} }
// make dist folder structure // make dist folder structure
gulp.task('mkdir', function () { gulp.task('mkdir', function(done) {
mkdirp.sync(DIST); mkdirp.sync(DIST);
mkdirp.sync(DIST + '/img'); mkdirp.sync(DIST + '/img');
done();
}); });
// bundle javascript // bundle javascript
gulp.task('bundle', ['mkdir'], function (done) { gulp.task(
// update the banner contents (has a date in it which should stay up to date) 'bundle',
bannerPlugin.banner = createBanner(); gulp.series(gulp.parallel('mkdir'), function(done) {
// update the banner contents (has a date in it which should stay up to date)
bannerPlugin.banner = createBanner();
compiler.run(function (err, stats) { compiler.run(function(err, stats) {
if (err) { if (err) {
gutil.log(err); gutil.log(err);
} }
gutil.log('bundled ' + NAME + '.js'); gutil.log('bundled ' + NAME + '.js');
done(); done();
}); });
}); })
);
// bundle minimalist version of javascript // bundle minimalist version of javascript
gulp.task('bundle-minimalist', ['mkdir'], function (done) { gulp.task(
// update the banner contents (has a date in it which should stay up to date) 'bundle-minimalist',
bannerPlugin.banner = createBanner(); gulp.series(gulp.parallel('mkdir'), function(done) {
// update the banner contents (has a date in it which should stay up to date)
bannerPlugin.banner = createBanner();
compilerMinimalist.run(function (err, stats) { compilerMinimalist.run(function(err, stats) {
if (err) { if (err) {
gutil.log(err); gutil.log(err);
} }
gutil.log('bundled ' + NAME_MINIMALIST + '.js'); gutil.log('bundled ' + NAME_MINIMALIST + '.js');
done(); done();
}); });
}); })
);
// bundle css // bundle css
gulp.task('bundle-css', ['mkdir'], function () { gulp.task(
gulp.src([ 'bundle-css',
'src/css/reset.css', gulp.series(gulp.parallel('mkdir'), function(done) {
'src/css/jsoneditor.css', gulp
'src/css/contextmenu.css', .src([
'src/css/menu.css', 'src/css/reset.css',
'src/css/searchbox.css', 'src/css/jsoneditor.css',
'src/css/autocomplete.css', 'src/css/contextmenu.css',
'src/css/treepath.css', 'src/css/menu.css',
'src/css/statusbar.css', 'src/css/searchbox.css',
'src/css/navigationbar.css', 'src/css/autocomplete.css',
'src/js/assets/selectr/selectr.css' 'src/css/treepath.css',
]) 'src/css/statusbar.css',
'src/css/navigationbar.css',
'src/js/assets/selectr/selectr.css'
])
.pipe(concatCss(NAME + '.css')) .pipe(concatCss(NAME + '.css'))
.pipe(gulp.dest(DIST)) .pipe(gulp.dest(DIST))
.pipe(concatCss(NAME + '.min.css')) .pipe(concatCss(NAME + '.min.css'))
.pipe(minifyCSS()) .pipe(minifyCSS())
.pipe(gulp.dest(DIST)); .pipe(gulp.dest(DIST));
gutil.log('bundled ' + DIST + '/' + NAME + '.css'); gutil.log('bundled ' + DIST + '/' + NAME + '.css');
gutil.log('bundled ' + DIST + '/' + NAME + '.min.css'); gutil.log('bundled ' + DIST + '/' + NAME + '.min.css');
}); done();
})
);
// create a folder img and copy the icons // create a folder img and copy the icons
gulp.task('copy-img', ['mkdir'], function () { gulp.task(
gulp.src(IMAGE) 'copy-img',
.pipe(gulp.dest(DIST + '/img')); gulp.series(gulp.parallel('mkdir'), function(done) {
gutil.log('Copied images'); gulp.src(IMAGE).pipe(gulp.dest(DIST + '/img'));
}); gutil.log('Copied images');
done();
})
);
// create a folder img and copy the icons // create a folder img and copy the icons
gulp.task('copy-docs', ['mkdir'], function () { gulp.task(
gulp.src(DOCS) 'copy-docs',
.pipe(gulp.dest(DIST)); gulp.series(gulp.parallel('mkdir'), function(done) {
gutil.log('Copied doc'); gulp.src(DOCS).pipe(gulp.dest(DIST));
}); gutil.log('Copied doc');
done();
})
);
gulp.task('minify', ['bundle'], function () { gulp.task(
minify(NAME) 'minify',
}); gulp.series(gulp.parallel('bundle'), function(done) {
minify(NAME);
done();
})
);
gulp.task('minify-minimalist', ['bundle-minimalist'], function () { gulp.task(
minify(NAME_MINIMALIST) 'minify-minimalist',
}); gulp.series(gulp.parallel('bundle-minimalist'), function(done) {
minify(NAME_MINIMALIST);
done();
})
);
// TODO: zip file using archiver // TODO: zip file using archiver
var pkg = 'jsoneditor-' + require('./package.json').version + '.zip'; var pkg = 'jsoneditor-' + require('./package.json').version + '.zip';
gulp.task('zip', shell.task([ gulp.task(
'zip ' + pkg + ' ' + 'README.md NOTICE LICENSE HISTORY.md index.html src dist docs examples -r ' 'zip',
])); shell.task([
'zip ' +
pkg +
' ' +
'README.md NOTICE LICENSE HISTORY.md index.html src dist docs examples -r '
])
);
// The watch task (to automatically rebuild when the source code changes) // The watch task (to automatically rebuild when the source code changes)
// Does only generate jsoneditor.js and jsoneditor.css, and copy the image // Does only generate jsoneditor.js and jsoneditor.css, and copy the image
// Does NOT minify the code and does NOT generate the minimalist version // Does NOT minify the code and does NOT generate the minimalist version
gulp.task('watch', ['bundle', 'bundle-css', 'copy-img'], function () { gulp.task(
gulp.watch(['src/**/*'], ['bundle', 'bundle-css', 'copy-img']); 'watch',
}); gulp.series(gulp.parallel('bundle', 'bundle-css', 'copy-img'), function() {
gulp.watch(['src/**/*'], gulp.series('bundle', 'bundle-css', 'copy-img'));
})
);
// The default task (called when you run `gulp`) // The default task (called when you run `gulp`)
gulp.task('default', [ gulp.task(
'bundle', 'default',
'bundle-minimalist', gulp.series(
'bundle-css', gulp.parallel(
'copy-img', 'bundle',
'copy-docs', 'bundle-minimalist',
'minify', 'bundle-css',
'minify-minimalist' 'copy-img',
]); 'copy-docs',
'minify',
'minify-minimalist'
)
)
);

2059
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@
"vanilla-picker": "2.4.2" "vanilla-picker": "2.4.2"
}, },
"devDependencies": { "devDependencies": {
"gulp": "3.9.1", "gulp": "4.0.0",
"gulp-clean-css": "3.4.2", "gulp-clean-css": "3.4.2",
"gulp-concat-css": "2.3.0", "gulp-concat-css": "2.3.0",
"gulp-shell": "0.6.3", "gulp-shell": "0.6.3",