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 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 markdown = require('gulp-markdown');
  7. var replace = require('gulp-replace');
  8. var rsync = require('gulp-rsync');
  9. var gutil = require('gulp-util');
  10. var _ = require('lodash');
  11. var args = require('yargs').argv;
  12. var git = require('gulp-git');
  13. var addsrc = require('gulp-add-src');
  14. var stagingBasePath = config.paths.staging.cdn;
  15. var version = config.version;
  16. var host = config.cdnHost;
  17. var permalink = config.permalink;
  18. var stagingPath = stagingBasePath + '/' + version;
  19. var testPath = process.cwd() + '/' + stagingPath + '/test';
  20. gulp.task('clean:cdn', function() {
  21. fs.removeSync(stagingBasePath);
  22. });
  23. gulp.task('cdn:stage-bower_components', function() {
  24. return bower({
  25. directory: stagingPath,
  26. forceLatest: true,
  27. cmd: 'install'
  28. });
  29. });
  30. gulp.task('cdn:stage-vaadin-components', function() {
  31. return gulp.src(['LICENSE.html', 'ga.js', 'vaadin-components.html', 'demo/*', 'apidoc/*'], {base:"."})
  32. .pipe(replace('https://cdn.vaadin.com/vaadin-components/latest/', '../../'))
  33. .pipe(addsrc('README.md'))
  34. .pipe(gulp.dest(stagingPath + "/vaadin-components"));
  35. });
  36. gulp.task('stage:cdn', [ 'clean:cdn', 'cdn:stage-bower_components', 'cdn:stage-vaadin-components' ]);
  37. gulp.task('upload:cdn', ['stage:cdn'], function() {
  38. common.checkArguments(['cdnUsername', 'cdnDestination']);
  39. gutil.log('Uploading to cdn (rsync): ' + stagingPath + ' -> '+ args.cdnUsername + '@' + host + ':' + args.cdnDestination + version);
  40. return gulp.src(stagingPath)
  41. .pipe(rsync({
  42. username: args.cdnUsername,
  43. hostname: host,
  44. root: stagingPath,
  45. emptyDirectories: false,
  46. recursive: true,
  47. clean: true,
  48. silent: true,
  49. destination: args.cdnDestination + version
  50. }));
  51. });
  52. gulp.task('deploy:cdn', ['upload:cdn'], function(done) {
  53. if (permalink) {
  54. var cmd = 'rm -f ' + args.cdnDestination + permalink + '; ln -s ' + version + ' ' + args.cdnDestination + permalink + '; ls -l ' + args.cdnDestination;
  55. gutil.log('Deploying CDN : ssh ' + args.cdnUsername + '@' + host + ' ' + cmd);
  56. require('node-ssh-exec')({
  57. host: host,
  58. username: args.cdnUsername,
  59. privateKey: config.paths.privateKey()
  60. }, cmd, function (error, response) {
  61. if (error) {
  62. throw error;
  63. }
  64. gutil.log(response);
  65. done();
  66. });
  67. } else {
  68. done();
  69. }
  70. });
  71. gulp.task('cdn-test:clean', function() {
  72. fs.removeSync(stagingPath + '/test');
  73. });
  74. gulp.task('cdn-test:install-dependencies', function() {
  75. return bower({
  76. directory: stagingPath,
  77. cmd: 'install'
  78. }, [['web-component-tester#2.2.6']]);
  79. });
  80. config.components.forEach(function (n) {
  81. gulp.task('cdn-test:stage:' + n, ['cdn-test:clean', 'cdn-test:install-dependencies'], function(done) {
  82. fs.mkdirsSync(testPath);
  83. return git.clone('https://github.com/vaadin/' + n, {cwd: testPath}, function (err) {
  84. gulp.src(testPath + '/' + n + '/test/**')
  85. .pipe(replace(/(src|href)=("|')(.*?)\.\.\/\.\.\/(bower_components|node_modules)\/(.*?)\//mg, '$1=$2https://cdn.vaadin.com/vaadin-components/'+ version + '/$5/'))
  86. .pipe(replace(/(src|href)=("|')(.*?)\.\.\//mg, '$1=$2https://cdn.vaadin.com/vaadin-components/'+ version +'/' + n + '/'))
  87. .pipe(replace(/(src|href)=("|')(.*?)(web-component-tester)\//mg, '$1=$2../../web-component-tester/'))
  88. .pipe(gulp.dest(testPath + '/' + n + '/test/'));
  89. done();
  90. });
  91. });
  92. });
  93. gulp.task('cdn-test:stage', _.map(config.components, function (n) {
  94. return 'cdn-test:stage:' + n;
  95. }));
  96. gulp.task('verify:cdn', ['cdn-test:stage'], function(done) {
  97. if(args.autoRevert) {
  98. common.checkArguments(['cdnUsername', 'cdnDestination']);
  99. }
  100. // use unique browser combination because bower,cdn,zip verifications are run
  101. // at the same time and TeamCity test results will get mixed up if same browsers are used.
  102. common.testSauce(
  103. ['target/cdn/' + version + '/test/**/index.html'],
  104. ['Windows 7/firefox@36'],
  105. 'vaadin-components / cdn.vaadin.com / ' + version,
  106. function(err) {
  107. common.autoRevert(err, function() {
  108. gutil.log('Deleting folder ' + args.cdnDestination + version);
  109. require('node-ssh-exec')({
  110. host: host,
  111. username: args.cdnUsername,
  112. privateKey: config.paths.privateKey()
  113. }, 'rm -rf ' + args.cdnDestination + version, function (error, response) {
  114. if (error) {
  115. throw error;
  116. }
  117. gutil.log(response);
  118. done(err);
  119. });
  120. }, done)});
  121. });