Blame view

node_modules/mockjs/gulpfile.js 4.87 KB
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  var gulp = require('gulp')
  var jshint = require('gulp-jshint')
  var webpack = require("webpack")
  var connect = require('gulp-connect')
  var mochaPhantomJS = require('gulp-mocha-phantomjs')
  var exec = require('child_process').exec
  
  var istanbul = require('gulp-istanbul')
  var mocha = require('gulp-mocha')
  var coveralls = require('gulp-coveralls')
  
  // 
  gulp.task('hello', function() {
      console.log((function() {
          /*
  ___  ___              _        _      
  |  \/  |             | |      (_)     
  | .  . |  ___    ___ | | __    _  ___ 
  | |\/| | / _ \  / __|| |/ /   | |/ __|
  | |  | || (_) || (__ |   <  _ | |\__ \
  \_|  |_/ \___/  \___||_|\_\(_)| ||___/
                               _/ |     
                              |__/    
          */
      }).toString().split('\n').slice(2, -2).join('\n') + '\n')
  })
  
  // https://github.com/AveVlad/gulp-connect
  gulp.task('connect', function() {
      /* jshint unused:false */
      connect.server({
          port: 5050,
          middleware: function(connect, opt) {
              return [
                  // https://github.com/senchalabs/connect/#use-middleware
                  function cors(req, res, next) {
                      res.setHeader('Access-Control-Allow-Origin', '*')
                      res.setHeader('Access-Control-Allow-Methods', '*')
                      next()
                  }
              ]
          }
      })
  })
  
  // https://github.com/spenceralger/gulp-jshint
  gulp.task('jshint', function() {
      var globs = [
          'src/**/*.js', 'test/test.*.js', 'gulpfile.js', '!**/regexp/parser.js'
      ]
      return gulp.src(globs)
          .pipe(jshint('.jshintrc'))
          .pipe(jshint.reporter('jshint-stylish'))
  })
  
  // https://webpack.github.io/docs/usage-with-gulp.html
  gulp.task("webpack", function( /*callback*/ ) {
      webpack({
          entry: './src/mock.js',
          output: {
              path: './dist',
              filename: 'mock.js',
              library: 'Mock',
              libraryTarget: 'umd'
          }
      }, function(err /*, stats*/ ) {
          // console.log(err, stats)
          if (err) throw err
      })
      webpack({
          entry: './src/mock.js',
          devtool: 'source-map',
          output: {
              path: './dist',
              filename: 'mock-min.js',
              library: 'Mock',
              libraryTarget: 'umd'
          },
          plugins: [
              new webpack.optimize.UglifyJsPlugin({
                  minimize: true
              })
          ]
      }, function(err /*, stats*/ ) {
          // console.log(err, stats)
          if (err) throw err
      })
  })
  
  // https://github.com/mrhooray/gulp-mocha-phantomjs
  gulp.task('mocha', function() {
      return gulp.src('test/test.mock.html')
          .pipe(mochaPhantomJS({
              reporter: 'spec'
          }))
  })
  
  
  // https://github.com/floatdrop/gulp-watch
  var watchTasks = ['hello', 'madge', 'jshint', 'webpack', 'mocha']
  gulp.task('watch', function( /*callback*/ ) {
      gulp.watch(['src/**/*.js', 'gulpfile.js', 'test/*'], watchTasks)
  })
  
  // https://github.com/pahen/madge
  gulp.task('madge', function( /*callback*/ ) {
      exec('madge ./src/',
          function(error, stdout /*, stderr*/ ) {
              if (error) console.log('exec error: ' + error)
              console.log('module dependencies:')
              console.log(stdout)
          }
      )
      exec('madge --image ./src/dependencies.png ./src/',
          function(error /*, stdout, stderr*/ ) {
              if (error) console.log('exec error: ' + error)
          }
      )
  })
  
  // TODO
  
  // https://github.com/SBoudrias/gulp-istanbul
  gulp.task('istanbul', function(cb) {
      gulp.src(['test/test.coveralls.js'])
          .pipe(istanbul()) // Covering files
          .pipe(istanbul.hookRequire()) // Force `require` to return covered files
          .on('finish', function() {
              gulp.src(['test/test.coveralls.js'])
                  .pipe(mocha({}))
                  .pipe(istanbul.writeReports()) // Creating the reports after tests runned
                  .on('end', cb)
          })
  })
  gulp.task('istanbulForMochaPhantomJS', function(cb) {
      gulp.src(['dist/mock.js'])
          .pipe(istanbul()) // Covering files
          .pipe(istanbul.hookRequire()) // Force `require` to return covered files
          .on('finish', function() {
              gulp.src(['test/test.mock.html'])
                  .pipe(mochaPhantomJS({
                      reporter: 'spec'
                  }))
                  .pipe(istanbul.writeReports()) // Creating the reports after tests runned
                  .on('end', cb)
          })
  })
  
  // https://github.com/markdalgleish/gulp-coveralls
  gulp.task('coveralls', ['istanbul'], function() {
      return gulp.src('coverage/**/lcov.info')
          .pipe(coveralls())
  })
  
  // 
  gulp.task('publish', function() {
      var child_process = require('child_process')
      child_process.exec('ls', function(error, stdout, stderr) {
          console.log(error, stdout, stderr)
      })
  })
  
  gulp.task('default', watchTasks.concat(['watch', 'connect']))
  gulp.task('build', ['jshint', 'webpack', 'mocha'])