material-design-lite/gulpfile.js

365 lines
9.5 KiB
JavaScript
Raw Normal View History

/**
*
2015-02-16 06:06:43 -08:00
* Material Design Lite
2015-01-06 05:36:47 -08:00
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
2014-10-22 06:14:09 -07:00
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*
*/
2014-04-17 05:02:38 -07:00
'use strict';
2014-06-19 05:14:21 -07:00
// Include Gulp & Tools We'll Use
2014-04-17 05:02:38 -07:00
var gulp = require('gulp');
2014-06-07 10:38:49 -07:00
var $ = require('gulp-load-plugins')();
var del = require('del');
2014-06-18 18:37:49 -07:00
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
2015-01-29 07:26:23 -08:00
var fs = require('fs');
var path = require('path');
2015-02-04 02:14:57 -08:00
var pkg = require('./package.json');
2015-04-01 04:54:06 -07:00
var through = require('through2');
var swig = require('swig');
2015-02-04 02:14:57 -08:00
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license.type %>',
2015-02-04 02:14:57 -08:00
' */',
''].join('\n');
var AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
2014-04-17 05:02:38 -07:00
2015-04-01 04:54:06 -07:00
// ***** Development tasks ****** //
2014-06-19 05:14:21 -07:00
// Lint JavaScript
2015-02-04 02:14:57 -08:00
gulp.task('jshint', function () {
return gulp.src('src/**/*.js')
.pipe(reload({stream: true, once: true}))
2015-02-10 05:20:01 -08:00
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
2014-06-19 05:14:21 -07:00
});
2015-04-01 04:54:06 -07:00
// ***** Production build tasks ****** //
2014-06-19 05:14:21 -07:00
// Optimize Images
2015-02-04 02:14:57 -08:00
// TODO: Update image paths in final CSS to match root/images
gulp.task('images', function () {
return gulp.src('src/**/*.{svg,png,jpg}')
2015-02-24 01:11:04 -08:00
.pipe($.flatten())
2014-06-20 08:20:44 -07:00
.pipe($.cache($.imagemin({
progressive: true,
interlaced: true
})))
2015-02-04 02:14:57 -08:00
.pipe(gulp.dest('./images'))
2014-06-20 08:20:44 -07:00
.pipe($.size({title: 'images'}));
2014-06-19 05:14:21 -07:00
});
// Copy fonts
gulp.task('fonts', function () {
return gulp.src([
'fonts/*'
]).pipe(gulp.dest('.tmp/fonts'));
});
2015-02-04 02:14:57 -08:00
// Compile and Automatically Prefix Stylesheets (dev)
gulp.task('styles:dev', ['fonts'], function () {
2015-02-04 02:14:57 -08:00
return gulp.src([
2015-03-20 08:36:16 -07:00
'src/**/*.scss'
2015-02-04 02:14:57 -08:00
])
.pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
}))
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
2015-02-05 04:39:43 -08:00
.pipe(gulp.dest('.tmp/styles'))
2015-02-04 02:14:57 -08:00
.pipe($.size({title: 'styles'}));
2014-07-08 07:53:00 -07:00
});
// Compile and Automatically Prefix Stylesheet Templates (production)
gulp.task('styletemplates', function () {
// For best performance, don't add Sass partials to `gulp.src`
return gulp.src([
'src/template.scss'
])
// Generate Source Maps
.pipe ($.sourcemaps.init())
.pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
}))
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(gulp.dest('.tmp'))
// Concatenate Styles
.pipe($.concat('material.css.template'))
.pipe($.header(banner, {pkg: pkg}))
.pipe(gulp.dest('./css'))
// Minify Styles
.pipe($.if('*.css.template', $.csso()))
.pipe($.concat('material.min.css.template'))
2015-04-08 12:02:29 -07:00
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./css'))
.pipe($.size({title: 'styles'}));
});
2015-02-04 02:14:57 -08:00
// Compile and Automatically Prefix Stylesheets (production)
gulp.task('styles', ['styletemplates'], function () {
// For best performance, don't add Sass partials to `gulp.src`
return gulp.src([
2015-02-04 02:14:57 -08:00
'src/styleguide.scss'
])
2015-02-24 06:21:47 -08:00
// Generate Source Maps
.pipe ($.sourcemaps.init())
2014-11-25 03:22:05 -08:00
.pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
}))
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
2014-09-03 03:47:19 -07:00
.pipe(gulp.dest('.tmp'))
2015-02-04 02:14:57 -08:00
// Concatenate Styles
.pipe($.concat('material.css'))
.pipe($.header(banner, {pkg: pkg}))
.pipe(gulp.dest('./css'))
// Minify Styles
.pipe($.if('*.css', $.csso()))
2015-02-04 02:14:57 -08:00
.pipe($.concat('material.min.css'))
//.pipe($.header(banner, {pkg: pkg}))
2015-02-24 06:21:47 -08:00
.pipe($.sourcemaps.write('./'))
2015-02-04 02:14:57 -08:00
.pipe(gulp.dest('./css'))
.pipe($.size({title: 'styles'}));
2014-06-18 18:37:49 -07:00
});
2014-06-18 12:58:06 -07:00
// Concatenate And Minify JavaScript
2015-02-04 02:14:57 -08:00
gulp.task('scripts', function () {
var sources = [
// Component handler
2015-02-04 02:14:57 -08:00
'src/wskComponentHandler.js',
// Polyfills/dependencies
2015-02-04 02:14:57 -08:00
'src/third_party/**/*.js',
// Base components
2015-02-04 02:14:57 -08:00
'src/animation/animation.js',
'src/button/button.js',
'src/checkbox/checkbox.js',
'src/column-layout/column-layout.js',
'src/icon-toggle/icon-toggle.js',
'src/menu/menu.js',
Implement progress bar component (closes #88) commit b8cb14ab0a511b806a65102f8f032fd40bf361bc Author: Alexander Surma <surma@surmair.de> Date: Wed Apr 1 12:16:57 2015 +0100 Invert CSS hack logic commit f58bf29ee4d376c97d9b673e76ac421eb0b2efae Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 15:43:28 2015 +0100 Use feature detection commit 095789e2bb09fcc3b2cfc66f7e9bf768a9e9f8cb Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 15:34:31 2015 +0100 Revert "Add browser detection" This reverts commit 82f6c28162d1f68de3dbdaf42f0975122305a8bf. commit 71d3f147da903d3e6fb8315dd1638dc035aa2d2d Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 14:37:17 2015 +0100 Colorize aux bar on IE and FF commit 82f6c28162d1f68de3dbdaf42f0975122305a8bf Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 14:15:43 2015 +0100 Add browser detection commit 06f347bba0d5b1979f07357a460dd7608b3063ad Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 14:01:51 2015 +0100 Externalize SVG again commit cfdc4f276fbe526a0a671601587fc2630129af10 Author: Alexander Surma <surma@surmair.de> Date: Mon Mar 30 15:47:13 2015 +0100 Adhere to styleguide commit cf4c72aebe94a1a59fa4b6e02b0b44888ef3a484 Author: Alexander Surma <surma@surmair.de> Date: Mon Mar 30 12:50:38 2015 +0100 Inline SVG for progress bar commit bc9e77d73462e2466d4685d381dc3bceeadeb12b Author: Alexander Surma <surma@surmair.de> Date: Mon Mar 30 12:46:44 2015 +0100 Add unit tests for progress bar commit 9e70b49480109d248d45737e80e517e04c78d4ac Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 17:48:11 2015 +0000 Speed up buffering animation commit 45e7dd3751e389c69c64ef33b912dda793b3f733 Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 16:15:03 2015 +0000 Add circle svg for buffer bar commit ade9276219db103a11fbcfc3908201a8d21e845c Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 15:24:17 2015 +0000 Fix colors commit ba10830796299571c96357fe8871678b3677046c Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 14:54:27 2015 +0000 Implement indeterminate progress bar commit 71bac12de651337cc3634ded6133372f54bbc6bd Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 14:23:24 2015 +0000 Add support for buffer bar commit 9933563f229d3bb4593110cc84e77a9eb46ae2a9 Author: Alexander Surma <surma@surmair.de> Date: Thu Mar 26 22:26:52 2015 +0000 Implement basic progress bar
2015-04-01 05:35:08 -07:00
'src/progress/progress.js',
2015-02-04 02:14:57 -08:00
'src/radio/radio.js',
'src/slider/slider.js',
'src/spinner/spinner.js',
'src/switch/switch.js',
'src/tabs/tabs.js',
'src/textfield/textfield.js',
'src/tooltip/tooltip.js',
// Complex components (which reuse base components)
2015-02-04 02:14:57 -08:00
'src/layout/layout.js',
// And finally, the ripples
2015-02-04 02:14:57 -08:00
'src/ripple/ripple.js'
];
return gulp.src(sources)
2015-02-04 02:14:57 -08:00
.pipe($.sourcemaps.init())
// Concatenate Scripts
.pipe($.concat('material.js'))
.pipe($.header(banner, {pkg: pkg}))
.pipe(gulp.dest('./js'))
// Minify Scripts
.pipe($.uglify({preserveComments: 'some', sourceRoot: '.', sourceMapIncludeSources: true}))
.pipe($.concat('material.min.js'))
// Write Source Maps
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./js'))
.pipe($.size({title: 'scripts'}));
});
2015-04-01 04:54:06 -07:00
// Clean Output Directory
gulp.task('clean', del.bind(null, ['css/*', 'js/*'], {dot: true}));
// Build Production Files, the Default Task
gulp.task('default', ['clean','mocha'], function (cb) {
runSequence(
'styles',
['jshint', 'scripts', 'images'],
cb);
});
// ***** Testing tasks ***** //
gulp.task('mocha', function () {
2015-02-16 01:15:59 -08:00
return gulp.src('./test/index.html')
.pipe($.mochaPhantomjs({reporter: 'list'}))
});
2015-04-01 04:54:06 -07:00
gulp.task('test', ['jshint', 'mocha']);
2014-04-17 05:02:38 -07:00
2015-04-01 04:54:06 -07:00
gulp.task('test:visual', function() {
browserSync({
2014-06-25 15:14:19 -07:00
notify: false,
2015-04-01 04:54:06 -07:00
server: './',
startPath: 'test/visual/index.html'
2014-06-20 08:20:44 -07:00
});
2014-04-17 05:02:38 -07:00
2015-04-01 04:54:06 -07:00
gulp.watch(['test/visual/**'], reload);
2014-04-17 05:02:38 -07:00
});
2014-06-07 10:38:49 -07:00
2015-04-01 04:54:06 -07:00
// ***** Landing page tasks ***** //
/**
* Site metadata for use with templates.
* @type {Object}
*/
var site = {};
/**
* Compiled swig templates cache.
* @type {Object}
*/
var templates = {};
/**
* Generates an HTML file based on a template and file metadata.
*/
function applyTemplate() {
return through.obj(function(file, enc, cb) {
var data = {
site: site,
page: file.page,
content: file.contents.toString()
};
// If template not in template cache, compile and add it.
if (!templates[file.page.layout]) {
var templateFile = path.join(
__dirname, 'docs', '_templates', file.page.layout + '.html');
$.util.log('Compiling template:', $.util.colors.yellow(file.page.layout));
templates[file.page.layout] = swig.compileFile(templateFile);
}
var tpl = templates[file.page.layout];
file.contents = new Buffer(tpl(data), 'utf8');
this.push(file);
cb();
})
}
/**
* Generates an index.html file for each README in MDL/src directory.
*/
gulp.task('components', function() {
return gulp.src('./src/**/README.md', {base: './src'})
// Add basic front matter.
.pipe($.header('---\nlayout: component\n---\n\n'))
.pipe($.frontMatter({property: 'page', remove: true}))
.pipe($.marked())
.pipe((function () {
var componentPages = [];
return through.obj(function(file, enc, cb) {
file.page.component = file.relative.split('/')[0];
componentPages.push(file.page);
this.push(file);
cb();
},
function(cb) {
site.components = componentPages;
cb();
})
})())
.pipe(applyTemplate())
.pipe($.rename(function (path) {
path.basename = "index";
}))
.pipe(gulp.dest('docs/out/components'));
});
2015-04-01 04:54:06 -07:00
/**
* Copies demo files from MDL/src directory.
*/
gulp.task('demos', function () {
return gulp.src([
'./src/**/demo.*',
'./src/**/*.js'
], {base: './src'})
.pipe($.if('*.scss', $.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
})))
.pipe($.if('*.css', $.autoprefixer(AUTOPREFIXER_BROWSERS)))
.pipe(gulp.dest('docs/out/components'));
2014-06-07 10:38:49 -07:00
});
2015-02-16 01:15:59 -08:00
2015-03-23 08:56:23 -07:00
2015-04-01 04:54:06 -07:00
/**
* Generates an HTML file for each md file in _pages directory.
*/
gulp.task('pages', ['components'], function() {
return gulp.src(['docs/_pages/*.md'])
.pipe($.frontMatter({property: 'page', remove: true}))
.pipe($.marked())
.pipe(applyTemplate())
.pipe($.rename(function(path) {
if (path.basename !== 'index') {
path.dirname = path.basename;
path.basename = 'index';
}
}))
.pipe(gulp.dest('docs/out'));
});
/**
* Copies assets from MDL and _assets directory.
*/
gulp.task('assets', function () {
return gulp.src(['docs/_assets/**'])
.pipe(gulp.dest('docs/out/assets'));
});
/**
* Serves the landing page from "out" directory.
*/
gulp.task('serve', ['assets', 'pages', 'demos'], function () {
2015-03-23 08:56:23 -07:00
browserSync({
notify: false,
2015-04-01 04:54:06 -07:00
server: {
baseDir: ['docs/out', 'js', 'css', 'fonts'],
routes: {
'/fonts': 'fonts',
'/components/fonts': 'fonts'
}
}
2015-03-23 08:56:23 -07:00
});
2015-04-08 12:02:29 -07:00
gulp.watch(['src/**/*.js', '!src/**/README.md'], ['demos', 'images', reload]);
2015-04-01 04:54:06 -07:00
gulp.watch(['src/**/*.js'], ['scripts', reload]);
2015-04-08 12:02:29 -07:00
gulp.watch(['src/**/*.{scss,css}'], ['styles', reload]);
2015-04-01 04:54:06 -07:00
gulp.watch(['src/**/README.md'], ['components', reload]);
2015-03-23 08:56:23 -07:00
});