archive.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var gulp = require('gulp');
  2. var rename = require('gulp-rename');
  3. var filter = require('gulp-filter');
  4. var replace = require('gulp-replace');
  5. var zip = require('gulp-zip');
  6. var del = require('del');
  7. // determines the name of the ZIP file
  8. var packageConf = require('../package.json');
  9. var packageId = packageConf.name + '-' + packageConf.version;
  10. gulp.task('archive', [
  11. 'archive:dist',
  12. 'archive:locale',
  13. 'archive:misc',
  14. 'archive:deps',
  15. 'archive:demos'
  16. ], function() {
  17. // make the zip, with a single root directory of a similar name
  18. return gulp.src('tmp/' + packageId + '/**/*', { base: 'tmp/' })
  19. .pipe(zip(packageId + '.zip'))
  20. .pipe(gulp.dest('dist/'));
  21. });
  22. gulp.task('archive:clean', function() {
  23. return del([
  24. 'tmp/' + packageId + '/',
  25. 'dist/' + packageId + '.zip'
  26. ]);
  27. });
  28. gulp.task('archive:dist', [ 'modules', 'minify' ], function() {
  29. return gulp.src('dist/*.{js,css}') // matches unminified and minified files
  30. .pipe(gulp.dest('tmp/' + packageId + '/'));
  31. });
  32. gulp.task('archive:locale', [ 'locale' ], function() {
  33. return gulp.src([
  34. 'dist/locale-all.js',
  35. 'dist/locale/*.js'
  36. ], {
  37. base: 'dist/'
  38. })
  39. .pipe(gulp.dest('tmp/' + packageId + '/'));
  40. });
  41. gulp.task('archive:misc', function() {
  42. return gulp.src([
  43. 'LICENSE.*',
  44. 'CHANGELOG.*',
  45. 'CONTRIBUTING.*'
  46. ])
  47. .pipe(rename({ extname: '.txt' }))
  48. .pipe(gulp.dest('tmp/' + packageId + '/'));
  49. });
  50. gulp.task('archive:deps', [ 'archive:jqui:theme' ], function() {
  51. return gulp.src([
  52. 'node_modules/moment/min/moment.min.js',
  53. 'node_modules/jquery/dist/jquery.min.js',
  54. 'node_modules/components-jqueryui/jquery-ui.min.js'
  55. ])
  56. .pipe(gulp.dest('tmp/' + packageId + '/lib/'));
  57. });
  58. // transfers a single jQuery UI theme
  59. gulp.task('archive:jqui:theme', function() {
  60. return gulp.src([
  61. 'jquery-ui.min.css',
  62. 'images/*'
  63. ], {
  64. cwd: 'node_modules/components-jqueryui/themes/cupertino/',
  65. base: 'node_modules/components-jqueryui/themes/'
  66. })
  67. .pipe(gulp.dest('tmp/' + packageId + '/lib/'));
  68. });
  69. // transfers demo files, transforming their paths to dependencies
  70. gulp.task('archive:demos', function() {
  71. return gulp.src('**/*', { cwd: 'demos/', base: 'demos/' })
  72. .pipe(htmlFileFilter)
  73. .pipe(demoPathReplace)
  74. .pipe(htmlFileFilter.restore) // pipe thru files that didn't match htmlFileFilter
  75. .pipe(gulp.dest('tmp/' + packageId + '/demos/'));
  76. });
  77. var htmlFileFilter = filter('*.html', { restore: true });
  78. var demoPathReplace = replace(
  79. /((?:src|href)=['"])([^'"]*)(['"])/g,
  80. function(m0, m1, m2, m3) {
  81. return m1 + transformDemoPath(m2) + m3;
  82. }
  83. );
  84. function transformDemoPath(path) {
  85. // reroot 3rd party libs
  86. path = path.replace('../node_modules/moment/', '../lib/');
  87. path = path.replace('../node_modules/jquery/dist/', '../lib/');
  88. path = path.replace('../node_modules/components-jqueryui/themes/cupertino/', '../lib/cupertino/'); // must be first
  89. path = path.replace('../node_modules/components-jqueryui/', '../lib/');
  90. // reroot dist files to archive root
  91. path = path.replace('../dist/', '../');
  92. if (
  93. !/\.min\.(js|css)$/.test(path) && // not already minified
  94. path !== '../locale-all.js' // this file is already minified
  95. ) {
  96. // use minified
  97. path = path.replace(/\/([^\/]*)\.(js|css)$/, '/$1.min.$2');
  98. }
  99. return path;
  100. }