gulpfile-release.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. module.exports = function(gulp, plugins) {
  2. var argv = require('yargs').argv,
  3. del = require('del'),
  4. moment = require('moment'),
  5. multiSprite = require('multi-sprite'),
  6. portfinder = require('portfinder'),
  7. browserSync = require('browser-sync'),
  8. log = console.log;
  9. var that = this;
  10. that.port = +argv.p || undefined;
  11. var pkg = require('../package.json');
  12. var banner = '/*!' + '\n * @project : ' + pkg.name + '\n * @version : ' + pkg.version + '\n * @author : ' + pkg.author + '\n * @update : ' + moment().format('YYYY-MM-DD h:mm:ss a') + '\n */\r';
  13. gulp.task('rels_sass', function() {
  14. var config = {
  15. sourceComments: 'map',
  16. sourceMap: 'sass',
  17. style: 'compact',
  18. onError: function(err) { console.log('...err...: ' + err) }
  19. }
  20. return gulp.src('src/sass/**')
  21. .pipe(plugins.sass(config))
  22. .pipe(plugins.autoprefixer("last 1 version", "> 1%", "ie 8", "ie 7"))
  23. .pipe(gulp.dest('src/css'))
  24. })
  25. gulp.task('rels_css', ['rels_sass'], function() {
  26. return gulp.src('src/css/**/*.css')
  27. .pipe(plugins.minifyCss())
  28. .pipe(plugins.header(banner, { pkg : pkg } ))
  29. .pipe(gulp.dest('dest/css'))
  30. })
  31. gulp.task('rels_slice', function() {
  32. return gulp.src('src/slice/**')
  33. .pipe(gulp.dest('dest/slice'))
  34. })
  35. gulp.task('rels_sprite', ['rels_slice', 'rels_css'], function() {
  36. multiSprite({
  37. srcCss: 'dest/css',
  38. srcImg: 'dest/slice',
  39. destCss: 'dest/css',
  40. destImg: 'dest/img/sprite',
  41. 'algorithm': 'binary-tree',
  42. 'padding': 4,
  43. 'exportOpts': {
  44. 'format': 'png',
  45. 'quality': 90
  46. },
  47. successCB: function(){
  48. del(['dest/slice/**'])
  49. }
  50. })
  51. })
  52. gulp.task('rels_js', function() {
  53. return gulp.src('src/js/**')
  54. .pipe(plugins.uglify())
  55. .pipe(plugins.header(banner, { pkg : pkg } ))
  56. .pipe(gulp.dest('dest/js'))
  57. })
  58. gulp.task('rels_img', function() {
  59. return gulp.src('src/img/**')
  60. .pipe(plugins.imagemin({
  61. progressive: true
  62. }))
  63. .pipe(gulp.dest('dest/img'))
  64. })
  65. gulp.task('rels_html', function() {
  66. return gulp.src(['src/*.html'])
  67. .pipe(gulp.dest('dest'))
  68. })
  69. gulp.task('rels_clean', function() {
  70. del.sync(['dest/**'])
  71. })
  72. gulp.task('release', ['rels_clean', 'rels_html', 'rels_sprite', 'rels_js', 'rels_img'], function(){
  73. portfinder.getPort(function (err, port) {
  74. browserSync({
  75. server: {
  76. baseDir: "dest",
  77. directory: true
  78. },
  79. notify: false,
  80. codeSync: false,
  81. port: that.port||port,
  82. open: "external",
  83. browser: "/Applications/Google\ Chrome.app/"
  84. })
  85. })
  86. })
  87. gulp.task('dest', function(){
  88. portfinder.getPort(function (err, port) {
  89. browserSync({
  90. server: {
  91. baseDir: "dest",
  92. directory: true
  93. },
  94. notify: false,
  95. codeSync: false,
  96. port: that.port||port,
  97. open: "external",
  98. browser: "/Applications/Google\ Chrome.app/"
  99. })
  100. })
  101. })
  102. }