aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Virkki <tomivirkki@users.noreply.github.com>2015-10-08 16:48:48 +0300
committerTomi Virkki <tomivirkki@users.noreply.github.com>2015-10-08 16:48:48 +0300
commit4ecbae8718341d380c57fce6bbd8fb690930bee1 (patch)
tree1444579207060892d753a256732885dfbf06999a
parentfef191e55a0055ace031fb2431fc2d9edc781052 (diff)
parent1f3a3c90baeb7aab5097d4df9f9331c16d7520db (diff)
downloadvaadin-core-4ecbae8718341d380c57fce6bbd8fb690930bee1.tar.gz
vaadin-core-4ecbae8718341d380c57fce6bbd8fb690930bee1.zip
Merge pull request #12 from vaadin/docsite_task
Adding tasks to prepare demos for the doc site
-rw-r--r--doc/index.asciidoc1
-rw-r--r--package.json3
-rw-r--r--tasks/config.js3
-rw-r--r--tasks/docsite.js123
4 files changed, 127 insertions, 3 deletions
diff --git a/doc/index.asciidoc b/doc/index.asciidoc
new file mode 100644
index 0000000..2dff096
--- /dev/null
+++ b/doc/index.asciidoc
@@ -0,0 +1 @@
+== Index \ No newline at end of file
diff --git a/package.json b/package.json
index 6de4edd..682742a 100644
--- a/package.json
+++ b/package.json
@@ -16,9 +16,8 @@
"gulp-util": "latest",
"web-component-tester": "3.3.10",
"yargs": "latest",
- "gulp-git": "latest",
+ "gulp-modify": "^0.1.1",
"gulp-add-src": "latest"
-
},
"devDependencies": {
"chalk": "latest",
diff --git a/tasks/config.js b/tasks/config.js
index dc48921..4c53fd6 100644
--- a/tasks/config.js
+++ b/tasks/config.js
@@ -13,7 +13,8 @@ module.exports = {
staging: {
bower: 'target/bower',
cdn: 'target/cdn',
- zip: 'target/zip'
+ zip: 'target/zip',
+ doc: 'target/docsite'
},
userhome: userhome,
privateKey: function() {
diff --git a/tasks/docsite.js b/tasks/docsite.js
new file mode 100644
index 0000000..bce91c8
--- /dev/null
+++ b/tasks/docsite.js
@@ -0,0 +1,123 @@
+var bower = require('gulp-bower');
+var config = require('./config');
+var common = require('./common');
+var gulp = require('gulp');
+var fs = require('fs-extra');
+var replace = require('gulp-replace');
+var rsync = require('gulp-rsync');
+var gutil = require('gulp-util');
+var zip = require('gulp-zip');
+var args = require('yargs').argv;
+var addsrc = require('gulp-add-src');
+
+var stagingBasePath = config.paths.staging.cdn;
+var docPath = config.paths.staging.doc;
+var version = config.version;
+var host = config.cdnHost;
+var permalink = config.permalink;
+var stagingPath = stagingBasePath + '/' + version;
+var modify = require('gulp-modify');
+var rootZip = 'target/';
+var fileZip = 'docsite.zip'
+
+gulp.task('cdn:docsite:clean', function() {
+ fs.removeSync(docPath);
+ fs.removeSync(rootZip + fileZip);
+});
+
+gulp.task('cdn:docsite:bower_components', ['cdn:stage-bower_components'], function() {
+ gutil.log('Copying bower components from ' + stagingPath + ' to ' + docPath + '/bower_components');
+ return gulp.src([stagingPath + '/**'])
+ // Temporary patch until #180 is fixed:
+ // https://github.com/webcomponents/webcomponentsjs/issues/180
+ .pipe(modify({
+ fileModifier: function(file, contents) {
+ if (/webcomponents-lite.*js/.test(file.path)) {
+ contents = contents.replace(/(if ?\()(\w+\.log)(\))/mg, '$1$2 && $2.split$3')
+ }
+ return contents;
+ }
+ }))
+ .pipe(gulp.dest(docPath + '/bower_components'));
+});
+
+gulp.task('cdn:docsite:components', function() {
+ return gulp.src('doc/*')
+ .pipe(gulp.dest(docPath));
+});
+
+var doctasks = ['cdn:docsite:components'];
+config.components.forEach(function (n) {
+ var task = 'cdn:docsite:' + n;
+ doctasks.push(task);
+ gulp.task(task, ['cdn:docsite:bower_components'], function(done) {
+ var componentDocsite = docPath + '/' + n;
+ var componentDemo = stagingPath + '/' + n + '/demo/**';
+
+ gutil.log('Generating site documentation from ' + componentDemo + ' into ' + componentDocsite);
+ fs.mkdirsSync(componentDocsite);
+ return gulp.src([componentDemo, '!**/*-embed.html'])
+ // Remove bad tags
+ .pipe(replace(/^.*<(!doctype|\/?html|\/?head|\/?body|meta|title).*>.*\n/img, ''))
+ // Uncomment metainfo, and enclose all the example in {% raw %} ... {% endraw %} to avoid liquid conflicts
+ // We use gulp-modify instead of replace in order to handle the github url for this file
+ .pipe(modify({
+ fileModifier: function(file, contents) {
+ var re = new RegExp(".*/" + n + "/");
+ var gh = 'https://github.com/vaadin/' + n + '/edit/master/' + file.path.replace(re, '');
+ return contents.replace(/^.*<!--[ \n]+([\s\S]*?title:[\s\S]*?)[ \n]+-->.*\n([\s\S]*)/img,
+ '---\n$1\nsourceurl: ' + gh + '\n---\n{% raw %}\n$2\n{% endraw %}');
+ }
+ }))
+ .pipe(replace(/^.*<section>[\s\S]*?table-of-contents[\s\S]*?<\/section>.*\n/im, ''))
+ // Add ids to headers, so as site configures permalinks
+ .pipe(replace(/<h(\d+)>(.*)(<\/h\d+>)/img, function($0, $1, $2, $3){
+ var id = $2.trim().toLowerCase().replace(/[^\w]+/g,'_');
+ return '<h' + $1 + ' id="' + id + '">' + $2 + $3;
+ }))
+ // Remove webcomponents polyfill since it's added at top of the site
+ .pipe(replace(/^.*<script.*?\/webcomponents.*\.js[\"'].*?<\/script>\s*?\n?/img, ''))
+ // embed files are displayed as iframe, we don't remove above fragments like body or polyfill
+ .pipe(addsrc(componentDemo + '/*-embed.html'))
+ // Remove Analytics
+ .pipe(replace(/^.*<script.*?ga\.js[\"'].*?<\/script>\s*?\n?/img, ''))
+ // Adjust bowerComponents variable in common.html
+ .pipe(replace(/(bowerComponents *= *)'..\/..\/'/, "$1'../bower_components/'"))
+ // Adjust location of the current component in bower_components (..)
+ .pipe(replace(/(src|href)=("|')\.\.(\/\w)/mg, '$1=$2../bower_components/' + n + '$3'))
+ // Adjust location of dependencies in bower_components (../..)
+ .pipe(replace(/(src|href)=("|')(.*?)\.\.\/\.\.\//mg, '$1=$2../bower_components/'))
+ // Remove references to demo.css file
+ .pipe(replace(/^.*<link.*demo.css.*\n/im, ''))
+ // Remove table of contents
+ .pipe(replace(/^.*table-of-contents.html.*\n/im, ''))
+ .pipe(gulp.dest(componentDocsite));
+ });
+});
+
+gulp.task('cdn:docsite:zip', doctasks, function() {
+ var src = docPath + '/**/*';
+ gutil.log("Creating docsite zip " + docPath + " -> " + rootZip + fileZip);
+ return gulp.src(src)
+ .pipe(zip(fileZip))
+ .pipe(gulp.dest(rootZip));
+});
+
+gulp.task('cdn:docsite:upload', ['cdn:docsite:clean', 'cdn:docsite:zip'], function(done) {
+ common.checkArguments(['cdnUsername', 'cdnDestination']);
+
+ gutil.log('Uploading docsite (scp): ' + rootZip + fileZip + ' -> ' + args.cdnUsername + '@' + host + ':' + args.cdnDestination + version);
+
+ require('scp2').scp(rootZip + fileZip, {
+ host: host,
+ username: args.cdnUsername,
+ privateKey: config.paths.privateKey(),
+ path: args.cdnDestination + version
+ }, function(err) {
+ done(err);
+ })
+});
+
+gulp.task('cdn:docsite', ['cdn:docsite:upload']);
+
+