1 | path = require 'path'
|
2 | require 'isomorphic-fetch'
|
3 |
|
4 | allowCorsMiddleware = (req, res, next) ->
|
5 | res.setHeader 'Access-Control-Allow-Origin', '*'
|
6 | next()
|
7 |
|
8 | module.exports = ->
|
9 |
|
10 | pkg = @file.readJSON 'package.json'
|
11 |
|
12 | @initConfig
|
13 | pkg: @file.readJSON 'package.json'
|
14 |
|
15 |
|
16 | yaml:
|
17 | schemas:
|
18 | files: [
|
19 | expand: true
|
20 | cwd: 'schemata/'
|
21 | src: '*.yaml'
|
22 | dest: 'schema/'
|
23 | ]
|
24 |
|
25 |
|
26 | webpack:
|
27 | build: require './webpack.config.js'
|
28 |
|
29 | watch:
|
30 | src:
|
31 | files: [
|
32 | "src/**/*"
|
33 | "examples/**/*"
|
34 | "spec/**/*"
|
35 | ]
|
36 | tasks: "test"
|
37 | options:
|
38 | livereload: true
|
39 |
|
40 | exec:
|
41 | runtime:
|
42 | command: 'python2 protocol-examples/python/runtime.py --port 3334'
|
43 |
|
44 |
|
45 | connect:
|
46 | server:
|
47 | options:
|
48 | port: 8000
|
49 | livereload: true
|
50 | middleware: (connect, options, middlewares) ->
|
51 | middlewares.unshift allowCorsMiddleware
|
52 | return middlewares
|
53 |
|
54 |
|
55 | yamllint:
|
56 | schemas: ['schemata/*.yaml']
|
57 | examples: ['examples/*.yml']
|
58 |
|
59 | coffeelint:
|
60 | components: ['Gruntfile.coffee', 'spec/*.coffee']
|
61 | options:
|
62 | 'max_line_length':
|
63 | 'level': 'ignore'
|
64 |
|
65 |
|
66 | mochaTest:
|
67 | nodejs:
|
68 | src: ['spec/*.coffee']
|
69 | options:
|
70 | reporter: 'spec'
|
71 | require: 'coffeescript/register'
|
72 | grep: process.env.TESTS
|
73 |
|
74 |
|
75 | coffee:
|
76 | options:
|
77 | bare: true
|
78 | transpile:
|
79 | presets: ['es2015']
|
80 | lib:
|
81 | expand: true
|
82 | cwd: 'src'
|
83 | src: ['**.coffee']
|
84 | dest: 'lib'
|
85 | ext: '.js'
|
86 | schema:
|
87 | expand: true
|
88 | cwd: 'schema'
|
89 | src: ['**.coffee']
|
90 | dest: 'schema'
|
91 | ext: '.js'
|
92 | browser:
|
93 | expand: true
|
94 | cwd: 'browser'
|
95 | src: ['**.coffee']
|
96 | dest: 'browser'
|
97 | ext: '.js'
|
98 | examples:
|
99 | expand: true
|
100 | cwd: 'examples'
|
101 | src: ['**.coffee']
|
102 | dest: 'examples'
|
103 | ext: '.js'
|
104 | spec:
|
105 | expand: true
|
106 | cwd: 'spec'
|
107 | src: '*.coffee'
|
108 | dest: 'browser/spec'
|
109 | ext: '.js'
|
110 |
|
111 | downloadfile:
|
112 | files: [
|
113 | { url: 'https://noflojs.org/noflo-browser/everything.html', dest: 'spec/fixtures' }
|
114 | { url: 'https://noflojs.org/noflo-browser/everything.js', dest: 'spec/fixtures' }
|
115 | ]
|
116 |
|
117 |
|
118 | mocha_phantomjs:
|
119 | all:
|
120 | options:
|
121 | output: 'spec/result.xml'
|
122 | reporter: 'spec'
|
123 | urls: ['http://localhost:8000/spec/runner.html']
|
124 | failWithOutput: true
|
125 |
|
126 |
|
127 | copy:
|
128 | ui:
|
129 | files: [ expand: true, cwd: './ui/', src: '*', dest: './browser/' ]
|
130 |
|
131 | 'gh-pages':
|
132 | options:
|
133 | base: 'browser/',
|
134 | user:
|
135 | name: 'fbp-spec bot',
|
136 | email: 'jononor+fbpspecbot@gmail.com'
|
137 | silent: true
|
138 | repo: 'https://' + process.env.GH_TOKEN + '@github.com/flowbased/fbp-spec.git'
|
139 | src: '**/*'
|
140 |
|
141 |
|
142 | @loadNpmTasks 'grunt-yaml'
|
143 | @loadNpmTasks 'grunt-webpack'
|
144 | @loadNpmTasks 'grunt-contrib-watch'
|
145 |
|
146 |
|
147 | @loadNpmTasks 'grunt-yamllint'
|
148 | @loadNpmTasks 'grunt-coffeelint'
|
149 | @loadNpmTasks 'grunt-contrib-coffee'
|
150 | @loadNpmTasks 'grunt-mocha-test'
|
151 | @loadNpmTasks 'grunt-contrib-connect'
|
152 | @loadNpmTasks 'grunt-mocha-phantomjs'
|
153 | @loadNpmTasks 'grunt-exec'
|
154 |
|
155 | @registerTask 'examples:bundle', =>
|
156 | examples = require './examples'
|
157 | examples.bundle()
|
158 |
|
159 |
|
160 | @loadNpmTasks 'grunt-contrib-copy'
|
161 | @loadNpmTasks 'grunt-gh-pages'
|
162 |
|
163 |
|
164 | grunt = @
|
165 | @registerMultiTask 'downloadfile', 'Download a file', ->
|
166 | callback = @async()
|
167 | promises = @data.map (conf) ->
|
168 | fetch(conf.url)
|
169 | .then (res) ->
|
170 | return res.text()
|
171 | .then (content) ->
|
172 | filename = path.basename conf.url
|
173 | location = path.join conf.dest, path.sep, filename
|
174 | grunt.file.write location, content
|
175 | console.log "Wrote #{conf.url} to #{location}"
|
176 | return true
|
177 | Promise.all promises
|
178 | .then ->
|
179 | do callback
|
180 | , (err) ->
|
181 | callback err
|
182 |
|
183 | @registerTask 'build', 'Build', (target = 'all') =>
|
184 | @task.run 'yaml'
|
185 | @task.run 'coffee'
|
186 | @task.run 'webpack'
|
187 | @task.run 'examples:bundle'
|
188 | @task.run 'copy:ui'
|
189 |
|
190 | @registerTask 'test', 'Build and run tests', (target = 'all') =>
|
191 | @task.run 'coffeelint'
|
192 | @task.run 'yamllint'
|
193 | @task.run 'build'
|
194 | @task.run 'mochaTest'
|
195 | if target != 'nodejs'
|
196 | @task.run 'downloadfile'
|
197 | @task.run 'connect'
|
198 | @task.run 'mocha_phantomjs'
|
199 |
|
200 | @registerTask 'default', ['test']
|
201 |
|
202 | @registerTask 'uidev', ['connect:server:keepalive']
|
203 |
|
204 | @registerTask 'dev', 'Developing', (target = 'all') =>
|
205 | @task.run 'test'
|
206 | @task.run 'watch'
|