1 | _ = require 'lodash'
|
2 | del = require 'del'
|
3 | gulp = require 'gulp'
|
4 | karma = require('karma').server
|
5 | rename = require 'gulp-rename'
|
6 | webpack = require 'gulp-webpack'
|
7 | nodemon = require 'gulp-nodemon'
|
8 | coffeelint = require 'gulp-coffeelint'
|
9 | RewirePlugin = require 'rewire-webpack'
|
10 | webpackSource = require 'webpack'
|
11 |
|
12 | karmaConf = require './karma.defaults'
|
13 | packangeConf = require './package.json'
|
14 |
|
15 | paths =
|
16 | coffee: ['./src/**/*.coffee', './*.coffee', './test/**/*.coffee']
|
17 | rootScripts: './src/index.coffee'
|
18 | rootTests: './test/index.coffee'
|
19 | dist: './dist/'
|
20 | build: './build/'
|
21 |
|
22 | gulp.task 'demo', ->
|
23 | gulp.start 'server'
|
24 |
|
25 | gulp.task 'assets:prod', [
|
26 | 'scripts:prod'
|
27 | ]
|
28 |
|
29 | gulp.task 'build', ['clean:dist', 'scripts:dist']
|
30 |
|
31 | gulp.task 'test', ['scripts:test', 'lint'], (cb) ->
|
32 | karma.start _.defaults(singleRun: true, karmaConf), cb
|
33 |
|
34 | gulp.task 'watch', ->
|
35 | gulp.watch paths.coffee, ['test:phantom']
|
36 |
|
37 | gulp.task 'test:phantom', ['scripts:test'], (cb) ->
|
38 | karma.start _.defaults({
|
39 | singleRun: true,
|
40 | browsers: ['PhantomJS']
|
41 | }, karmaConf), cb
|
42 |
|
43 | gulp.task 'lint', ->
|
44 | gulp.src paths.coffee
|
45 | .pipe coffeelint()
|
46 | .pipe coffeelint.reporter()
|
47 |
|
48 | gulp.task 'scripts:test', ->
|
49 | gulp.src paths.rootTests
|
50 | .pipe webpack
|
51 | devtool: '#inline-source-map'
|
52 | module:
|
53 | postLoaders: [
|
54 | { test: /\.coffee$/, loader: 'transform/cacheable?envify' }
|
55 | ]
|
56 | loaders: [
|
57 | { test: /\.coffee$/, loader: 'coffee' }
|
58 | { test: /\.json$/, loader: 'json' }
|
59 | ]
|
60 | plugins: [
|
61 | new RewirePlugin()
|
62 | ]
|
63 | resolve:
|
64 | extensions: ['.coffee', '.js', '.json', '']
|
65 | modulesDirectories: ['node_modules', './src']
|
66 | .pipe rename 'tests.js'
|
67 | .pipe gulp.dest paths.build
|
68 |
|
69 | gulp.task 'test:phantom', ['scripts:test'], (cb) ->
|
70 | karma.start _.defaults({
|
71 | singleRun: true,
|
72 | browsers: ['PhantomJS']
|
73 | }, karmaConf), cb
|
74 |
|
75 | gulp.task 'clean:dist', (cb) ->
|
76 | del paths.dist, cb
|
77 |
|
78 | gulp.task 'server', ->
|
79 | nodemon {script: 'bin/dev_server.coffee', ext: 'null', ignore: ['**/*.*']}
|
80 |
|
81 | gulp.task 'scripts:dist', ->
|
82 | gulp.src paths.rootScripts
|
83 | .pipe webpack
|
84 | module:
|
85 | postLoaders: [
|
86 | { test: /\.coffee$/, loader: 'transform/cacheable?envify' }
|
87 | ]
|
88 | loaders: [
|
89 | { test: /\.coffee$/, loader: 'coffee' }
|
90 | { test: /\.json$/, loader: 'json' }
|
91 | ]
|
92 | plugins: [
|
93 | new webpackSource.optimize.UglifyJsPlugin()
|
94 | ]
|
95 | resolve:
|
96 | extensions: ['.coffee', '.js', '.json', '']
|
97 | .pipe rename 'clay_sdk_base.js'
|
98 | .pipe gulp.dest paths.dist
|