add publish:gcs gulp task to push microsite to gcs bucket

added publish dep on default task (per Surma comments)

add support for cache control tuning

remove redundant comma

use {read:false} on gulp.src to avoid wasting time reading file contents

remove publish dep on default and rename two publish tasks per Alex' comment
master
Marc Cohen 2015-06-19 14:28:48 +01:00
parent f17e472f86
commit f130c8dd84
3 changed files with 60 additions and 21 deletions

View File

@ -62,11 +62,11 @@
</div>
<nav class="docs-navigation mdl-navigation">
<a href="{{page.include_prefix}}" class="mdl-navigation__link about">About</a>
<a href="{{page.include_prefix}}started" class="mdl-navigation__link started">Getting Started</a>
<a href="{{page.include_prefix}}templates" class="mdl-navigation__link templates">Templates</a>
<a href="{{page.include_prefix}}components" class="mdl-navigation__link components">Components</a>
<a href="{{page.include_prefix}}styles" class="mdl-navigation__link styles">Styles</a>
<a href="{{page.include_prefix}}customize" class="mdl-navigation__link customize">Customize</a>
<a href="{{page.include_prefix}}started/index.html" class="mdl-navigation__link started">Getting Started</a>
<a href="{{page.include_prefix}}templates/index.html" class="mdl-navigation__link templates">Templates</a>
<a href="{{page.include_prefix}}components/index.html" class="mdl-navigation__link components">Components</a>
<a href="{{page.include_prefix}}styles/index.html" class="mdl-navigation__link styles">Styles</a>
<a href="{{page.include_prefix}}customize/index.html" class="mdl-navigation__link customize">Customize</a>
</nav>
<div class="docs-special">
<a href="https://github.com/google/material-design-lite" class="github docs-special--button"><i class="material-icons">link</i><span>GitHub</span></a>

View File

@ -16,7 +16,7 @@
</button>
Download
</a>
<a href="{{page.include_prefix}}templates/{{ template.name }}" target="_blank" class="mdl-cell mdl-cell--6-col-desktop mdl-cell--4-col-tablet mdl-cell--2-col-phone">
<a href="{{page.include_prefix}}templates/{{ template.name }}/index.html" target="_blank" class="mdl-cell mdl-cell--6-col-desktop mdl-cell--4-col-tablet mdl-cell--2-col-phone">
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
<i class="material-icons">arrow_forward</i>
</button>

View File

@ -439,25 +439,36 @@ gulp.task('publish', function(cb) {
cb);
});
// Push the latest version to CDN (Google Cloud Storage)
// Push the latest version of runtime 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 more info on gsutil: https://cloud.google.com/storage/docs/gsutil.
gulp.task('publish:cdn', function() {
var bucket = 'gs://materialdesignlite/';
var infoMsg = 'Publishing ' + pkg.version + ' to CDN (' + bucket + ')';
// Build gsutil command to copy each object into the dest bucket.
// -a sets the ACL on each object to public-read
// -m does parallel copies (no help here since one gsutil per file)
// We copy both a default instance at the bucket root and a version
// specific instance into a subdir.
var gsutilCmd = 'gsutil -m cp -a public-read <%= file.path %> ' + bucket;
process.stdout.write(infoMsg + '\n');
return gulp.src('dist/material.*@(js|css)')
// For info on gsutil: https://cloud.google.com/storage/docs/gsutil.
//
gulp.task('publish:runtime', function() {
// Build dest path, info message, cache control and gsutil cmd to copy
// each object into a GCS bucket. The dest is a version specific path.
// The gsutil -a option sets the ACL on each object copied.
// The gsutil -m option requests parallel copies.
// The gsutil -h option is used to set metadata headers (cache control, in this case).
// For cache control, start with 0s (disable caching during dev),
// but consider more helpful interval (e.g. 3600s) after launch.
var dest = 'gs://materialdesignlite/serve';
var info_msg = 'Publishing ' + pkg.version + ' to CDN (' + dest + ')';
var cache_control = '-h "Cache-Control:public,max-age=0"';
var gsutil_cp_cmd = 'gsutil -m cp -a public-read <%= file.path %> ' + dest;
var gsutil_cache_cmd = 'gsutil -m setmeta ' + cache_control + ' ' + dest;
process.stdout.write(info_msg + '\n');
return gulp.src('dist/material.*@(js|css)', {read: false})
.pipe($.tap(function(file, t) {
file.base = path.basename(file.path);
}))
.pipe($.shell([gsutilCmd, gsutilCmd +
pkg.version + '/<%= file.base %>']));
.pipe($.shell([
gsutil_cp_cmd + '/' + pkg.version + '/<%= file.base %>',
gsutil_cache_cmd + '/' + pkg.version + '/<%= file.base %>'
]));
});
gulp.task('publish:push', function() {
@ -472,6 +483,34 @@ gulp.task('publish:push', function() {
}));
});
// Push the latest version of the MDL microsite 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.
//
gulp.task('publish:site', function() {
// Build dest bucket, cache control, and info message.
// For cache control, start with 0s (disable caching during dev),
// but consider more helpful interval (e.g. 3600s) after launch.
var dest = 'gs://materialdesignlite';
var cache_control = '-h "Cache-Control:public,max-age=0"';
var info_msg = 'Publishing ' + pkg.version + ' of MDL site to GCS (' + dest + ')';
// Build gsutil commands to recursively sync local distribution tree
// to the dest bucket and to recursively set permissions to public-read.
// The gsutil -m option requests parallel copies.
// The gsutil -R option does recursive acl setting.
// The gsutil -h option is used to set metadata headers (cache control, in this case).
var gsutil_sync_cmd = 'gsutil -m rsync -d -R dist ' + dest;
var gsutil_acl_cmd = 'gsutil -m acl set -R public-read ' + dest;
var gsutil_cache_cmd = 'gsutil -m setmeta ' + cache_control + ' ' + dest + '/**';
process.stdout.write(info_msg + '\n');
gulp.src('').pipe($.shell([gsutil_sync_cmd, gsutil_acl_cmd, gsutil_cache_cmd]));
});
gulp.task('templates:mdl', function() {
return gulp.src([
'templates/**/*.scss'