UNPKG

causeway-standard-theme

Version:

431 lines (413 loc) 16.3 kB
"use strict"; let gulp = require('gulp'), concat = require('gulp-concat'), fs = require('fs'), copy = require('gulp-copy'), connect = require('gulp-connect'), uglify = require('gulp-uglify'), rename = require('gulp-rename'), clean = require('gulp-clean'), less = require('gulp-less'), sourcemaps = require('gulp-sourcemaps'), open = require('gulp-open'), watch = require('gulp-watch'), gutil = require('gulp-util'), banner = require('gulp-banner'), cleanCSS = require('gulp-clean-css'), injectPartials = require('gulp-inject-partials'), gulpSequence = require('gulp-sequence'), zip = require('gulp-zip'), bump = require('gulp-bump'); let pkg = JSON.parse(fs.readFileSync('./package.json')), config = { banner: ` /*! ********************************************************************************************* * ${pkg.name} v${pkg.version} * Copyright 1998-${new Date().getFullYear()} ${pkg.company}. * Author: ${pkg.author} ********************************************************************************************* */ `, bootstrap_banner: ` /*! * ${pkg.bootstrap.name} v${pkg.bootstrap.version} (${pkg.bootstrap.url}) * Copyright 2011-${new Date().getFullYear()} Twitter, Inc. * ${pkg.bootstrap.license} */ `, jquery_banner: ` /*! * ${pkg.jquery.name} v${pkg.jquery.version} * ${pkg.jquery.url} * * ${pkg.jquery.includes.sizzle.name} * ${pkg.jquery.includes.sizzle.url} * * ${pkg.jquery.copyright} * ${pkg.jquery.license.type} * ${pkg.jquery.license.url} * * ${pkg.jquery.date} */ `, bootstrap_file_name: `${pkg.bootstrap.name.toLowerCase()}`, cs_js_path: `./causeway/js/components`, cs_js_responsive_path: `./causeway/js/responsive`, cs_js_vendors_path: `./causeway/js/vendors`, cs_img_path: `./causeway/images`, cs_dist_path: `./dist`, cs_bower_path: `./bower_components` }; // Concat jQuery JS files gulp.task('jquery_js', function() { return gulp.src([`${config.cs_bower_path}/jquery/dist/jquery.js`]) .pipe(concat('jquery.js')) .pipe(gulp.dest(`${config.cs_dist_path}/js/`)) .pipe(connect.reload()); }); //Concat Bootstrap JS files gulp.task('bootstrap_js', function() { return gulp.src([ `${config.cs_bower_path}/bootstrap/js/transition.js`, `${config.cs_bower_path}/bootstrap/js/alert.js`, `${config.cs_bower_path}/bootstrap/js/button.js`, `${config.cs_bower_path}/bootstrap/js/carousel.js`, `${config.cs_bower_path}/bootstrap/js/collapse.js`, `${config.cs_bower_path}/bootstrap/js/dropdown.js`, `${config.cs_bower_path}/bootstrap/js/modal.js`, `${config.cs_bower_path}/bootstrap/js/tooltip.js`, `${config.cs_bower_path}/bootstrap/js/popover.js`, `${config.cs_bower_path}/bootstrap/js/scrollspy.js`, `${config.cs_bower_path}/bootstrap/js/tab.js`, `${config.cs_bower_path}/bootstrap/js/affix.j`, ]) .pipe(sourcemaps.init()) .pipe(concat(`${config.bootstrap_file_name}.js`)) .pipe(banner(config.bootstrap_banner)) .pipe(sourcemaps.write('../maps')) .pipe(gulp.dest(`${config.cs_dist_path}/js/`)) .pipe(connect.reload()); }); // Concat Causeway Utils JS files gulp.task('causeway_utils_js', function() { return gulp.src([ `${config.cs_bower_path}/bootstrap-datepicker/dist/js/bootstrap-datepicker.js`, `${config.cs_bower_path}/bootstrap-duallistbox/dist/jquery.bootstrap-duallistbox.js`, `${config.cs_bower_path}/bootstrap-select/dist/js/bootstrap-select.js`, `${config.cs_bower_path}/bootstrap-spinedit/js/bootstrap-spinedit.js`, `${config.cs_js_vendors_path}/bootstrap-timepicker-gh-pages/js/bootstrap-timepicker.js`, `${config.cs_js_vendors_path}/jquery.jqtree/tree.jquery.js`, `${config.cs_js_vendors_path}/jquery.tablesorter/jquery.tablesorter.js`, `${config.cs_js_vendors_path}/jquery.treegrid/jquery.treegrid.js`, `${config.cs_js_vendors_path}/jquery-simple-color-master/jquery.simple-color.js`, `${config.cs_js_vendors_path}/jquery.placeholder.js`, `${config.cs_bower_path}/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js`, `${config.cs_js_vendors_path}/jquery.fixedtable/jquery.fixedTblHdrLftCol-min.js`, `${config.cs_js_vendors_path}/tableHeadFixer.js` ]) .pipe(concat('causeway-utils.js')) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/js/`)) .pipe(connect.reload()); }); // Concat Causeway Utils CSS files gulp.task('causeway_utils_css', function() { return gulp.src([ `${config.cs_bower_path}/bootstrap-select/dist/css/bootstrap-select.css`, `${config.cs_bower_path}/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css`, `${config.cs_js_vendors_path}/bootstrap-timepicker-gh-pages/css/bootstrap-timepicker.css`, `${config.cs_js_vendors_path}/jquery.treegrid/jquery.treegrid.css`, `${config.cs_bower_path}/bootstrap-spinedit/css/bootstrap-spinedit.css`, `${config.cs_bower_path}/bootstrap-duallistbox/dist/bootstrap-duallistbox.css`, `${config.cs_js_vendors_path}/jquery.jqtree/jqtree.css`, 'causeway/causeway-utils.less' ]) .pipe(concat('causeway-utils.css')) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/css/`)) .pipe(connect.reload()); }); // Concat Causeway JS files gulp.task('causeway_js', function() { return gulp.src([ `${config.cs_js_path}/global.js`, `${config.cs_js_path}/causeway.js`, `${config.cs_js_path}/left-shell-navigation.js`, `${config.cs_js_path}/lightbox.js`, `${config.cs_js_path}/tables.js`, `${config.cs_js_path}/tree-list.js`, `${config.cs_js_path}/tree-view.js`, `${config.cs_js_path}/wizard.js`, `${config.cs_js_path}/init-post-dynamic.js` ]) .pipe(concat('causeway.js')) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/js/`)) .pipe(connect.reload()); }); //Concat Responsive JS files gulp.task('responsive_js', function() { return gulp.src([ `${config.cs_js_responsive_path}/*.js` ]) .pipe(concat('responsive.js')) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/js/`)) .pipe(connect.reload()); }); // Concat Docs JS files gulp.task('docs_js', function() { return gulp.src('causeway/docs/js/docs.js') .pipe(concat('docs.js')) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/docs/js/`)) .pipe(connect.reload()); }); gulp.task('docs_js_compress', ['docs_js'], function() { return gulp.src([`${config.cs_dist_path}/docs/js/*.js`]) .pipe(uglify()) .pipe(rename({ suffix: '.min' })) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/docs/js/`)) }); // Less gulp.task('bootstrap_less', function() { return gulp.src('./causeway/override/bootstrap.less') .pipe(sourcemaps.init()) .pipe(less('bootstrap.css').on('error', gutil.log)) .pipe(banner(config.bootstrap_banner)) .pipe(sourcemaps.write('../maps')) .pipe(gulp.dest(`${config.cs_dist_path}/css/`)) .pipe(connect.reload()); }); gulp.task('causeway_less', function() { return gulp.src('./causeway/causeway-standard.less') .pipe(sourcemaps.init()) .pipe(less('causeway-standard.css').on('error', gutil.log)) .pipe(banner(config.banner)) .pipe(sourcemaps.write('../maps')) .pipe(gulp.dest(`${config.cs_dist_path}/css/`)) .pipe(connect.reload()); }); gulp.task('causeway_print_less', function() { return gulp.src('./causeway/causeway-print.less') .pipe(sourcemaps.init()) .pipe(less('causeway-print.css').on('error', gutil.log)) .pipe(banner(config.banner)) .pipe(sourcemaps.write('../maps')) .pipe(gulp.dest(`${config.cs_dist_path}/css/`)) .pipe(connect.reload()); }); gulp.task('causeway_docs_less', function() { return gulp.src('./causeway/docs/less/docs.less') .pipe(sourcemaps.init()) .pipe(less('docs.css').on('error', gutil.log)) .pipe(banner(config.banner)) .pipe(sourcemaps.write('../maps')) .pipe(gulp.dest(`${config.cs_dist_path}/docs/css/`)) .pipe(connect.reload()); }); gulp.task('causeway_docs_less_compress', ['causeway_docs_less'], function() { return gulp.src(`${config.cs_dist_path}/docs/css/*.css`) .pipe(cleanCSS({level: {1: {specialComments: 0}}})) .pipe(rename({ suffix: '.min' })) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/docs/css/`)) }); // Copy gulp.task('fonts_copy', function() { return gulp.src([`${config.cs_bower_path}/bootstrap/fonts/**/*`, `${config.cs_bower_path}/font-awesome/fonts/**/*`, './causeway/fonts/**/*']) .pipe(gulp.dest(`${config.cs_dist_path}/fonts`)) .pipe(connect.reload()); }); gulp.task('images_copy', function() { return gulp.src([`${config.cs_img_path}/**/*`]) .pipe(gulp.dest(`${config.cs_dist_path}/images`)) .pipe(connect.reload()); }); gulp.task('fav_copy', function() { return gulp.src([`./causeway/favicon/*`]) .pipe(gulp.dest(`${config.cs_dist_path}/`)) .pipe(connect.reload()); }); gulp.task('package_copy', function() { return gulp.src('./package.json') .pipe(gulp.dest(`${config.cs_dist_path}`)) .pipe(connect.reload()); }); // Bake html gulp.task('bake_index', function() { return gulp.src('causeway/index.html') .pipe(injectPartials({ start: "<!--(bake {{path}}", end: ")-->", removeTags: true })) .pipe(gulp.dest(`${config.cs_dist_path}`)) .pipe(connect.reload()); }); gulp.task('bake_docs', function() { return gulp.src([ "causeway/docs/index.html", "causeway/docs/misc.html", "causeway/docs/shells.html", "causeway/docs/content.html", "causeway/docs/icons.html", "causeway/docs/double-pane.html", "causeway/docs/components.html", "causeway/docs/buttons.html", "causeway/docs/forms.html", "causeway/docs/select.html", "causeway/docs/date.html", "causeway/docs/menus.html", "causeway/docs/table.html", "causeway/docs/pagination.html", "causeway/docs/wizard.html", "causeway/docs/print.html", "causeway/docs/login.html", "causeway/docs/login_new.html", "causeway/docs/color-palette.html", "causeway/docs/login_demo.html", "causeway/docs/login_demo2.html", "causeway/docs/login-screen.html", "causeway/docs/login_v1.0.6-0.html", "causeway/docs/left-navigation.html", "causeway/docs/breadcrumb.html", "causeway/docs/treeview.html", "causeway/docs/treegrid.html", "causeway/docs/treelist.html", "causeway/docs/treesearchlist.html", "causeway/docs/site-notification.html", "causeway/docs/status-indicator.html", "causeway/docs/twopane-horizontal.html", "causeway/docs/left-navigation-rightpane.html", "causeway/docs/twopane-vertical.html", "causeway/docs/accordion.html" ]) .pipe(injectPartials({ start: "<!--(bake {{path}}", end: ")-->", removeTags: true })) .pipe(gulp.dest(`${config.cs_dist_path}/docs`)) .pipe(connect.reload()); }); // Compress JS gulp.task('compress_js', ['jquery_js', 'bootstrap_js', 'causeway_utils_js', 'causeway_js', 'responsive_js', 'docs_js_compress'], function() { return gulp.src([`${config.cs_dist_path}/js/*.js`]) .pipe(uglify()) .pipe(rename({ suffix: '.min' })) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/js/`)) }); // Compress CSS gulp.task('compress_css',['bootstrap_less', 'causeway_less', 'causeway_print_less', 'causeway_docs_less_compress', 'causeway_utils_css' ], function() { return gulp.src(`${config.cs_dist_path}/css/*.css`) .pipe(cleanCSS({level: {1: {specialComments: 0}}})) .pipe(rename({ suffix: '.min' })) .pipe(banner(config.banner)) .pipe(gulp.dest(`${config.cs_dist_path}/css/`)) }); gulp.task('compress', ['compress_js', 'compress_css']); // Clean gulp.task('clean', function () { return gulp.src(['dist/css', 'dist/docs', 'dist/fonts', 'dist/images', 'dist/js', 'dist/maps', 'dist/index.html', 'dist/package.json', 'dist/*.png', 'dist/*.ico', 'dist/manifest.json' ], { read: false }) .pipe(clean()); }); // Build gulp.task('build', gulpSequence('clean', 'compress', ['fonts_copy', 'images_copy', 'fav_copy', 'package_copy'], 'bake_index', 'bake_docs')); // Zip gulp.task('zip', function() { return gulp.src([ 'dist/**/*', '!dist/downloads/**', '!dist/application-bar/**', '!dist/archive/**', '!dist/release-notes/**', '!dist/package.json' ]) .pipe(zip(`CausewayCSS.dist.v${pkg.version}.zip`)) .pipe(gulp.dest(`${config.cs_dist_path}/downloads`)) }); // Bump gulp.task('bump', function(){ gulp.src(['./bower.json', './package.json']) .pipe(bump()) .pipe(gulp.dest('./')); }); // Watch for changes gulp.task('watch', function () { gulp.watch([`${config.cs_bower_path}/jquery/dist/jquery.js`], ['jquery_js']); gulp.watch([ `${config.cs_bower_path}/bootstrap/js/transition.js`, `${config.cs_bower_path}/bootstrap/js/alert.js`, `${config.cs_bower_path}/bootstrap/js/button.js`, `${config.cs_bower_path}/bootstrap/js/carousel.js`, `${config.cs_bower_path}/bootstrap/js/collapse.js`, `${config.cs_bower_path}/bootstrap/js/dropdown.js`, `${config.cs_bower_path}/bootstrap/js/modal.js`, `${config.cs_bower_path}/bootstrap/js/tooltip.js`, `${config.cs_bower_path}/bootstrap/js/popover.js`, `${config.cs_bower_path}/bootstrap/js/scrollspy.js`, `${config.cs_bower_path}/bootstrap/js/tab.js`, `${config.cs_bower_path}/bootstrap/js/affix.j`, ], ['bootstrap_js']); gulp.watch([ `${config.cs_bower_path}/bootstrap-datepicker/dist/js/bootstrap-datepicker.js`, `${config.cs_bower_path}/bootstrap-duallistbox/dist/jquery.bootstrap-duallistbox.js`, `${config.cs_bower_path}/bootstrap-select/dist/js/bootstrap-select.js`, `${config.cs_bower_path}/bootstrap-spinedit/js/bootstrap-spinedit.js`, `${config.cs_js_vendors_path}/bootstrap-timepicker-gh-pages/js/bootstrap-timepicker.js`, `${config.cs_js_vendors_path}/jquery.jqtree/tree.jquery.js`, `${config.cs_js_vendors_path}/jquery.scrollbar/jquery.scrollbar.js`, `${config.cs_js_vendors_path}/jquery.tablesorter/jquery.tablesorter.js`, `${config.cs_js_vendors_path}/jquery.treegrid/jquery.treegrid.js`, `${config.cs_js_vendors_path}/jquery-simple-color-master/jquery.simple-color.js`, `${config.cs_js_vendors_path}/jquery.placeholder.js`, `${config.cs_bower_path}/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js`, `${config.cs_js_vendors_path}/jquery.fixedtable/jquery.fixedTblHdrLftCol-min.js`, `${config.cs_js_vendors_path}/tableHeadFixer.js` ], ['causeway_utils_js']); gulp.watch([ `${config.cs_js_path}/global.js`, `${config.cs_js_path}/causeway.js`, `${config.cs_js_path}/left-shell-navigation.js`, `${config.cs_js_path}/lightbox.js`, `${config.cs_js_path}/tables.js`, `${config.cs_js_path}/tree-list.js`, `${config.cs_js_path}/tree-view.js`, `${config.cs_js_path}/wizard.js` ], ['causeway_js']); gulp.watch([ `${config.cs_js_responsive_path}/*.js` ], ['responsive_js']); gulp.watch(['causeway/docs/js/docs.js'], ['docs_js']); gulp.watch(['./causeway/override/*.less'], ['bootstrap_less']); gulp.watch(['./causeway/components/*.less', './causeway/components/**/*.less', './causeway/utilities/*.less', './causeway/layouts/*.less'], ['causeway_less']); gulp.watch(['./causeway/causeway-print.less'], ['causeway_print_less']); gulp.watch(['./causeway/docs/less/*.less'], ['causeway_docs_less']); gulp.watch([`${config.cs_bower_path}/bootstrap/fonts/**/*`, `${config.cs_bower_path}/font-awesome/fonts/**/*`, './causeway/fonts/**/*'], ['fonts_copy']); gulp.watch([`${config.cs_img_path}/**/*`], ['images_copy']); gulp.watch(['./package.json'], ['package_copy']); gulp.watch(['./causeway/index.html'], ['bake_index']); gulp.watch(['./causeway/docs/**/*.html'], ['bake_docs']); }); // Serve to lite server gulp.task('connect', function () { connect.server({ livereload: true, root: 'dist', port: 9000 }) }); // Open gulp.task('open', function(){ gulp.src('./dist/index.html') .pipe(open({uri: 'http://localhost:9000', app: 'google chrome'})); }); // Start gulp.task('default', gulpSequence('build', 'connect', 'open', 'watch'));