gulpfile-zip.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. module.exports = function(gulp, plugins) {
  2. var del = require('del'),
  3. path = require('path'),
  4. log = console.log;
  5. var pkg = require('../package.json');
  6. gulp.task('zip_clean', function(){
  7. del.sync(['assets'])
  8. })
  9. gulp.task('zip_copySrc', function(){
  10. return gulp.src(['src/**'])
  11. .pipe(gulp.dest('assets/src'))
  12. })
  13. gulp.task('zip_copyDest', function(){
  14. return gulp.src(['dest/**', '!dest/**/*.html'])
  15. .pipe(gulp.dest('assets/dest'))
  16. })
  17. gulp.task('zip_trans', function() {
  18. var url = require('url').resolve('http://assets.dwstatic.com', [pkg.description, pkg.name, pkg.version].join('/'))
  19. return gulp.src(['dest/**/*.html'])
  20. .pipe( plugins.cdnAbsolutePath({assets:'dest', cdn:url}) )
  21. .pipe(gulp.dest('assets/dest'))
  22. })
  23. gulp.task('zip_done', ['zip_clean', 'zip_copySrc', 'zip_copyDest', 'zip_trans'], function() {
  24. var zipname = path.basename(path.join(__dirname, '..'))+'.zip'
  25. return gulp.src(['assets/**'])
  26. .pipe(plugins.zip(zipname))
  27. .pipe(gulp.dest('./'))
  28. })
  29. gulp.task('zip', ['zip_done'], function() {
  30. del.sync(['assets'])
  31. })
  32. }