deploy.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. var gulp = require('gulp');
  2. var filter = require('gulp-filter');
  3. var cleancss = require('gulp-clean-css');
  4. var rename = require('gulp-rename');
  5. var uglify = require('gulp-uglify');
  6. var confirm = require('gulp-prompt').confirm;
  7. var rsync = require('gulp-rsync');
  8. var replace = require('gulp-replace');
  9. var octophant = require('octophant');
  10. var inquirer = require('inquirer');
  11. var exec = require('child_process').execSync;
  12. var plumber = require('gulp-plumber');
  13. var sourcemaps = require('gulp-sourcemaps');
  14. var rollup = require('rollup');
  15. var ROLLUP_CONFIG = require('../../rollup.config.js');
  16. var CONFIG = require('../config.js');
  17. var CURRENT_VERSION = require('../../package.json').version;
  18. var NEXT_VERSION;
  19. gulp.task('deploy', gulp.series('deploy:prompt', 'deploy:version', 'deploy:dist', 'deploy:plugins', 'deploy:settings', 'deploy:commit', 'deploy:templates'));
  20. gulp.task('deploy:prep', gulp.series('deploy:prompt', 'deploy:version', 'deploy:dist', 'deploy:plugins', 'deploy:settings'));
  21. gulp.task('deploy:dist', gulp.series('sass:foundation', 'javascript:foundation', 'deploy:dist:files', 'deploy:dist:bundles'));
  22. gulp.task('deploy:plugins', gulp.series('deploy:plugins:sources', 'deploy:plugins:sourcemaps'));
  23. gulp.task('deploy:prompt', function(cb) {
  24. inquirer.prompt([{
  25. type: 'input',
  26. name: 'version',
  27. message: 'What version are we moving to? (Current version is ' + CURRENT_VERSION + ')'
  28. }])
  29. .then(function(res) {
  30. NEXT_VERSION = res.version;
  31. cb();
  32. });
  33. });
  34. // Bumps the version number in any file that has one
  35. gulp.task('deploy:version', function() {
  36. return gulp.src(CONFIG.VERSIONED_FILES, { base: process.cwd() })
  37. .pipe(replace(CURRENT_VERSION, NEXT_VERSION))
  38. .pipe(gulp.dest('.'));
  39. });
  40. // Generates compiled CSS and JS files and sourcemaps and puts them in the dist/ folder
  41. gulp.task('deploy:dist:files', function() {
  42. var cssFilter = filter(['**/*.css'], { restore: true });
  43. var jsFilter = filter(['**/*.js'], { restore: true });
  44. var cssSourcemapFilter = filter(['**/*.css.map'], { restore: true });
  45. var jsSourcemapFilter = filter(['**/*.js.map'], { restore: true });
  46. var tsFilter = filter(['**/*.ts'], { restore: true });
  47. return gulp.src(CONFIG.DIST_FILES)
  48. .pipe(plumber())
  49. // --- Source maps ---
  50. // * Copy sourcemaps to the dist folder
  51. // This is done first to avoid collision with minified-sourcemaps.
  52. .pipe(cssSourcemapFilter)
  53. .pipe(gulp.dest('./dist/css'))
  54. .pipe(cssSourcemapFilter.restore)
  55. .pipe(jsSourcemapFilter)
  56. .pipe(gulp.dest('./dist/js'))
  57. .pipe(jsSourcemapFilter.restore)
  58. // --- Source files ---
  59. // * Copy source files to dist folder
  60. // * Create minified files
  61. // * Create minified-sourcemaps based on standard sourcemaps.
  62. // Sourcemaps are initialized before the ".min" renaming to be able retrieve
  63. // original sourcemaps from source names.
  64. .pipe(cssFilter)
  65. .pipe(gulp.dest('./dist/css'))
  66. .pipe(sourcemaps.init({ loadMaps: true }))
  67. .pipe(rename({ suffix: '.min' }))
  68. .pipe(cleancss({ compatibility: 'ie9' }))
  69. .pipe(sourcemaps.write('.'))
  70. .pipe(gulp.dest('./dist/css'))
  71. .pipe(cssFilter.restore)
  72. .pipe(jsFilter)
  73. .pipe(gulp.dest('./dist/js'))
  74. .pipe(sourcemaps.init({ loadMaps: true }))
  75. .pipe(rename({ suffix: '.min' }))
  76. .pipe(uglify())
  77. .pipe(sourcemaps.write('.'))
  78. .pipe(gulp.dest('./dist/js'))
  79. .pipe(jsFilter.restore)
  80. // --- TypeScript files ---
  81. // * Copy typescript files to the dist folder
  82. .pipe(tsFilter)
  83. .pipe(gulp.dest('./dist/js'))
  84. .pipe(tsFilter.restore);
  85. });
  86. //
  87. // Generates JS bundles and puts them in the dist/ folder.
  88. //
  89. // In addition to the UMD bundle coming from the build task, the following
  90. // formats are generated: CJS, ESM, ES6.
  91. // See "rollup.config.js" for more information.
  92. //
  93. gulp.task('deploy:dist:bundles', gulp.series(
  94. // Create a subtask for each Rollup config
  95. ...ROLLUP_CONFIG.map((config) => function () {
  96. // Run rollup with the Rollup config
  97. return rollup.rollup(config)
  98. .then(bundle => bundle.write(config.output));
  99. })
  100. ));
  101. // Copies standalone JavaScript plugins to dist/ folder
  102. gulp.task('deploy:plugins:sources', function () {
  103. return gulp.src('_build/assets/js/plugins/*.js')
  104. .pipe(gulp.dest('dist/js/plugins'))
  105. .pipe(sourcemaps.init({ loadMaps: true }))
  106. .pipe(rename({ suffix: '.min' }))
  107. .pipe(uglify())
  108. .pipe(sourcemaps.write('.'))
  109. .pipe(gulp.dest('dist/js/plugins'));
  110. });
  111. // Copies standalone JavaScript plugins sourcemaps to dist/ folder
  112. gulp.task('deploy:plugins:sourcemaps', function () {
  113. return gulp.src('_build/assets/js/plugins/*.js.map')
  114. .pipe(gulp.dest('dist/js/plugins'));
  115. });
  116. // Generates a settings file
  117. gulp.task('deploy:settings', function(done) {
  118. var options = {
  119. title: 'Foundation for Sites Settings',
  120. output: './scss/settings/_settings.scss',
  121. groups: {
  122. 'grid': 'The Grid',
  123. 'off-canvas': 'Off-canvas',
  124. 'typography-base': 'Base Typography'
  125. },
  126. sort: [
  127. 'global',
  128. 'breakpoints',
  129. 'grid',
  130. 'typography-base',
  131. 'typography-helpers'
  132. ],
  133. imports: ['util/util'],
  134. _foundationShim: true
  135. }
  136. octophant('./scss', options, done);
  137. });
  138. // Writes a commit with the changes to the version numbers
  139. gulp.task('deploy:commit', function() {
  140. exec('git commit -am "Bump to version "' + NEXT_VERSION);
  141. exec('git tag v' + NEXT_VERSION);
  142. exec('git push origin develop --follow-tags');
  143. });
  144. // Uploads the documentation to the live server
  145. gulp.task('deploy:docs', gulp.series('build', function() {
  146. return gulp.src('./_build/**')
  147. .pipe(confirm('Make sure everything looks right before you deploy.'))
  148. .pipe(rsync({
  149. root: './_build',
  150. hostname: 'deployer@72.32.134.77',
  151. destination: '/home/deployer/sites/foundation-sites-6-docs'
  152. }));
  153. }));
  154. // Uploads the documentation to the live server in beta env
  155. gulp.task('deploy:beta', gulp.series('build', function() {
  156. return gulp.src('./_build/**')
  157. .pipe(confirm('Make sure everything looks right before you deploy.'))
  158. .pipe(rsync({
  159. root: './_build',
  160. hostname: 'deployer@72.32.134.77',
  161. destination: '/home/deployer/sites/scalingsexiness/foundation-sites-6-docs'
  162. }));
  163. }));
  164. // This part of the deploy process hasn't been tested! It should be done manually for now
  165. gulp.task('deploy:templates', function(done) {
  166. // exec('git clone https://github.com/zurb/foundation-sites-template');
  167. // exec('cp scss/settings/_settings.scss foundation-sites-template/scss/_settings.scss');
  168. // exec('cd foundation-sites-template');
  169. // exec('git commit -am "Update settings file to match Foundation "' + NEXT_VERSION);
  170. // exec('git push origin master');
  171. // exec('cd ..');
  172. // exec('rm -rf foundation-sites-template');
  173. //
  174. // exec('git clone https://github.com/zurb/foundation-zurb-template');
  175. // exec('cp scss/settings/_settings.scss foundation-zurb-template/src/assets/scss/_settings.scss');
  176. // exec('cd foundation-zurb-template');
  177. // exec('git commit -am "Update settings file to match Foundation "' + NEXT_VERSION);
  178. // exec('git push origin master');
  179. // exec('cd ..');
  180. // exec('rm -rf foundation-zurb-template');
  181. done();
  182. });
  183. // The Customizer runs this function to generate files it needs
  184. gulp.task('deploy:custom', gulp.series('sass:foundation', 'javascript:foundation', gulp.parallel(
  185. function () {
  186. return gulp.src('./_build/assets/css/foundation.css')
  187. .pipe(cleancss({ compatibility: 'ie9' }))
  188. .pipe(rename('foundation.min.css'))
  189. .pipe(gulp.dest('./_build/assets/css'));
  190. },
  191. function () {
  192. return gulp.src('_build/assets/js/foundation.js')
  193. .pipe(uglify())
  194. .pipe(rename('foundation.min.js'))
  195. .pipe(gulp.dest('./_build/assets/js'));
  196. }
  197. )));