diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2017-03-29 18:38:50 +0300 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2017-03-29 18:52:17 +0300 |
commit | 7ecfa2f29101401d6d71a43d1f8e6905b447784a (patch) | |
tree | b5498fa9510c3d6dd3004f4b668a7a10633d1f9d /tasks | |
parent | 10900248d101ac72c2d3877613c83b9c6581c0e0 (diff) | |
download | vaadin-core-7ecfa2f29101401d6d71a43d1f8e6905b447784a.tar.gz vaadin-core-7ecfa2f29101401d6d71a43d1f8e6905b447784a.zip |
Enable deploying single elements
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/cdn.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tasks/cdn.js b/tasks/cdn.js index a2bb3a7..0361287 100644 --- a/tasks/cdn.js +++ b/tasks/cdn.js @@ -8,6 +8,7 @@ var modify = require('gulp-modify'); var rsync = require('gulp-rsync'); var gutil = require('gulp-util'); var args = require('yargs').argv; +var git = require('gulp-git'); var stagingBasePath = config.paths.staging.cdn; var version = config.version; @@ -91,3 +92,57 @@ gulp.task('deploy:cdn', ['upload:cdn'], function(done) { done(); } }); + +gulp.task('cdn:arguments', function(done) { + common.checkArguments(['element', 'tag']); + args.folder = args.tag.replace(/^v/g, ''); + stagingPath = path.join(process.cwd(), stagingBasePath, args.element, args.folder); + done(); +}); + +gulp.task('cdn:clone', ['clean:cdn', 'cdn:arguments'], function(done) { + git.clone('https://github.com/vaadin/' + args.element, {args: '-b ' + args.tag + ' ./target/cdn/' + args.element + '/' + args.folder }, function (err) { + if (err) throw err; + done(); + }); +}); + +gulp.task('cdn:install', ['cdn:arguments', 'cdn:clone'], function() { + return bower({ + cwd: stagingPath, + forceLatest: true, + cmd: 'install' + }); +}); + +gulp.task('cdn:stage', ['cdn:arguments', 'cdn:install'], function() { + return gulp.src([stagingPath + '/**/*.html', '!**/bower_components/**']) + .pipe(modify({ + fileModifier: function(file, contents) { + // magic regex trying to change import paths from: + // ../foo/foo.html to bower_components/foo/foo.html + // ../../foo/foo.html to ../bower_components/foo/foo.html + // ../my-element.html stays as it is. + contents = contents.replace(new RegExp(/([href|src].+)((\.\.\/)((?!bower_components|\.\.).+\/.+))/g), '$1bower_components/$4'); + return contents; + } + })) + .pipe(gulp.dest(stagingPath)); +}); + +gulp.task('cdn:upload', ['cdn:stage'], function() { + common.checkArguments(['cdnUsername', 'cdnDestination']); + var destination = path.join(args.cdnDestination, args.element, args.folder); + gutil.log('Uploading to cdn (rsync): ' + stagingPath + ' -> ' + args.cdnUsername + '@' + host + ':' + destination); + return gulp.src(stagingPath) + .pipe(rsync({ + username: args.cdnUsername, + hostname: host, + root: stagingPath, + emptyDirectories: false, + recursive: true, + clean: true, + silent: true, + destination: destination + })); +}); |