Поскольку мне еще не раз понадобится заглянуть в gulpfile.babel.js из Material Design Light, то надо иметь под рукой его скомпилированный вариант. Так что здесь сам файл, содержание директории material-design-lite... фрагменты из файла... Templating with Swig and YAML front-matter
Templating with Swig and YAML front-matter
Swig Plugin for Gulp
gulp-data Generate a data object from a variety of sources: json, front-matter, databases, promises, anything... and set it to the file object for other plugins to consume.
The ClosureCompiler.js Gulp Task
Require babel's ES6 modules from node.
With the release of babel@6 the way generated modules work now does NOT set the module.exports property; instead it sets exports.default. Of course this basically breaks everything trying to require() it. So this tiny module is a replacement for require() for node-based runtimes that imports the default if an ES6 module is detected. A necessary evil it seems, given this behavior is not changing: https://github.com/babel/babel/issues/2212.
Global Objects Node.js v6.3.0 Documentation
These objects are available in all modules. Some of these objects aren't actually in the global scope but in the module scope - this will be noted.
The objects listed here are specific to Node.js. There are a number of built-in objects that are part of the JavaScript language itself, which are also globally accessible.
gulp-front-matter Extract YAML Front-Matter
header from files, removes it from contents
and add a new frontMatter
property to file object.
####Вот здесь все установлено
F:\stradorusite\MDL\material-design-lite-1>dir
Том в устройстве F имеет метку MYLINUXLIVE
Серийный номер тома: CE7F-8134
Содержимое папки F:\stradorusite\MDL\material-design-lite-1
03.07.2016 17:57 <DIR> .
03.07.2016 17:57 <DIR> ..
03.07.2016 17:58 3 630 .drone.sec
03.07.2016 17:58 1 343 .drone.yml
03.07.2016 17:58 220 .editorconfig
03.07.2016 17:58 13 .gitattributes
03.07.2016 17:58 86 .gitignore
03.07.2016 17:58 700 .jscsrc
03.07.2016 17:58 299 .jshintrc
03.07.2016 17:58 9 788 CONTRIBUTING.md
03.07.2016 17:58 12 069 LICENSE
03.07.2016 17:58 4 019 README.md
03.07.2016 17:58 584 bower.json
03.07.2016 17:58 <DIR> docs
03.07.2016 21:37 24 729 gulpfile.babel.js
03.07.2016 17:58 2 087 package.json
03.07.2016 17:58 <DIR> src
03.07.2016 17:58 <DIR> templates
03.07.2016 17:58 <DIR> test
03.07.2016 17:58 <DIR> utils
03.07.2016 18:03 <DIR> node_modules
02.06.2016 23:46 135 .babelrc
20.07.2016 13:00 26 377 se1-gulpfile.js
20.07.2016 13:02 <DIR> .tmp
20.07.2016 13:33 <DIR> dist
15 файлов 86 079 байт
10 папок 67 960 832 байт свободно
Вот сюда я начал было копировать фрагменты¶
// ***** Landing page tasks ***** //
/**
* Site metadata for use with templates.
* @type {Object}
*/
var site = {};
/**
* Generates an HTML file based on a template and file metadata.
*/
function applyTemplate() {
return _through2.default.obj(function(file, enc, cb) {
var data = {
site: site,
page: file.page,
content: file.contents.toString()
};
var templateFile = _path2.default.join(
__dirname, 'docs', '_templates', file.page.layout + '.html');
var tpl = _swig2.default.compileFile(templateFile, {
cache: false
});
file.contents = new Buffer(tpl(data));
cb(null, file);
});
}
Но потом решил ограничиться только приложением...
####Приложение F:\stradorusite\MDL\material-design-lite-1\se1-gulpfile.js
/**
*
* Material Design Lite
* 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
*
* 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
*
*/
// jscs:disable jsDoc
'use strict';
// Include Gulp & Tools We'll Use
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _mergeStream = require('merge-stream');
var _mergeStream2 = _interopRequireDefault(_mergeStream);
var _del = require('del');
var _del2 = _interopRequireDefault(_del);
var _vinylPaths = require('vinyl-paths');
var _vinylPaths2 = _interopRequireDefault(_vinylPaths);
var _runSequence = require('run-sequence');
var _runSequence2 = _interopRequireDefault(_runSequence);
var _browserSync = require('browser-sync');
var _browserSync2 = _interopRequireDefault(_browserSync);
var _through = require('through2');
var _through2 = _interopRequireDefault(_through);
var _swig = require('swig');
var _swig2 = _interopRequireDefault(_swig);
var _gulp = require('gulp');
var _gulp2 = _interopRequireDefault(_gulp);
var _gulpClosureCompiler = require('gulp-closure-compiler');
var _gulpClosureCompiler2 = _interopRequireDefault(_gulpClosureCompiler);
var _gulpLoadPlugins = require('gulp-load-plugins');
var _gulpLoadPlugins2 = _interopRequireDefault(_gulpLoadPlugins);
var _uniffe = require('./utils/uniffe.js');
var _uniffe2 = _interopRequireDefault(_uniffe);
var _package = require('./package.json');
var _package2 = _interopRequireDefault(_package);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var $ = (0, _gulpLoadPlugins2.default)();
var reload = _browserSync2.default.reload;
var hostedLibsUrlPrefix = 'https://code.getmdl.io';
var templateArchivePrefix = 'mdl-template-';
var bucketProd = 'gs://www.getmdl.io';
var bucketStaging = 'gs://mdl-staging';
var bucketCode = 'gs://code.getmdl.io';
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @license <%= pkg.license %>',
' * @copyright 2015 Google, Inc.',
' * @link https://github.com/google/material-design-lite',
' */',
''
].join('\n');
var codeFiles = '';
var AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
var SOURCES = [
// 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',
'src/snackbar/snackbar.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)
'src/layout/layout.js',
'src/data-table/data-table.js',
// And finally, the ripples
'src/ripple/ripple.js'
];
// ***** Development tasks ****** //
// Lint JavaScript
_gulp2.default.task('lint', function() {
return _gulp2.default.src([
'src/**/*.js',
'gulpfile.babel.js'
]).
pipe(reload({
stream: true,
once: true
})).
pipe($.jshint()).
pipe($.jscs()).
pipe($.jshint.reporter('jshint-stylish')).
pipe($.jscs.reporter()).
pipe($.if(!_browserSync2.default.active, $.jshint.reporter('fail'))).
pipe($.if(!_browserSync2.default.active, $.jscs.reporter('fail')));
});
// ***** Production build tasks ****** //
// Optimize Images
// TODO: Update image paths in final CSS to match root/images
_gulp2.default.task('images', function() {
return _gulp2.default.src('src/**/*.{svg,png,jpg}').
pipe($.flatten()).
pipe($.cache($.imagemin({
progressive: true,
interlaced: true
}))).
pipe(_gulp2.default.dest('dist/images')).
pipe($.size({
title: 'images'
}));
});
// Compile and Automatically Prefix Stylesheets (dev)
_gulp2.default.task('styles:dev', function() {
return _gulp2.default.src('src/**/*.scss').
pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
})).
pipe($.cssInlineImages({
webRoot: 'src'
})).
pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)).
pipe(_gulp2.default.dest('.tmp/styles')).
pipe($.size({
title: 'styles'
}));
});
// Compile and Automatically Prefix Stylesheet Templates (production)
_gulp2.default.task('styletemplates', function() {
// For best performance, don't add Sass partials to `gulp.src`
return _gulp2.default.src('src/template.scss')
// Generate Source Maps
.pipe($.sourcemaps.init()).
pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
})).
pipe($.cssInlineImages({
webRoot: 'src'
})).
pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)).
pipe(_gulp2.default.dest('.tmp'))
// Concatenate Styles
.pipe($.concat('material.css.template')).
pipe(_gulp2.default.dest('dist'))
// Minify Styles
.pipe($.if('*.css.template', $.csso())).
pipe($.concat('material.min.css.template')).
pipe($.header(banner, {
pkg: _package2.default
})).
pipe($.sourcemaps.write('.')).
pipe(_gulp2.default.dest('dist')).
pipe($.size({
title: 'styles'
}));
});
// Compile and Automatically Prefix Stylesheets (production)
_gulp2.default.task('styles', function() {
// For best performance, don't add Sass partials to `gulp.src`
return _gulp2.default.src('src/material-design-lite.scss')
// Generate Source Maps
.pipe($.sourcemaps.init()).
pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
})).
pipe($.cssInlineImages({
webRoot: 'src'
})).
pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)).
pipe(_gulp2.default.dest('.tmp'))
// Concatenate Styles
.pipe($.concat('material.css')).
pipe($.header(banner, {
pkg: _package2.default
})).
pipe(_gulp2.default.dest('dist'))
// Minify Styles
.pipe($.if('*.css', $.csso())).
pipe($.concat('material.min.css')).
pipe($.header(banner, {
pkg: _package2.default
})).
pipe($.sourcemaps.write('.')).
pipe(_gulp2.default.dest('dist')).
pipe($.size({
title: 'styles'
}));
});
// Only generate CSS styles for the MDL grid
_gulp2.default.task('styles-grid', function() {
return _gulp2.default.src('src/material-design-lite-grid.scss').
pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
})).
pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)).
pipe(_gulp2.default.dest('.tmp'))
// Concatenate Styles
.pipe($.concat('material-grid.css')).
pipe($.header(banner, {
pkg: _package2.default
})).
pipe(_gulp2.default.dest('dist'))
// Minify Styles
.pipe($.if('*.css', $.csso())).
pipe($.concat('material-grid.min.css')).
pipe($.header(banner, {
pkg: _package2.default
})).
pipe(_gulp2.default.dest('dist')).
pipe($.size({
title: 'styles-grid'
}));
});
// Build with Google's Closure Compiler, requires Java 1.7+ installed.
_gulp2.default.task('closure', function() {
return _gulp2.default.src(SOURCES).
pipe((0, _gulpClosureCompiler2.default)({
compilerPath: 'node_modules/google-closure-compiler/compiler.jar',
fileName: 'material.closure.min.js',
compilerFlags: {
// jscs:disable closureCamelCase
compilation_level: 'ADVANCED_OPTIMIZATIONS',
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT5_STRICT',
warning_level: 'VERBOSE'
// jscs:enable closureCamelCase
}
})).
pipe(_gulp2.default.dest('./dist'));
});
// Concatenate And Minify JavaScript
_gulp2.default.task('scripts', ['lint'], function() {
return _gulp2.default.src(SOURCES).
pipe($.if(/mdlComponentHandler\.js/, $.util.noop(), (0, _uniffe2.default)())).
pipe($.sourcemaps.init())
// Concatenate Scripts
.pipe($.concat('material.js')).
pipe($.iife({
useStrict: true
})).
pipe(_gulp2.default.dest('dist'))
// Minify Scripts
.pipe($.uglify({
sourceRoot: '.',
sourceMapIncludeSources: true
})).
pipe($.header(banner, {
pkg: _package2.default
})).
pipe($.concat('material.min.js'))
// Write Source Maps
.pipe($.sourcemaps.write('.')).
pipe(_gulp2.default.dest('dist')).
pipe($.size({
title: 'scripts'
}));
});
// Clean Output Directory
_gulp2.default.task('clean', function() {
return (0, _del2.default)(['dist', '.publish']);
});
// Copy package manger and LICENSE files to dist
_gulp2.default.task('metadata', function() {
return _gulp2.default.src([
'package.json',
'bower.json',
'LICENSE'
]).
pipe(_gulp2.default.dest('dist'));
});
// Build Production Files, the Default Task
_gulp2.default.task('default', ['clean'], function(cb) {
(0, _runSequence2.default)(
['styles', 'styles-grid'], ['scripts'], ['mocha'],
cb);
});
// Build production files and microsite
_gulp2.default.task('all', ['clean'], function(cb) {
(0, _runSequence2.default)(
['styletemplates'], ['styles-grid', 'styles:gen'], ['scripts'], ['mocha'], ['assets', 'pages',
'templates', 'images', 'metadata'
], ['zip'],
cb);
});
// ***** Testing tasks ***** //
_gulp2.default.task('mocha', ['styles'], function() {
return _gulp2.default.src('test/index.html').
pipe($.mochaPhantomjs({
reporter: 'tap'
}));
});
_gulp2.default.task('mocha:closure', ['closure'], function() {
return _gulp2.default.src('test/index.html').
pipe($.replace('src="../dist/material.js"',
'src="../dist/material.closure.min.js"')).
pipe($.rename('temp.html')).
pipe(_gulp2.default.dest('test')).
pipe($.mochaPhantomjs({
reporter: 'tap'
})).
on('finish', function() {
return _del2.default.sync('test/temp.html');
}).
on('error', function() {
return _del2.default.sync('test/temp.html');
});
});
_gulp2.default.task('test', [
'lint',
'mocha',
'mocha:closure'
]);
_gulp2.default.task('test:visual', function() {
(0, _browserSync2.default)({
notify: false,
server: '.',
startPath: 'test/visual/index.html'
});
_gulp2.default.watch('test/visual/**', reload);
});
// ***** Landing page tasks ***** //
/**
* Site metadata for use with templates.
* @type {Object}
*/
var site = {};
/**
* Generates an HTML file based on a template and file metadata.
*/
function applyTemplate() {
return _through2.default.obj(function(file, enc, cb) {
var data = {
site: site,
page: file.page,
content: file.contents.toString()
};
var templateFile = _path2.default.join(
__dirname, 'docs', '_templates', file.page.layout + '.html');
var tpl = _swig2.default.compileFile(templateFile, {
cache: false
});
file.contents = new Buffer(tpl(data));
cb(null, file);
});
}
/**
* Generates an index.html file for each README in MDL/src directory.
*/
_gulp2.default.task('components', ['demos'], function() {
return _gulp2.default.src('src/**/README.md', {
base: 'src'
})
// Add basic front matter.
.pipe($.header('---\nlayout: component\nbodyclass: component\ninclude_prefix: ../../\n---\n\n')).
pipe($.frontMatter({
property: 'page',
remove: true
})).
pipe($.marked()).
pipe(function() {
return _through2.default.obj(function(file, enc, cb) {
file.page.component = file.relative.split('/')[0];
cb(null, file);
});
}()).
pipe(applyTemplate()).
pipe($.rename(function(path) {
return path.basename = 'index';
})).
pipe(_gulp2.default.dest('dist/components'));
});
/**
* Copies demo files from MDL/src directory.
*/
_gulp2.default.task('demoresources', function() {
return _gulp2.default.src([
'src/**/demos.css',
'src/**/demo.css',
'src/**/demo.js'
], {
base: 'src'
}).
pipe($.if('*.scss', $.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
}))).
pipe($.cssInlineImages({
webRoot: 'src'
})).
pipe($.if('*.css', $.autoprefixer(AUTOPREFIXER_BROWSERS))).
pipe(_gulp2.default.dest('dist/components'));
});
/**
* Generates demo files for testing made of all the snippets and the demo file
* put together.
*/
_gulp2.default.task('demos', ['demoresources'], function() {
/**
* Retrieves the list of component folders.
*/
function getComponentFolders() {
return _fs2.default.readdirSync('src').
filter(function(file) {
return _fs2.default.statSync(_path2.default.join('src', file)).isDirectory();
});
}
var tasks = getComponentFolders().map(function(component) {
return _gulp2.default.src([
_path2.default.join('src', component, 'snippets', '*.html'),
_path2.default.join('src', component, 'demo.html')
]).
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()).
pipe(function() {
return _through2.default.obj(function(file, enc, cb) {
file.page.component = component;
cb(null, file);
});
}()).
pipe(applyTemplate()).
pipe(_gulp2.default.dest(_path2.default.join('dist', 'components', component)));
});
return (0, _mergeStream2.default)(tasks);
});
/**
* Generates an HTML file for each md file in _pages directory.
*/
_gulp2.default.task('pages', ['components'], function() {
return _gulp2.default.src('docs/_pages/*.md').
pipe($.frontMatter({
property: 'page',
remove: true
})).
pipe($.marked()).
pipe(applyTemplate()).
pipe($.replace('$$version$$', _package2.default.version)).
pipe($.replace('$$hosted_libs_prefix$$', hostedLibsUrlPrefix)).
pipe($.replace('$$template_archive_prefix$$', templateArchivePrefix))
/* Replacing code blocks class name to match Prism's. */
.
pipe($.replace('class="lang-', 'class="language-'))
/* Translate html code blocks to "markup" because that's what Prism uses. */
.
pipe($.replace('class="language-html', 'class="language-markup')).
pipe($.rename(function(path) {
if (path.basename !== 'index') {
path.dirname = path.basename;
path.basename = 'index';
}
})).
pipe(_gulp2.default.dest('dist'));
});
/**
* Copies assets from MDL and _assets directory.
*/
_gulp2.default.task('assets', function() {
return _gulp2.default.src([
'docs/_assets/**/*',
'node_modules/clippy/build/clippy.swf',
'node_modules/swfobject-npm/swfobject/src/swfobject.js',
'node_modules/prismjs/prism.js',
'node_modules/prismjs/components/prism-markup.min.js',
'node_modules/prismjs/components/prism-javascript.min.js',
'node_modules/prismjs/components/prism-css.min.js',
'node_modules/prismjs/components/prism-bash.min.js',
'node_modules/prismjs/dist/prism-default/prism-default.css'
]).
pipe($.if(/\.js/i, $.replace('$$version$$', _package2.default.version))).
pipe($.if(/\.js/i, $.replace('$$hosted_libs_prefix$$', hostedLibsUrlPrefix))).
pipe($.if(/\.(svg|jpg|png)$/i, $.imagemin({
progressive: true,
interlaced: true
}))).
pipe($.if(/\.css/i, $.autoprefixer(AUTOPREFIXER_BROWSERS))).
pipe($.if(/\.css/i, $.csso())).
pipe($.if(/\.js/i, $.uglify({
preserveComments: 'some',
sourceRoot: '.',
sourceMapIncludeSources: true
}))).
pipe(_gulp2.default.dest('dist/assets'));
});
/**
* Defines the list of resources to watch for changes.
*/
function watch() {
_gulp2.default.watch(['src/**/*.js', '!src/**/README.md'], ['scripts', 'demos', 'components', reload]);
_gulp2.default.watch(['src/**/*.{scss,css}'], ['styles', 'styles-grid', 'styletemplates', reload]);
_gulp2.default.watch(['src/**/*.html'], ['pages', reload]);
_gulp2.default.watch(['src/**/*.{svg,png,jpg}'], ['images', reload]);
_gulp2.default.watch(['src/**/README.md'], ['pages', reload]);
_gulp2.default.watch(['templates/**/*'], ['templates', reload]);
_gulp2.default.watch(['docs/**/*'], ['pages', 'assets', reload]);
_gulp2.default.watch(['package.json', 'bower.json', 'LICENSE'], ['metadata']);
}
/**
* Serves the landing page from "out" directory.
*/
_gulp2.default.task('serve:browsersync', function() {
(0, _browserSync2.default)({
notify: false,
server: {
baseDir: ['dist']
}
});
watch();
});
_gulp2.default.task('serve', function() {
$.connect.server({
root: 'dist',
port: 5000,
livereload: true
});
watch();
_gulp2.default.src('dist/index.html').
pipe($.open({
uri: 'http://localhost:5000'
}));
});
//My test of serve
_gulp2.default.task('serve:se', function() {
$.connect.server({
root: 'templates',
port: 5000,
livereload: true
});
watch();
_gulp2.default.src('dist/index.html').pipe($.open({
uri: 'http://localhost:5000'
}));
});
// Generate release archive containing just JS, CSS, Source Map deps
_gulp2.default.task('zip:mdl', function() {
return _gulp2.default.src([
'dist/material?(.min)@(.js|.css)?(.map)',
'LICENSE',
'bower.json',
'package.json'
]).
pipe($.zip('mdl.zip')).
pipe(_gulp2.default.dest('dist'));
});
/**
* Returns the list of children directories inside the given directory.
* @param {string} dir the parent directory
* @return {Array<string>} list of child directories
*/
function getSubDirectories(dir) {
return _fs2.default.readdirSync(dir).
filter(function(file) {
return _fs2.default.statSync(_path2.default.join(dir, file)).isDirectory();
});
}
// Generate release archives containing the templates and assets for templates.
_gulp2.default.task('zip:templates', function() {
var templates = getSubDirectories('dist/templates');
// Generate a zip file for each template.
var generateZips = templates.map(function(template) {
return _gulp2.default.src(['dist/templates/' +
template + '/**/*.*',
'LICENSE'
]).
pipe($.rename(function(path) {
path.dirname = path.dirname.replace('dist/templates/' + template, '');
})).
pipe($.zip('' + templateArchivePrefix + template + '.zip')).
pipe(_gulp2.default.dest('dist'));
});
return (0, _mergeStream2.default)(generateZips);
});
_gulp2.default.task('zip', [
'zip:templates',
'zip:mdl'
]);
_gulp2.default.task('genCodeFiles', function() {
return _gulp2.default.src([
'dist/material.*@(js|css)?(.map)',
'dist/mdl.zip', 'dist/' +
templateArchivePrefix + '*.zip'
], {
read: false
}).
pipe($.tap(function(file) {
codeFiles += ' dist/' + _path2.default.basename(file.path);
}));
});
// Push the latest version of code resources (CSS+JS) to Google Cloud Storage.
// 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.
_gulp2.default.task('pushCodeFiles', function() {
var dest = bucketCode;
console.log('Publishing ' + _package2.default.version + ' to CDN (' + dest + ')');
// Build cache control and gsutil cmd to copy
// each object into a GCS bucket. The dest is a version specific path.
// The gsutil -m option requests parallel copies.
// The gsutil -h option is used to set metadata headers
// (cache control, in this case).
// Code files should NEVER be touched after uploading, therefore
// 30 days caching is a safe value.
var cacheControl = '-h "Cache-Control:public,max-age=2592000"';
var gsutilCpCmd = 'gsutil -m cp -z js,css,map ';
var gsutilCacheCmd = 'gsutil -m setmeta -R ' + cacheControl;
// 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.
return _gulp2.default.src('').
pipe($.shell(['' +
gsutilCpCmd + codeFiles + ' ' + dest + '/' + _package2.default.version,
gsutilCacheCmd + ' ' + dest + '/' + _package2.default.version
]));
});
_gulp2.default.task('publish:code', function(cb) {
(0, _runSequence2.default)(
['zip:mdl', 'zip:templates'],
'genCodeFiles',
'pushCodeFiles',
cb);
});
/**
* 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.
*/
function mdlPublish(pubScope) {
var cacheTtl = null;
var src = null;
var dest = null;
if (pubScope === 'staging') {
// Set staging specific vars here.
cacheTtl = 0;
src = 'dist/*';
dest = bucketStaging;
} else if (pubScope === 'prod') {
// Set prod specific vars here.
cacheTtl = 60;
src = 'dist/*';
dest = bucketProd;
} else if (pubScope === 'promote') {
// Set promote (essentially prod) specific vars here.
cacheTtl = 60;
src = bucketStaging + '/*';
dest = bucketProd;
}
var infoMsg = 'Publishing ' + pubScope + '/' + _package2.default.version + ' to GCS (' + dest + ')';
if (src) {
infoMsg += ' from ' + src;
}
console.log(infoMsg);
// Build gsutil commands:
// The gsutil -h option is used to set metadata headers.
// The gsutil -m option requests parallel copies.
// The gsutil -R option is used for recursive file copy.
var cacheControl = '-h "Cache-Control:public,max-age=' + cacheTtl + '"';
var gsutilCacheCmd = 'gsutil -m setmeta ' + cacheControl + ' ' + dest + '/**';
var gsutilCpCmd = 'gsutil -m cp -r -z html,css,js,svg ' + src + ' ' + dest;
_gulp2.default.src('').pipe($.shell([gsutilCpCmd, gsutilCacheCmd]));
}
// 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.
//
_gulp2.default.task('publish:prod', function() {
mdlPublish('prod');
});
// 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.
//
_gulp2.default.task('publish:promote', function() {
mdlPublish('promote');
});
// 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.
//
_gulp2.default.task('publish:staging', function() {
mdlPublish('staging');
});
_gulp2.default.task('_release', function() {
return _gulp2.default.src([
'dist/material?(.min)@(.js|.css)?(.map)',
'LICENSE',
'README.md',
'bower.json',
'package.json',
'.jscsrc',
'.jshintrc',
'./sr?/**/*',
'gulpfile.babel.js',
'./util?/**/*'
]).
pipe(_gulp2.default.dest('_release'));
});
_gulp2.default.task('publish:release', ['_release'], function() {
return _gulp2.default.src('_release').
pipe($.subtree({
remote: 'origin',
branch: 'release'
})).
pipe((0, _vinylPaths2.default)(_del2.default));
});
_gulp2.default.task('templates:styles', function() {
return _gulp2.default.src('templates/**/*.css').
pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
// FIXME: This crashes. It's a bug in gulp-csso,
// not csso itself.
//.pipe($.csso())
.pipe(_gulp2.default.dest('dist/templates'));
});
_gulp2.default.task('templates:static', function() {
return _gulp2.default.src('templates/**/*.html').
pipe($.replace('$$version$$', _package2.default.version)).
pipe($.replace('$$hosted_libs_prefix$$', hostedLibsUrlPrefix)).
pipe(_gulp2.default.dest('dist/templates'));
});
// This task can be used if you want to test the templates against locally
// built version of the MDL libraries.
_gulp2.default.task('templates:localtestingoverride', function() {
return _gulp2.default.src('templates/**/*.html').
pipe($.replace('$$version$$', '.')).
pipe($.replace('$$hosted_libs_prefix$$', '')).
pipe(_gulp2.default.dest('dist/templates'));
});
_gulp2.default.task('templates:images', function() {
return _gulp2.default.src('templates/*/images/**/*').
pipe($.imagemin({
progressive: true,
interlaced: true
})).
pipe(_gulp2.default.dest('dist/templates'));
});
_gulp2.default.task('templates:fonts', function() {
return _gulp2.default.src('templates/*/fonts/**/*').
pipe(_gulp2.default.dest('dist/templates/'));
});
_gulp2.default.task('templates', [
'templates:static',
'templates:images',
'templates:fonts',
'templates:styles'
]);
_gulp2.default.task('styles:gen', ['styles'], function() {
var MaterialCustomizer = require('./docs/_assets/customizer.js');
var templatePath = _path2.default.join(__dirname, 'dist', 'material.min.css.template');
// TODO: This task needs refactoring once we turn MaterialCustomizer
// into a proper Node module.
var mc = new MaterialCustomizer();
mc.template = _fs2.default.readFileSync(templatePath).toString();
var stream = _gulp2.default.src('');
mc.paletteIndices.forEach(function(primary) {
mc.paletteIndices.forEach(function(accent) {
if (primary === accent) {
return;
}
if (mc.forbiddenAccents.indexOf(accent) !== -1) {
return;
}
var primaryName = primary.toLowerCase().replace(' ', '_');
var accentName = accent.toLowerCase().replace(' ', '_');
stream = stream.pipe($.file('material.' +
primaryName + '-' + accentName + '.min.css',
mc.processTemplate(primary, accent)));
});
});
stream.pipe(_gulp2.default.dest('dist'));
});
1 комментарий:
Invest in Ripple on eToro the World’s #1 Social Trading Network...
Join millions who have already discovered easier strategies for investing in Ripple...
Learn from profitable eToro traders or copy their orders automatically!
Отправить комментарий