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.0KB

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