2014-06-09 17:02:39 +04:00
|
|
|
/**
|
|
|
|
*
|
2015-02-16 17:06:43 +03:00
|
|
|
* Material Design Lite
|
2015-01-06 16:36:47 +03:00
|
|
|
* Copyright 2015 Google Inc. All rights reserved.
|
2014-06-09 17:02:39 +04:00
|
|
|
*
|
2014-06-09 12:56:26 +04:00
|
|
|
* 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-06-09 17:02:39 +04:00
|
|
|
*
|
2014-10-22 17:14:09 +04:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2014-06-09 17:02:39 +04:00
|
|
|
*
|
2014-06-09 12:56:26 +04:00
|
|
|
* 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-06-09 17:02:39 +04:00
|
|
|
*
|
2014-06-09 12:56:26 +04:00
|
|
|
*/
|
2014-06-09 17:02:39 +04:00
|
|
|
|
2014-04-17 16:02:38 +04:00
|
|
|
'use strict';
|
2014-06-19 16:14:21 +04:00
|
|
|
|
|
|
|
// Include Gulp & Tools We'll Use
|
2015-10-01 17:19:43 +03:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import merge from 'merge-stream';
|
|
|
|
import del from 'del';
|
|
|
|
import vinylPaths from'vinyl-paths';
|
|
|
|
import runSequence from 'run-sequence';
|
|
|
|
import browserSync from 'browser-sync';
|
|
|
|
import through from 'through2';
|
|
|
|
import swig from 'swig';
|
|
|
|
import gulp from 'gulp';
|
|
|
|
import closureCompiler from 'gulp-closure-compiler';
|
|
|
|
import gulpLoadPlugins from 'gulp-load-plugins';
|
|
|
|
import uniffe from './utils/uniffe.js';
|
|
|
|
import pkg from './package.json';
|
|
|
|
|
|
|
|
const $ = gulpLoadPlugins();
|
|
|
|
const reload = browserSync.reload;
|
|
|
|
const hostedLibsUrlPrefix = 'https://storage.googleapis.com/code.getmdl.io';
|
|
|
|
const templateArchivePrefix = 'mdl-template-';
|
|
|
|
const bucketProd = 'gs://www.getmdl.io';
|
|
|
|
const bucketStaging = 'gs://mdl-staging';
|
|
|
|
const bucketCode = 'gs://code.getmdl.io';
|
|
|
|
const banner = ['/**',
|
2015-02-04 13:14:57 +03:00
|
|
|
' * <%= pkg.name %> - <%= pkg.description %>',
|
|
|
|
' * @version v<%= pkg.version %>',
|
2015-07-07 11:10:39 +03:00
|
|
|
' * @license <%= pkg.license %>',
|
2015-07-05 16:57:40 +03:00
|
|
|
' * @copyright 2015 Google, Inc.',
|
2015-07-07 11:10:39 +03:00
|
|
|
' * @link https://github.com/google/material-design-lite',
|
2015-02-04 13:14:57 +03:00
|
|
|
' */',
|
|
|
|
''].join('\n');
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
let codeFiles = '';
|
|
|
|
|
|
|
|
const AUTOPREFIXER_BROWSERS = [
|
2015-02-04 13:14:57 +03:00
|
|
|
'ie >= 10',
|
|
|
|
'ie_mob >= 10',
|
|
|
|
'ff >= 30',
|
|
|
|
'chrome >= 34',
|
|
|
|
'safari >= 7',
|
|
|
|
'opera >= 23',
|
|
|
|
'ios >= 7',
|
|
|
|
'android >= 4.4',
|
|
|
|
'bb >= 10'
|
|
|
|
];
|
2014-04-17 16:02:38 +04:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
const SOURCES = [
|
2015-09-04 05:26:49 +03:00
|
|
|
// Component handler
|
|
|
|
'src/mdlComponentHandler.js',
|
|
|
|
// Polyfills/dependencies
|
|
|
|
'src/third_party/**/*.js',
|
|
|
|
// Base components
|
|
|
|
'src/button/button.js',
|
|
|
|
'src/checkbox/checkbox.js',
|
|
|
|
'src/icon-toggle/icon-toggle.js',
|
|
|
|
'src/menu/menu.js',
|
|
|
|
'src/progress/progress.js',
|
|
|
|
'src/radio/radio.js',
|
|
|
|
'src/slider/slider.js',
|
2015-09-16 00:35:09 +03:00
|
|
|
'src/snackbar/snackbar.js',
|
2015-09-04 05:26:49 +03:00
|
|
|
'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)
|
|
|
|
'src/layout/layout.js',
|
|
|
|
'src/data-table/data-table.js',
|
|
|
|
// And finally, the ripples
|
|
|
|
'src/ripple/ripple.js'
|
|
|
|
];
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
// ***** Development tasks ****** //
|
|
|
|
|
2014-06-19 16:14:21 +04:00
|
|
|
// Lint JavaScript
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('jshint', () => {
|
|
|
|
return gulp.src(['src/**/*.js', 'gulpfile.js'])
|
2014-06-26 23:32:04 +04:00
|
|
|
.pipe(reload({stream: true, once: true}))
|
2015-02-10 16:20:01 +03:00
|
|
|
.pipe($.jshint())
|
|
|
|
.pipe($.jshint.reporter('jshint-stylish'))
|
|
|
|
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
|
2014-06-19 16:14:21 +04:00
|
|
|
});
|
2014-05-07 13:33:42 +04:00
|
|
|
|
2015-06-15 12:26:18 +03:00
|
|
|
// Lint JavaScript code style
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('jscs', () => {
|
|
|
|
return gulp.src(['src/**/*.js', 'gulpfile.js'])
|
2015-06-15 12:26:18 +03:00
|
|
|
.pipe(reload({stream: true, once: true}))
|
|
|
|
.pipe($.jscs())
|
|
|
|
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
|
|
|
|
});
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
// ***** Production build tasks ****** //
|
|
|
|
|
2014-06-19 16:14:21 +04:00
|
|
|
// Optimize Images
|
2015-02-04 13:14:57 +03:00
|
|
|
// TODO: Update image paths in final CSS to match root/images
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('images', () => {
|
2015-02-04 13:14:57 +03:00
|
|
|
return gulp.src('src/**/*.{svg,png,jpg}')
|
2015-02-24 12:11:04 +03:00
|
|
|
.pipe($.flatten())
|
2014-06-20 19:20:44 +04:00
|
|
|
.pipe($.cache($.imagemin({
|
|
|
|
progressive: true,
|
|
|
|
interlaced: true
|
|
|
|
})))
|
2015-05-06 16:39:10 +03:00
|
|
|
.pipe(gulp.dest('dist/images'))
|
2014-06-20 19:20:44 +04:00
|
|
|
.pipe($.size({title: 'images'}));
|
2014-06-19 16:14:21 +04:00
|
|
|
});
|
|
|
|
|
2015-02-04 13:14:57 +03:00
|
|
|
// Compile and Automatically Prefix Stylesheets (dev)
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('styles:dev', () => {
|
2015-02-04 13:14:57 +03:00
|
|
|
return gulp.src([
|
2015-03-20 18:36:16 +03:00
|
|
|
'src/**/*.scss'
|
2015-02-04 13:14:57 +03:00
|
|
|
])
|
|
|
|
.pipe($.sass({
|
|
|
|
precision: 10,
|
|
|
|
onError: console.error.bind(console, 'Sass error:')
|
|
|
|
}))
|
2015-05-08 05:01:05 +03:00
|
|
|
.pipe($.cssInlineImages({
|
|
|
|
webRoot: 'src'
|
2015-04-16 14:55:04 +03:00
|
|
|
}))
|
2015-02-04 13:14:57 +03:00
|
|
|
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
|
2015-02-05 15:39:43 +03:00
|
|
|
.pipe(gulp.dest('.tmp/styles'))
|
2015-02-04 13:14:57 +03:00
|
|
|
.pipe($.size({title: 'styles'}));
|
2014-07-08 18:53:00 +04:00
|
|
|
});
|
|
|
|
|
2015-03-18 21:31:44 +03:00
|
|
|
// Compile and Automatically Prefix Stylesheet Templates (production)
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('styletemplates', () => {
|
2015-03-18 21:31:44 +03:00
|
|
|
// For best performance, don't add Sass partials to `gulp.src`
|
|
|
|
return gulp.src([
|
|
|
|
'src/template.scss'
|
|
|
|
])
|
|
|
|
// Generate Source Maps
|
2015-08-06 14:39:04 +03:00
|
|
|
.pipe($.sourcemaps.init())
|
2015-03-18 21:31:44 +03:00
|
|
|
.pipe($.sass({
|
|
|
|
precision: 10,
|
|
|
|
onError: console.error.bind(console, 'Sass error:')
|
|
|
|
}))
|
2015-05-08 05:01:05 +03:00
|
|
|
.pipe($.cssInlineImages({
|
|
|
|
webRoot: 'src'
|
2015-04-16 14:55:04 +03:00
|
|
|
}))
|
2015-03-18 21:31:44 +03:00
|
|
|
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
|
|
|
|
.pipe(gulp.dest('.tmp'))
|
|
|
|
// Concatenate Styles
|
|
|
|
.pipe($.concat('material.css.template'))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('dist'))
|
2015-03-18 21:31:44 +03:00
|
|
|
// Minify Styles
|
2015-03-19 15:47:21 +03:00
|
|
|
.pipe($.if('*.css.template', $.csso()))
|
2015-03-18 21:31:44 +03:00
|
|
|
.pipe($.concat('material.min.css.template'))
|
2015-06-13 01:55:41 +03:00
|
|
|
.pipe($.header(banner, {pkg: pkg}))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.sourcemaps.write('.'))
|
|
|
|
.pipe(gulp.dest('dist'))
|
2015-03-18 21:31:44 +03:00
|
|
|
.pipe($.size({title: 'styles'}));
|
|
|
|
});
|
|
|
|
|
2015-02-04 13:14:57 +03:00
|
|
|
// Compile and Automatically Prefix Stylesheets (production)
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('styles', () => {
|
2014-07-30 03:25:19 +04:00
|
|
|
// For best performance, don't add Sass partials to `gulp.src`
|
|
|
|
return gulp.src([
|
2015-08-12 13:49:25 +03:00
|
|
|
'src/material-design-lite.scss'
|
2014-10-14 19:19:35 +04:00
|
|
|
])
|
2015-02-24 17:21:47 +03:00
|
|
|
// Generate Source Maps
|
2015-08-06 14:39:04 +03:00
|
|
|
.pipe($.sourcemaps.init())
|
2014-11-25 14:22:05 +03:00
|
|
|
.pipe($.sass({
|
2015-01-07 16:50:02 +03:00
|
|
|
precision: 10,
|
|
|
|
onError: console.error.bind(console, 'Sass error:')
|
|
|
|
}))
|
2015-05-08 05:01:05 +03:00
|
|
|
.pipe($.cssInlineImages({
|
|
|
|
webRoot: 'src'
|
2015-04-16 14:55:04 +03:00
|
|
|
}))
|
2014-07-04 15:35:14 +04:00
|
|
|
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
|
2014-09-03 14:47:19 +04:00
|
|
|
.pipe(gulp.dest('.tmp'))
|
2015-02-04 13:14:57 +03:00
|
|
|
// Concatenate Styles
|
|
|
|
.pipe($.concat('material.css'))
|
|
|
|
.pipe($.header(banner, {pkg: pkg}))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('dist'))
|
2015-02-04 13:14:57 +03:00
|
|
|
// Minify Styles
|
2014-08-28 20:13:09 +04:00
|
|
|
.pipe($.if('*.css', $.csso()))
|
2015-02-04 13:14:57 +03:00
|
|
|
.pipe($.concat('material.min.css'))
|
2015-06-13 01:55:41 +03:00
|
|
|
.pipe($.header(banner, {pkg: pkg}))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.sourcemaps.write('.'))
|
|
|
|
.pipe(gulp.dest('dist'))
|
2014-07-30 03:25:19 +04:00
|
|
|
.pipe($.size({title: 'styles'}));
|
2014-06-19 05:37:49 +04:00
|
|
|
});
|
2014-06-18 23:58:06 +04:00
|
|
|
|
2015-06-15 19:24:52 +03:00
|
|
|
// Only generate CSS styles for the MDL grid
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('styles-grid', () => {
|
2015-06-15 19:24:52 +03:00
|
|
|
return gulp.src(['src/material-design-lite-grid.scss'])
|
|
|
|
.pipe($.sass({
|
|
|
|
precision: 10,
|
|
|
|
onError: console.error.bind(console, 'Sass error:')
|
|
|
|
}))
|
|
|
|
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
|
|
|
|
.pipe(gulp.dest('.tmp'))
|
|
|
|
// Concatenate Styles
|
|
|
|
.pipe($.concat('material-grid.css'))
|
|
|
|
.pipe($.header(banner, {pkg: pkg}))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('dist'))
|
2015-06-15 19:24:52 +03:00
|
|
|
// Minify Styles
|
|
|
|
.pipe($.if('*.css', $.csso()))
|
|
|
|
.pipe($.concat('material-grid.min.css'))
|
|
|
|
.pipe($.header(banner, {pkg: pkg}))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('dist'))
|
2015-06-15 19:24:52 +03:00
|
|
|
.pipe($.size({title: 'styles-grid'}));
|
|
|
|
});
|
|
|
|
|
2015-09-04 05:26:49 +03:00
|
|
|
// Build with Google's Closure Compiler, requires Java 1.7+ installed.
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('closure', () => {
|
2015-09-04 05:26:49 +03:00
|
|
|
return gulp.src(SOURCES)
|
|
|
|
.pipe(closureCompiler({
|
|
|
|
compilerPath: 'node_modules/google-closure-compiler/compiler.jar',
|
2015-09-10 02:02:29 +03:00
|
|
|
fileName: 'material.closure.min.js',
|
2015-09-04 05:26:49 +03:00
|
|
|
compilerFlags: {
|
|
|
|
// jscs:disable closureCamelCase
|
|
|
|
compilation_level: 'ADVANCED_OPTIMIZATIONS',
|
|
|
|
language_in: 'ECMASCRIPT6_STRICT',
|
|
|
|
language_out: 'ECMASCRIPT5_STRICT',
|
|
|
|
warning_level: 'VERBOSE'
|
|
|
|
// jscs:enable closureCamelCase
|
|
|
|
}
|
2015-09-10 02:02:29 +03:00
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./dist'));
|
2015-09-04 05:26:49 +03:00
|
|
|
});
|
|
|
|
|
2014-11-12 19:43:46 +03:00
|
|
|
// Concatenate And Minify JavaScript
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('scripts', ['jscs', 'jshint'], () => {
|
2015-09-04 05:26:49 +03:00
|
|
|
return gulp.src(SOURCES)
|
2015-09-08 16:24:09 +03:00
|
|
|
.pipe($.if(/mdlComponentHandler\.js/, $.util.noop(), uniffe()))
|
2015-02-04 13:14:57 +03:00
|
|
|
.pipe($.sourcemaps.init())
|
|
|
|
// Concatenate Scripts
|
|
|
|
.pipe($.concat('material.js'))
|
2015-08-06 14:39:20 +03:00
|
|
|
.pipe($.iife({
|
2015-10-01 17:19:43 +03:00
|
|
|
useStrict: true
|
2015-08-06 14:39:20 +03:00
|
|
|
}))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('dist'))
|
2015-02-04 13:14:57 +03:00
|
|
|
// Minify Scripts
|
2015-06-30 19:44:52 +03:00
|
|
|
.pipe($.uglify({
|
|
|
|
sourceRoot: '.',
|
|
|
|
sourceMapIncludeSources: true
|
|
|
|
}))
|
|
|
|
.pipe($.header(banner, {pkg: pkg}))
|
2015-02-04 13:14:57 +03:00
|
|
|
.pipe($.concat('material.min.js'))
|
|
|
|
// Write Source Maps
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.sourcemaps.write('.'))
|
|
|
|
.pipe(gulp.dest('dist'))
|
2014-11-12 19:43:46 +03:00
|
|
|
.pipe($.size({title: 'scripts'}));
|
|
|
|
});
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
// Clean Output Directory
|
2015-10-02 17:07:10 +03:00
|
|
|
gulp.task('clean', () => del(['dist', '.publish']));
|
2015-04-01 14:54:06 +03:00
|
|
|
|
2015-07-05 14:04:15 +03:00
|
|
|
// Copy package manger and LICENSE files to dist
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('metadata', () => {
|
2015-07-05 14:04:15 +03:00
|
|
|
return gulp.src(['package.json', 'bower.json', 'LICENSE'])
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('dist'));
|
2015-07-05 14:04:15 +03:00
|
|
|
});
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
// Build Production Files, the Default Task
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('default', ['clean'], cb => {
|
2015-04-01 14:54:06 +03:00
|
|
|
runSequence(
|
2015-07-21 14:57:50 +03:00
|
|
|
['styles', 'styles-grid'],
|
|
|
|
['scripts'],
|
2015-09-11 15:37:45 +03:00
|
|
|
['mocha'],
|
2015-07-21 14:57:50 +03:00
|
|
|
cb);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build production files and microsite
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('all', ['clean'], cb => {
|
2015-07-21 14:57:50 +03:00
|
|
|
runSequence(
|
2015-07-31 14:10:51 +03:00
|
|
|
['default', 'styletemplates'],
|
|
|
|
['styles:gen'],
|
2015-10-01 17:19:43 +03:00
|
|
|
['jshint', 'jscs', 'scripts', 'assets', 'demos', 'pages',
|
2015-07-05 14:04:15 +03:00
|
|
|
'templates', 'images', 'styles-grid', 'metadata'],
|
2015-09-11 15:37:45 +03:00
|
|
|
['mocha'],
|
2015-07-21 14:57:50 +03:00
|
|
|
['zip'],
|
2015-04-01 14:54:06 +03:00
|
|
|
cb);
|
|
|
|
});
|
|
|
|
|
|
|
|
// ***** Testing tasks ***** //
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('mocha', ['styles'], () => {
|
|
|
|
return gulp.src('test/index.html')
|
2015-06-24 13:30:48 +03:00
|
|
|
.pipe($.mochaPhantomjs({reporter: 'tap'}));
|
2015-02-10 16:19:18 +03:00
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('mocha:closure', ['closure'], () => {
|
|
|
|
return gulp.src('test/index.html')
|
2015-09-11 15:37:45 +03:00
|
|
|
.pipe($.replace('src="../dist/material.js"',
|
|
|
|
'src="../dist/material.closure.min.js"'))
|
|
|
|
.pipe($.rename('temp.html'))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest('test'))
|
2015-09-11 15:37:45 +03:00
|
|
|
.pipe($.mochaPhantomjs({reporter: 'tap'}))
|
2015-10-02 17:07:10 +03:00
|
|
|
.on('finish', () => del.sync('test/temp.html'))
|
|
|
|
.on('error', () => del.sync('test/temp.html'));
|
2015-09-11 15:37:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('test', ['jshint', 'jscs', 'mocha', 'mocha:closure']);
|
2014-04-17 16:02:38 +04:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('test:visual', () => {
|
2014-06-26 11:10:04 +04:00
|
|
|
browserSync({
|
2014-06-26 02:14:19 +04:00
|
|
|
notify: false,
|
2015-10-01 17:19:43 +03:00
|
|
|
server: '.',
|
2015-04-01 14:54:06 +03:00
|
|
|
startPath: 'test/visual/index.html'
|
2014-06-20 19:20:44 +04:00
|
|
|
});
|
2014-04-17 16:02:38 +04:00
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
gulp.watch(['test/visual/**'], reload);
|
2014-04-17 16:02:38 +04:00
|
|
|
});
|
2014-06-07 21:38:49 +04:00
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
// ***** Landing page tasks ***** //
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Site metadata for use with templates.
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
const site = {};
|
2015-04-01 14:54:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates an HTML file based on a template and file metadata.
|
|
|
|
*/
|
|
|
|
function applyTemplate() {
|
2015-10-01 17:19:43 +03:00
|
|
|
return through.obj((file, enc, cb) => {
|
|
|
|
const data = {
|
2015-04-01 14:54:06 +03:00
|
|
|
site: site,
|
|
|
|
page: file.page,
|
|
|
|
content: file.contents.toString()
|
|
|
|
};
|
2015-04-29 13:00:31 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
const templateFile = path.join(
|
|
|
|
__dirname, 'docs', '_templates', `${file.page.layout}.html`);
|
|
|
|
const tpl = swig.compileFile(templateFile, {cache: false});
|
|
|
|
|
|
|
|
file.contents = new Buffer(tpl(data));
|
|
|
|
cb(null, file);
|
2015-06-01 17:20:14 +03:00
|
|
|
});
|
2015-04-01 14:54:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates an index.html file for each README in MDL/src directory.
|
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('components', ['demos'], () => {
|
|
|
|
return gulp.src(['src/**/README.md'], {base: 'src'})
|
2015-04-01 14:54:06 +03:00
|
|
|
// Add basic front matter.
|
2015-06-02 16:59:21 +03:00
|
|
|
.pipe($.header('---\nlayout: component\nbodyclass: component\ninclude_prefix: ../../\n---\n\n'))
|
2015-04-01 14:54:06 +03:00
|
|
|
.pipe($.frontMatter({property: 'page', remove: true}))
|
|
|
|
.pipe($.marked())
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe((() => {
|
|
|
|
return through.obj((file, enc, cb) => {
|
2015-04-01 14:54:06 +03:00
|
|
|
file.page.component = file.relative.split('/')[0];
|
2015-10-01 17:19:43 +03:00
|
|
|
cb(null, file);
|
2015-06-01 17:20:14 +03:00
|
|
|
});
|
2015-04-01 14:54:06 +03:00
|
|
|
})())
|
|
|
|
.pipe(applyTemplate())
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.rename(path => path.basename = 'index'))
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist/components'));
|
2014-07-01 00:18:52 +04:00
|
|
|
});
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
/**
|
|
|
|
* Copies demo files from MDL/src directory.
|
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('demoresources', () => {
|
2015-06-01 15:30:17 +03:00
|
|
|
return gulp.src([
|
2015-10-01 17:19:43 +03:00
|
|
|
'src/**/demos.css',
|
|
|
|
'src/**/demo.css',
|
|
|
|
'src/**/demo.js'
|
|
|
|
], {base: 'src'})
|
2015-04-01 14:54:06 +03:00
|
|
|
.pipe($.if('*.scss', $.sass({
|
|
|
|
precision: 10,
|
|
|
|
onError: console.error.bind(console, 'Sass error:')
|
|
|
|
})))
|
2015-05-08 05:01:05 +03:00
|
|
|
.pipe($.cssInlineImages({
|
|
|
|
webRoot: 'src'
|
2015-04-16 14:55:04 +03:00
|
|
|
}))
|
2015-04-01 14:54:06 +03:00
|
|
|
.pipe($.if('*.css', $.autoprefixer(AUTOPREFIXER_BROWSERS)))
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist/components'));
|
2014-06-07 21:38:49 +04:00
|
|
|
});
|
2015-02-16 12:15:59 +03:00
|
|
|
|
2015-06-11 18:02:19 +03:00
|
|
|
/**
|
2015-06-23 19:22:22 +03:00
|
|
|
* Generates demo files for testing made of all the snippets and the demo file
|
|
|
|
* put together.
|
2015-06-11 18:02:19 +03:00
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('demos', ['demoresources'], () => {
|
2015-09-04 15:45:36 +03:00
|
|
|
/**
|
|
|
|
* Retrieves the list of component folders.
|
|
|
|
*/
|
2015-06-23 19:22:22 +03:00
|
|
|
function getComponentFolders() {
|
2015-10-01 17:19:43 +03:00
|
|
|
return fs.readdirSync('src')
|
|
|
|
.filter(file => fs.statSync(path.join('src', file)).isDirectory());
|
2015-06-23 19:22:22 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
const tasks = getComponentFolders().map(component => {
|
2015-06-23 19:22:22 +03:00
|
|
|
return gulp.src([
|
2015-10-01 17:19:43 +03:00
|
|
|
path.join('src', component, 'snippets', '*.html'),
|
|
|
|
path.join('src', component, 'demo.html')
|
2015-06-23 19:22:22 +03:00
|
|
|
])
|
|
|
|
.pipe($.concat('/demo.html'))
|
|
|
|
// Add basic front matter.
|
|
|
|
.pipe($.header('---\nlayout: demo\nbodyclass: demo\ninclude_prefix: ../../\n---\n\n'))
|
|
|
|
.pipe($.frontMatter({property: 'page', remove: true}))
|
|
|
|
.pipe($.marked())
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe((() => {
|
|
|
|
return through.obj((file, enc, cb) => {
|
2015-06-23 19:22:22 +03:00
|
|
|
file.page.component = component;
|
2015-10-01 17:19:43 +03:00
|
|
|
cb(null, file);
|
2015-06-23 19:22:22 +03:00
|
|
|
});
|
|
|
|
})())
|
|
|
|
.pipe(applyTemplate())
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe(gulp.dest(path.join('dist', 'components', component)));
|
2015-06-23 19:22:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return merge(tasks);
|
2015-06-11 18:02:19 +03:00
|
|
|
});
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
/**
|
|
|
|
* Generates an HTML file for each md file in _pages directory.
|
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('pages', ['components'], () => {
|
2015-04-01 14:54:06 +03:00
|
|
|
return gulp.src(['docs/_pages/*.md'])
|
|
|
|
.pipe($.frontMatter({property: 'page', remove: true}))
|
|
|
|
.pipe($.marked())
|
|
|
|
.pipe(applyTemplate())
|
2015-06-16 16:33:52 +03:00
|
|
|
.pipe($.replace('$$version$$', pkg.version))
|
2015-06-24 17:57:57 +03:00
|
|
|
.pipe($.replace('$$hosted_libs_prefix$$', hostedLibsUrlPrefix))
|
2015-08-17 22:22:05 +03:00
|
|
|
.pipe($.replace('$$template_archive_prefix$$', templateArchivePrefix))
|
2015-06-11 16:43:36 +03:00
|
|
|
/* Replacing code blocks class name to match Prism's. */
|
2015-06-15 19:36:58 +03:00
|
|
|
.pipe($.replace('class="lang-', 'class="language-'))
|
2015-06-11 16:43:36 +03:00
|
|
|
/* Translate html code blocks to "markup" because that's what Prism uses. */
|
2015-06-15 19:36:58 +03:00
|
|
|
.pipe($.replace('class="language-html', 'class="language-markup'))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.rename(path => {
|
2015-04-01 14:54:06 +03:00
|
|
|
if (path.basename !== 'index') {
|
|
|
|
path.dirname = path.basename;
|
|
|
|
path.basename = 'index';
|
|
|
|
}
|
|
|
|
}))
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist'));
|
2015-04-01 14:54:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies assets from MDL and _assets directory.
|
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('assets', () => {
|
2015-06-23 19:22:22 +03:00
|
|
|
return gulp.src([
|
|
|
|
'docs/_assets/**/*',
|
|
|
|
'node_modules/clippy/build/clippy.swf',
|
2015-07-02 18:28:27 +03:00
|
|
|
'node_modules/swfobject-npm/swfobject/src/swfobject.js',
|
|
|
|
'node_modules/prismjs/prism.js',
|
|
|
|
'node_modules/prismjs/components/prism-markup.min.js',
|
2015-07-03 15:09:44 +03:00
|
|
|
'node_modules/prismjs/components/prism-javascript.min.js',
|
|
|
|
'node_modules/prismjs/components/prism-css.min.js',
|
2015-07-06 15:58:46 +03:00
|
|
|
'node_modules/prismjs/components/prism-bash.min.js',
|
2015-07-02 18:28:27 +03:00
|
|
|
'node_modules/prismjs/dist/prism-default/prism-default.css'
|
2015-06-23 19:22:22 +03:00
|
|
|
])
|
2015-06-25 02:11:14 +03:00
|
|
|
.pipe($.if(/\.js/i, $.replace('$$version$$', pkg.version)))
|
|
|
|
.pipe($.if(/\.js/i, $.replace('$$hosted_libs_prefix$$', hostedLibsUrlPrefix)))
|
2015-04-29 13:00:31 +03:00
|
|
|
.pipe($.if(/\.(svg|jpg|png)$/i, $.imagemin({
|
|
|
|
progressive: true,
|
|
|
|
interlaced: true
|
|
|
|
})))
|
2015-06-03 02:01:04 +03:00
|
|
|
.pipe($.if(/\.css/i, $.autoprefixer(AUTOPREFIXER_BROWSERS)))
|
2015-07-02 22:31:50 +03:00
|
|
|
.pipe($.if(/\.css/i, $.csso()))
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.if(/\.js/i, $.uglify({
|
|
|
|
preserveComments: 'some',
|
|
|
|
sourceRoot: '.',
|
|
|
|
sourceMapIncludeSources: true
|
|
|
|
})))
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist/assets'));
|
2015-04-01 14:54:06 +03:00
|
|
|
});
|
|
|
|
|
2015-09-04 15:45:36 +03:00
|
|
|
/**
|
|
|
|
* Defines the list of resources to watch for changes.
|
|
|
|
*/
|
2015-07-22 18:24:59 +03:00
|
|
|
function watch() {
|
|
|
|
gulp.watch(['src/**/*.js', '!src/**/README.md'],
|
|
|
|
['scripts', 'demos', 'components', reload]);
|
|
|
|
gulp.watch(['src/**/*.{scss,css}'],
|
|
|
|
['styles', 'styles-grid', 'styletemplates', reload]);
|
|
|
|
gulp.watch(['src/**/*.html'], ['pages', reload]);
|
|
|
|
gulp.watch(['src/**/*.{svg,png,jpg}'], ['images', reload]);
|
|
|
|
gulp.watch(['src/**/README.md'], ['pages', reload]);
|
|
|
|
gulp.watch(['templates/**/*'], ['templates', reload]);
|
|
|
|
gulp.watch(['docs/**/*'], ['pages', 'assets', reload]);
|
|
|
|
gulp.watch(['package.json', 'bower.json', 'LICENSE'], ['metadata']);
|
|
|
|
}
|
|
|
|
|
2015-04-01 14:54:06 +03:00
|
|
|
/**
|
|
|
|
* Serves the landing page from "out" directory.
|
|
|
|
*/
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('serve:browsersync', () => {
|
2015-03-23 18:56:23 +03:00
|
|
|
browserSync({
|
|
|
|
notify: false,
|
2015-04-01 14:54:06 +03:00
|
|
|
server: {
|
2015-06-01 17:15:55 +03:00
|
|
|
baseDir: ['dist']
|
2015-04-01 14:54:06 +03:00
|
|
|
}
|
2015-03-23 18:56:23 +03:00
|
|
|
});
|
|
|
|
|
2015-07-22 18:24:59 +03:00
|
|
|
watch();
|
2015-03-23 18:56:23 +03:00
|
|
|
});
|
2015-04-15 17:13:10 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('serve', () => {
|
2015-06-04 23:59:06 +03:00
|
|
|
$.connect.server({
|
|
|
|
root: 'dist',
|
2015-06-05 20:07:09 +03:00
|
|
|
port: 5000,
|
2015-06-04 23:59:06 +03:00
|
|
|
livereload: true
|
|
|
|
});
|
|
|
|
|
2015-07-22 18:24:59 +03:00
|
|
|
watch();
|
2015-06-05 20:07:09 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.src('dist/index.html')
|
2015-06-05 20:07:09 +03:00
|
|
|
.pipe($.open('', {url: 'http://localhost:5000'}));
|
2015-06-04 23:59:06 +03:00
|
|
|
});
|
|
|
|
|
2015-06-29 20:54:20 +03:00
|
|
|
// Generate release archive containing just JS, CSS, Source Map deps
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('zip:mdl', () => {
|
2015-07-06 14:03:35 +03:00
|
|
|
return gulp.src(['dist/material?(.min)@(.js|.css)?(.map)', 'LICENSE', 'bower.json', 'package.json'])
|
2015-06-29 20:54:20 +03:00
|
|
|
.pipe($.zip('mdl.zip'))
|
|
|
|
.pipe(gulp.dest('dist'));
|
|
|
|
});
|
|
|
|
|
2015-09-07 13:12:59 +03:00
|
|
|
/**
|
|
|
|
* Returns the list of children directories inside the given directory.
|
|
|
|
* @param {string} dir the parent directory
|
2015-09-07 13:50:59 +03:00
|
|
|
* @return {Array<string>} list of child directories
|
2015-09-07 13:12:59 +03:00
|
|
|
*/
|
2015-08-17 22:22:05 +03:00
|
|
|
function getSubDirectories(dir) {
|
|
|
|
return fs.readdirSync(dir)
|
2015-10-01 17:19:43 +03:00
|
|
|
.filter(file => fs.statSync(path.join(dir, file)).isDirectory());
|
2015-08-17 22:22:05 +03:00
|
|
|
}
|
2015-06-30 16:02:35 +03:00
|
|
|
|
2015-08-17 22:22:05 +03:00
|
|
|
// Generate release archives containing the templates and assets for templates.
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('zip:templates', () => {
|
|
|
|
const templates = getSubDirectories('dist/templates');
|
2015-06-30 16:02:35 +03:00
|
|
|
|
2015-08-17 22:22:05 +03:00
|
|
|
// Generate a zip file for each template.
|
2015-10-01 17:19:43 +03:00
|
|
|
const generateZips = templates.map(template => {
|
2015-08-17 22:22:05 +03:00
|
|
|
return gulp.src(['dist/templates/' + template + '/**/*.*', 'LICENSE'])
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.rename(path => {
|
2015-08-17 22:22:05 +03:00
|
|
|
path.dirname = path.dirname.replace('dist/templates/' + template, '');
|
|
|
|
}))
|
|
|
|
.pipe($.zip(templateArchivePrefix + template + '.zip'))
|
|
|
|
.pipe(gulp.dest('dist'));
|
|
|
|
});
|
2015-06-30 16:02:35 +03:00
|
|
|
|
2015-08-17 22:22:05 +03:00
|
|
|
return merge(generateZips);
|
2015-06-29 20:54:20 +03:00
|
|
|
});
|
|
|
|
|
2015-07-21 16:05:50 +03:00
|
|
|
gulp.task('zip', ['zip:templates', 'zip:mdl']);
|
2015-07-21 14:57:50 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('genCodeFiles', () => {
|
2015-08-17 22:22:05 +03:00
|
|
|
return gulp.src(['dist/material.*@(js|css)?(.map)', 'dist/mdl.zip', 'dist/' + templateArchivePrefix + '*.zip'],
|
2015-07-05 21:17:45 +03:00
|
|
|
{read: false})
|
2015-10-01 17:19:43 +03:00
|
|
|
.pipe($.tap(file => {
|
2015-07-05 21:17:45 +03:00
|
|
|
codeFiles += ' dist/' + path.basename(file.path);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2015-06-24 20:07:33 +03:00
|
|
|
// Push the latest version of code resources (CSS+JS) to Google Cloud Storage.
|
2015-06-19 16:28:48 +03:00
|
|
|
// Public-read objects in GCS are served by a Google provided and supported
|
|
|
|
// global, high performance caching/content delivery network (CDN) service.
|
2015-06-12 18:50:10 +03:00
|
|
|
// This task requires gsutil to be installed and configured.
|
2015-06-19 16:28:48 +03:00
|
|
|
// For info on gsutil: https://cloud.google.com/storage/docs/gsutil.
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('pushCodeFiles', () => {
|
|
|
|
const dest = bucketCode;
|
2015-07-06 16:24:25 +03:00
|
|
|
process.stdout.write('Publishing ' + pkg.version + ' to CDN (' + dest + ')\n');
|
|
|
|
|
|
|
|
// Build cache control and gsutil cmd to copy
|
2015-06-19 16:28:48 +03:00
|
|
|
// each object into a GCS bucket. The dest is a version specific path.
|
|
|
|
// The gsutil -m option requests parallel copies.
|
2015-06-24 20:07:33 +03:00
|
|
|
// The gsutil -h option is used to set metadata headers
|
|
|
|
// (cache control, in this case).
|
2015-09-28 15:58:36 +03:00
|
|
|
// Code files should NEVER be touched after uploading, therefore
|
|
|
|
// 30 days caching is a safe value.
|
2015-10-01 17:19:43 +03:00
|
|
|
const cacheControl = '-h "Cache-Control:public,max-age=2592000"';
|
|
|
|
const gsutilCpCmd = 'gsutil -m cp -z js,css,map ';
|
|
|
|
const gsutilCacheCmd = 'gsutil -m setmeta -R ' + cacheControl;
|
2015-06-19 16:28:48 +03:00
|
|
|
|
2015-06-24 20:07:33 +03:00
|
|
|
// Upload the goodies to a separate GCS bucket with versioning.
|
|
|
|
// Using a sep bucket avoids the risk of accidentally blowing away
|
|
|
|
// old versions in the microsite bucket.
|
2015-07-06 14:03:35 +03:00
|
|
|
return gulp.src('')
|
2015-06-19 16:28:48 +03:00
|
|
|
.pipe($.shell([
|
2015-07-05 21:17:45 +03:00
|
|
|
gsutilCpCmd + codeFiles + ' ' + dest + '/' + pkg.version,
|
|
|
|
gsutilCacheCmd + ' ' + dest + '/' + pkg.version
|
2015-06-19 16:28:48 +03:00
|
|
|
]));
|
2015-06-12 18:50:10 +03:00
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('publish:code', cb => {
|
2015-07-05 21:17:45 +03:00
|
|
|
runSequence(
|
2015-07-06 13:55:11 +03:00
|
|
|
['zip:mdl', 'zip:templates'],
|
2015-07-05 21:17:45 +03:00
|
|
|
'genCodeFiles',
|
|
|
|
'pushCodeFiles',
|
|
|
|
cb);
|
|
|
|
});
|
|
|
|
|
2015-09-04 15:45:36 +03:00
|
|
|
/**
|
|
|
|
* Function to publish staging or prod version from local tree,
|
|
|
|
* or to promote staging to prod, per passed arg.
|
|
|
|
* @param {string} pubScope the scope to publish to.
|
|
|
|
*/
|
2015-06-25 13:34:00 +03:00
|
|
|
function mdlPublish(pubScope) {
|
2015-10-01 17:19:43 +03:00
|
|
|
let cacheTtl = null;
|
|
|
|
let src = null;
|
|
|
|
let dest = null;
|
2015-06-25 13:34:00 +03:00
|
|
|
if (pubScope === 'staging') {
|
2015-06-24 15:40:47 +03:00
|
|
|
// Set staging specific vars here.
|
2015-06-25 13:34:00 +03:00
|
|
|
cacheTtl = 0;
|
2015-07-06 16:24:25 +03:00
|
|
|
src = 'dist/*';
|
2015-06-25 13:34:00 +03:00
|
|
|
dest = bucketStaging;
|
|
|
|
} else if (pubScope === 'prod') {
|
2015-06-24 15:40:47 +03:00
|
|
|
// Set prod specific vars here.
|
2015-07-05 22:25:22 +03:00
|
|
|
cacheTtl = 60;
|
2015-07-06 16:24:25 +03:00
|
|
|
src = 'dist/*';
|
2015-06-25 13:34:00 +03:00
|
|
|
dest = bucketProd;
|
|
|
|
} else if (pubScope === 'promote') {
|
2015-06-24 15:40:47 +03:00
|
|
|
// Set promote (essentially prod) specific vars here.
|
2015-07-05 22:25:22 +03:00
|
|
|
cacheTtl = 60;
|
2015-06-25 13:34:00 +03:00
|
|
|
src = bucketStaging + '/*';
|
|
|
|
dest = bucketProd;
|
2015-04-15 17:13:10 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
let infoMsg = 'Publishing ' + pubScope + '/' + pkg.version + ' to GCS (' + dest + ')';
|
2015-06-24 15:40:47 +03:00
|
|
|
if (src) {
|
2015-06-25 13:34:00 +03:00
|
|
|
infoMsg += ' from ' + src;
|
2015-06-24 15:40:47 +03:00
|
|
|
}
|
2015-07-06 16:24:25 +03:00
|
|
|
process.stdout.write(infoMsg + '\n');
|
2015-06-19 16:28:48 +03:00
|
|
|
|
2015-07-06 16:24:25 +03:00
|
|
|
// Build gsutil commands:
|
|
|
|
// The gsutil -h option is used to set metadata headers.
|
2015-06-19 16:28:48 +03:00
|
|
|
// The gsutil -m option requests parallel copies.
|
2015-07-01 15:55:47 +03:00
|
|
|
// The gsutil -R option is used for recursive file copy.
|
2015-10-01 17:19:43 +03:00
|
|
|
const cacheControl = '-h "Cache-Control:public,max-age=' + cacheTtl + '"';
|
|
|
|
const gsutilCacheCmd = 'gsutil -m setmeta ' + cacheControl + ' ' + dest + '/**';
|
|
|
|
const gsutilCpCmd = 'gsutil -m cp -r -z html,css,js,svg ' + src + ' ' + dest;
|
2015-06-19 16:28:48 +03:00
|
|
|
|
2015-07-06 16:24:25 +03:00
|
|
|
gulp.src('').pipe($.shell([gsutilCpCmd, gsutilCacheCmd]));
|
2015-06-24 15:40:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push the local build of the MDL microsite and release artifacts to the
|
|
|
|
// production Google Cloud Storage bucket for general serving to the web.
|
|
|
|
// Public-read objects in GCS are served by a Google provided and supported
|
|
|
|
// global, high performance caching/content delivery network (CDN) service.
|
|
|
|
// This task requires gsutil to be installed and configured.
|
|
|
|
// For info on gsutil: https://cloud.google.com/storage/docs/gsutil.
|
|
|
|
//
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('publish:prod', () => {
|
2015-06-25 13:34:00 +03:00
|
|
|
mdlPublish('prod');
|
2015-06-24 15:40:47 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Promote the staging version of the MDL microsite and release artifacts
|
|
|
|
// to the production Google Cloud Storage bucket for general serving.
|
|
|
|
// Public-read objects in GCS are served by a Google provided and supported
|
|
|
|
// global, high performance caching/content delivery network (CDN) service.
|
|
|
|
// This task requires gsutil to be installed and configured.
|
|
|
|
// For info on gsutil: https://cloud.google.com/storage/docs/gsutil.
|
|
|
|
//
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('publish:promote', () => {
|
2015-06-25 13:34:00 +03:00
|
|
|
mdlPublish('promote');
|
2015-06-24 15:40:47 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Push the staged version of the MDL microsite and release artifacts
|
|
|
|
// to a production Google Cloud Storage bucket for staging and pre-production testing.
|
|
|
|
//
|
|
|
|
// This task requires gsutil to be installed and configured.
|
|
|
|
// For info on gsutil: https://cloud.google.com/storage/docs/gsutil.
|
|
|
|
//
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('publish:staging', () => {
|
2015-06-25 13:34:00 +03:00
|
|
|
mdlPublish('staging');
|
2015-06-19 16:28:48 +03:00
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('_release', () => {
|
2015-07-21 16:05:50 +03:00
|
|
|
return gulp.src(['dist/material?(.min)@(.js|.css)?(.map)', 'LICENSE',
|
2015-08-19 17:47:22 +03:00
|
|
|
'README.md', 'bower.json', 'package.json', '.jscsrc', '.jshintrc',
|
|
|
|
'./sr?/**/*', 'gulpfile.js', './util?/**/*'])
|
2015-07-21 16:05:50 +03:00
|
|
|
.pipe(gulp.dest('_release'));
|
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('publish:release', ['_release'], () => {
|
2015-07-21 16:05:50 +03:00
|
|
|
return gulp.src('_release')
|
|
|
|
.pipe($.subtree({
|
|
|
|
remote: 'origin',
|
|
|
|
branch: 'release'
|
|
|
|
}))
|
|
|
|
.pipe(vinylPaths(del));
|
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('templates:styles', () => {
|
2015-05-13 17:59:31 +03:00
|
|
|
return gulp.src([
|
|
|
|
'templates/**/*.css'
|
|
|
|
])
|
|
|
|
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
|
|
|
|
// FIXME: This crashes. It's a bug in gulp-csso,
|
|
|
|
// not csso itself.
|
|
|
|
//.pipe($.csso())
|
|
|
|
.pipe(gulp.dest('dist/templates'));
|
2015-04-16 13:37:38 +03:00
|
|
|
});
|
2015-04-15 19:09:28 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('templates:static', () => {
|
2015-04-16 13:37:38 +03:00
|
|
|
return gulp.src([
|
2015-10-01 17:19:43 +03:00
|
|
|
'templates/**/*.html'
|
2015-04-16 13:37:38 +03:00
|
|
|
])
|
2015-08-17 22:22:05 +03:00
|
|
|
.pipe($.replace('$$version$$', pkg.version))
|
|
|
|
.pipe($.replace('$$hosted_libs_prefix$$', hostedLibsUrlPrefix))
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist/templates'));
|
2015-04-16 13:37:38 +03:00
|
|
|
});
|
|
|
|
|
2015-08-19 18:50:31 +03:00
|
|
|
// This task can be used if you want to test the templates against locally
|
|
|
|
// built version of the MDL libraries.
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('templates:localtestingoverride', () => {
|
2015-08-19 18:50:31 +03:00
|
|
|
return gulp.src([
|
2015-10-01 17:19:43 +03:00
|
|
|
'templates/**/*.html'
|
2015-08-19 18:50:31 +03:00
|
|
|
])
|
|
|
|
.pipe($.replace('$$version$$', '.'))
|
|
|
|
.pipe($.replace('$$hosted_libs_prefix$$', ''))
|
|
|
|
.pipe(gulp.dest('dist/templates'));
|
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('templates:images', () => {
|
2015-04-16 13:37:38 +03:00
|
|
|
return gulp.src([
|
|
|
|
'templates/*/images/**/*'
|
|
|
|
])
|
2015-09-28 14:00:18 +03:00
|
|
|
.pipe($.imagemin({
|
2015-04-16 13:37:38 +03:00
|
|
|
progressive: true,
|
|
|
|
interlaced: true
|
2015-09-28 14:00:18 +03:00
|
|
|
}))
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist/templates'));
|
2015-04-16 13:37:38 +03:00
|
|
|
});
|
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('templates:fonts', () => {
|
2015-04-16 14:20:01 +03:00
|
|
|
return gulp.src([
|
2015-06-16 17:41:51 +03:00
|
|
|
'templates/*/fonts/**/*'
|
|
|
|
])
|
2015-05-06 16:25:08 +03:00
|
|
|
.pipe(gulp.dest('dist/templates/'));
|
2015-06-01 17:20:14 +03:00
|
|
|
});
|
2015-04-16 14:20:01 +03:00
|
|
|
|
2015-08-17 22:22:05 +03:00
|
|
|
gulp.task('templates', ['templates:static', 'templates:images',
|
2015-06-16 17:41:51 +03:00
|
|
|
'templates:fonts', 'templates:styles']);
|
2015-07-01 16:40:42 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
gulp.task('styles:gen', ['styles'], () => {
|
|
|
|
const MaterialCustomizer = require('./docs/_assets/customizer.js');
|
|
|
|
const templatePath = path.join(__dirname, 'dist', 'material.min.css.template');
|
2015-07-01 16:40:42 +03:00
|
|
|
// TODO: This task needs refactoring once we turn MaterialCustomizer
|
|
|
|
// into a proper Node module.
|
2015-10-01 17:19:43 +03:00
|
|
|
const mc = new MaterialCustomizer();
|
2015-07-28 14:27:50 +03:00
|
|
|
mc.template = fs.readFileSync(templatePath).toString();
|
2015-07-01 16:40:42 +03:00
|
|
|
|
2015-10-01 17:19:43 +03:00
|
|
|
let stream = gulp.src('');
|
|
|
|
mc.paletteIndices.forEach(primary => {
|
|
|
|
mc.paletteIndices.forEach(accent => {
|
2015-07-28 14:44:40 +03:00
|
|
|
if (primary === accent) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-01 16:40:42 +03:00
|
|
|
if (mc.forbiddenAccents.indexOf(accent) !== -1) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-01 17:19:43 +03:00
|
|
|
const primaryName = primary.toLowerCase().replace(' ', '_');
|
|
|
|
const accentName = accent.toLowerCase().replace(' ', '_');
|
2015-07-01 16:40:42 +03:00
|
|
|
stream = stream.pipe($.file(
|
|
|
|
'material.' + primaryName + '-' + accentName + '.min.css',
|
|
|
|
mc.processTemplate(primary, accent)
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
2015-10-01 17:19:43 +03:00
|
|
|
|
2015-07-01 16:40:42 +03:00
|
|
|
stream.pipe(gulp.dest('dist'));
|
|
|
|
});
|