You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cdn.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var bower = require('gulp-bower');
  2. var config = require('./config');
  3. var common = require('./common');
  4. var gulp = require('gulp');
  5. var fs = require('fs-extra');
  6. var modify = require('gulp-modify');
  7. var rsync = require('gulp-rsync');
  8. var gutil = require('gulp-util');
  9. var args = require('yargs').argv;
  10. var stagingBasePath = config.paths.staging.cdn;
  11. var version = config.version;
  12. var host = config.toolsHost;
  13. var permalink = config.permalink;
  14. var stagingPath = stagingBasePath + '/' + version;
  15. var testPath = process.cwd() + '/' + stagingPath + '/test';
  16. gulp.task('clean:cdn', function() {
  17. fs.removeSync(stagingBasePath);
  18. });
  19. gulp.task('cdn:stage-bower_components', function() {
  20. return bower({
  21. directory: stagingPath,
  22. forceLatest: true,
  23. cmd: 'install'
  24. });
  25. });
  26. gulp.task('cdn:stage-vaadin-elements', function() {
  27. return gulp.src(['LICENSE.html', 'README.md', 'vaadin-elements.html', 'demo/*', 'apidoc/*'], {base:"."})
  28. .pipe(modify({
  29. fileModifier: function(file, contents) {
  30. if (/README.md/.test(file.path)) {
  31. contents = contents.replace(/\/latest\//mg, '/' + version + '/');
  32. } else {
  33. contents.replace('https://cdn.vaadin.com/vaadin-elements/latest/', '../../');
  34. }
  35. return contents;
  36. }
  37. }))
  38. .pipe(gulp.dest(stagingPath + "/vaadin-elements"));
  39. });
  40. gulp.task('stage:cdn', [ 'clean:cdn', 'cdn:stage-bower_components', 'cdn:stage-vaadin-elements' ]);
  41. gulp.task('upload:cdn', ['stage:cdn'], function() {
  42. common.checkArguments(['cdnUsername', 'cdnDestination']);
  43. gutil.log('Uploading to cdn (rsync): ' + stagingPath + ' -> '+ args.cdnUsername + '@' + host + ':' + args.cdnDestination + version);
  44. return gulp.src(stagingPath)
  45. .pipe(rsync({
  46. username: args.cdnUsername,
  47. hostname: host,
  48. root: stagingPath,
  49. emptyDirectories: false,
  50. recursive: true,
  51. clean: true,
  52. silent: true,
  53. destination: args.cdnDestination + version
  54. }));
  55. });
  56. gulp.task('deploy:cdn', ['upload:cdn'], function(done) {
  57. if (permalink) {
  58. var cmd = 'rm -f ' + args.cdnDestination + permalink + '; ln -s ' + version + ' ' + args.cdnDestination + permalink + '; ls -l ' + args.cdnDestination;
  59. gutil.log('Deploying CDN : ssh ' + args.cdnUsername + '@' + host + ' ' + cmd);
  60. common.ssh(args.cdnUsername, host, cmd, done);
  61. } else {
  62. done();
  63. }
  64. });