提交 4eb98d72 编写于 作者: C Catouse

* refactor gulp tasks.

上级 fc9f7204
...@@ -35,12 +35,13 @@ var today = moment(); ...@@ -35,12 +35,13 @@ var today = moment();
var typeSet = ['less', 'js', 'resource'], var typeSet = ['less', 'js', 'resource'],
lib = zui.lib, lib = zui.lib,
builds = zui.builds, builds = zui.builds,
banner = ('/*!\n' + BANNER = ('/*!\n' +
' * {title} - v{version} - {date}\n' + ' * {title} - v{version} - {date}\n' +
' * {homepage}\n' + ' * {homepage}\n' +
' * GitHub: {repo} \n' + ' * GitHub: {repo} \n' +
' * Copyright (c) {year} {author}; Licensed {license}\n' + ' * Copyright (c) {year} {author}; Licensed {license}\n' +
' */\n\n').format({ ' */\n\n'),
BANNER_OPTONS = {
title: pkg.title || pkg.name, title: pkg.title || pkg.name,
version: pkg.version, version: pkg.version,
date: today.format('YYYY-MM-DD'), date: today.format('YYYY-MM-DD'),
...@@ -49,8 +50,16 @@ var typeSet = ['less', 'js', 'resource'], ...@@ -49,8 +50,16 @@ var typeSet = ['less', 'js', 'resource'],
year: today.format('YYYY'), year: today.format('YYYY'),
author: pkg.author, author: pkg.author,
license: pkg.license license: pkg.license
}), },
statement = '/*! Some code copy from Bootstrap v3.0.0 by @fat and @mdo. (Copyright 2013 Twitter, Inc. Licensed under http://www.apache.org/licenses/)*/\n\n'; BOOTSTRAP_STATEMENT = '/*! Some code copy from Bootstrap v3.0.0 by @fat and @mdo. (Copyright 2013 Twitter, Inc. Licensed under http://www.apache.org/licenses/)*/\n\n';
function formatBanner(options) {
if(options && options.title) {
options.title = BANNER_OPTONS.title + ': ' + options.title;
}
options = Object.assign({}, BANNER_OPTONS, options);
return BANNER.format(options);
}
function tryStatSync(path) { function tryStatSync(path) {
try { try {
...@@ -216,11 +225,12 @@ function buildBundle(name, callback, type) { ...@@ -216,11 +225,12 @@ function buildBundle(name, callback, type) {
build = { build = {
title: buildLib.name, title: buildLib.name,
dest: 'dist/lib/' + name + '/', dest: 'dist/lib/' + name + '/',
filename: name, filename: (buildLib.source && buildLib.source !== 'Bootstrap') ? name : ('zui.' + name),
includes: [name], includes: [name],
thirdpart: buildLib.thirdpart, source: buildLib.source,
settingDpds: ['setting'], settingDpds: (buildLib.src && buildLib.src.less && buildLib.src.less.length) ? ['setting'] : null,
ignoreBasic: true ignoreBasic: true,
ignoreDpds: buildLib.ignoreDpds !== undefined ? buildLib.ignoreDpds : true
}; };
} else { } else {
console.log((' Cannot found the build config: ' + name).red); console.log((' Cannot found the build config: ' + name).red);
...@@ -231,14 +241,11 @@ function buildBundle(name, callback, type) { ...@@ -231,14 +241,11 @@ function buildBundle(name, callback, type) {
console.log((' === BUILD BUNDLES ' + name.toUpperCase() + ' [' + build.bundles.join(', ') + '] ===').blue.bold); console.log((' === BUILD BUNDLES ' + name.toUpperCase() + ' [' + build.bundles.join(', ') + '] ===').blue.bold);
var bundlesTaskList = []; var bundlesTaskList = [];
build.bundles.forEach(function(bundleName) { build.bundles.forEach(function(bundleName) {
var bundleBuild = builds[bundleName]; gulp.task('build:' + bundleName, function(cb) {
if(bundleBuild) { buildBundle(bundleName, cb, type);
gulp.task('build:' + bundleName, function(cb) { });
buildBundle(bundleName, cb, type);
});
bundlesTaskList.push('build:' + bundleName); bundlesTaskList.push('build:' + bundleName);
}
}); });
gulp.task('build:' + name + ':bundles', function(cb) { gulp.task('build:' + name + ':bundles', function(cb) {
...@@ -261,9 +268,10 @@ function buildBundle(name, callback, type) { ...@@ -261,9 +268,10 @@ function buildBundle(name, callback, type) {
console.log((' --- build ' + name + ' ---').cyan.bold); console.log((' --- build ' + name + ' ---').cyan.bold);
var banner = formatBanner({title: build.title || name});
var source = getBuildSource(build), var source = getBuildSource(build),
bannerContent = build.thirdpart ? bannerContent = (build.source && build.source !== 'Bootstrap') ?
'' : banner + (build.bootstrapStatement ? statement : ''); '' : banner + (build.bootstrapStatement ? BOOTSTRAP_STATEMENT : '');
if(source.js && source.js.length && (!type || type === 'js')) { if(source.js && source.js.length && (!type || type === 'js')) {
console.log((' + Ready to process ' + source.js.length + ' javascript files.').bold); console.log((' + Ready to process ' + source.js.length + ' javascript files.').bold);
...@@ -285,11 +293,10 @@ function buildBundle(name, callback, type) { ...@@ -285,11 +293,10 @@ function buildBundle(name, callback, type) {
console.log(' js > '.yellow.bold + (destPath + build.filename + '.js').italic.underline); console.log(' js > '.yellow.bold + (destPath + build.filename + '.js').italic.underline);
}) })
//.pipe(sourcemaps.init()) //.pipe(sourcemaps.init())
.pipe(uglify()) .pipe(uglify({preserveComments: 'some'}))
.pipe(rename({ .pipe(rename({
suffix: '.min' suffix: '.min'
})) }))
.pipe(header(bannerContent))
//.pipe(sourcemaps.write()) //.pipe(sourcemaps.write())
.pipe(gulp.dest(destPath)) .pipe(gulp.dest(destPath))
.on('end', function() { .on('end', function() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册