-
Notifications
You must be signed in to change notification settings - Fork 9
/
Cakefile
264 lines (241 loc) · 8.83 KB
/
Cakefile
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
fs = require 'fs'
{print} = require 'util'
{spawn, exec} = require 'child_process'
jade = require 'jade'
path = require 'path'
{_} = require 'underscore'
views_conf =
'./src/templates/project_item.jade' : './lib/public/lib/templates/project_item.js'
'./src/templates/output_item.jade' : './lib/public/lib/templates/output_item.js'
'./src/templates/main.jade' : './lib/public/lib/templates/main.js'
'./src/templates/console.jade' : './lib/public/lib/templates/console.js'
'./src/templates/new_project.jade' : './lib/public/lib/templates/new_project.js'
'./src/templates/url_input.jade' : './lib/public/lib/templates/url_input.js'
'./src/templates/output_switch.jade' : './lib/public/lib/templates/output_switch.js'
'./src/templates/outline_info.jade' : './lib/public/lib/templates/outline_info.js'
'./src/templates/editor.jade' : './lib/public/lib/templates/editor.js'
'./src/templates/file_item.jade' : './lib/public/lib/templates/file_item.js'
'./src/templates/tab_switch.jade' : './lib/public/lib/templates/tab_switch.js'
'./src/templates/mode_switch.jade' : './lib/public/lib/templates/mode_switch.js'
'./src/templates/settings.jade' : './lib/public/lib/templates/settings.js'
'./src/templates/warning_browser.jade': './lib/public/lib/templates/warning_browser.js'
'./src/templates/warning_disconnect.jade': './lib/public/lib/templates/warning_disconnect.js'
'./src/templates/warning_overload.jade': './lib/public/lib/templates/warning_overload.js'
build = (watch, callback) ->
if typeof watch is 'function'
callback = watch
watch = false
options = ['-c', '-o', 'lib', 'src']
options.unshift '-w' if watch
coffee = spawn './node_modules/.bin/coffee', options
coffee.stdout.on 'data', (data) -> print data.toString()
coffee.stderr.on 'data', (data) -> print data.toString()
coffee.on 'exit', (status) -> callback?() if status is 0
build_views views_conf, watch
build_stylus watch
build_views = (conf, watch) ->
runtime = fs.readFileSync (path.resolve (require.resolve 'jade'), '../runtime.min.js')
views = ""
_.each conf, (outfile, infile) ->
data = jade.compile(fs.readFileSync(infile),compileDebug: false, client:true).toString()
out = """
define(function(require, exports, module){
require("vendor/jade");
module.exports = #{data};
});
"""
fs.writeFileSync outfile, out
console.log "Compiled #{outfile}"
if watch
fs.watchFile infile, (curr, prev) ->
if curr.mtime.getTime() != prev.mtime.getTime()
prop = {}
prop[infile] = outfile
build_views prop, false
build_stylus = (watch) ->
options = ['--out', 'lib/public/css/', '--include', 'node_modules/nib/lib', 'src/style']
options.unshift '-w' if watch
#console.log 'stylus', options
stylus = spawn './node_modules/.bin/stylus', options
stylus.stdout.on 'data', (data) -> print data.toString()
stylus.stderr.on 'data', (data) -> print data.toString()
task 'docs', 'Generate annotated source code with Docco', ->
fs.readdir 'src/public/lib', (err, contents) ->
files = ("src/public/lib/#{file}" for file in contents when /\.coffee$/.test file)
docco = spawn 'docco', files
docco.stdout.on 'data', (data) -> print data.toString()
docco.stderr.on 'data', (data) -> print data.toString()
docco.on 'exit', (status) -> callback?() if status is 0
task 'build', 'Compile CoffeeScript source files', ->
build()
task 'watch', 'Recompile CoffeeScript source files when modified', ->
build true
task 'test', 'Run the test suite', ->
build ->
require.paths.unshift __dirname + "/lib"
{reporters} = require 'nodeunit'
process.chdir __dirname
reporters.default.run ['test']
task 'jade', 'Prebuild views', ->
build_views views_conf
task 'stylus', 'Build stylus files to css', ->
build_stylus()
task 'dryice', 'Build compressed modules', ->
{copy} = require(__dirname + '/support/dryice')
targetDir = __dirname + '/lib/public/build'
filter = (input)->
input = input.replace /vendor\/text!/g, 'text!'
#input = input.replace /ace\/requirejs\/text!(\.|ace)\//, 'vendor/text_'
input = input.replace /text!/g, 'text_'
input = input.replace /ace\/requirejs\/text_(\.|ace)/g, 'text_ace'
input = input.replace /vendor\/link![^"']+/g, 'empty'
input
filters = [copy.filter.moduleDefines, filter]#, copy.filter.uglifyjs]
copy({
source: (root: __dirname + '/lib/public/css', include: /.*\.css$/),
#filter: [copy.filter.uglifyjs],
dest: __dirname + '/lib/public/build/styles.css'
});
project = copy.createCommonJsProject
roots: [
__dirname + '/support/ace/lib'
__dirname + '/lib/public'
]
ignores: [ 'css/editorview.css' ]
textPluginPattern: /^(vendor|ace\/requirejs)\/text!/
ace = copy.createDataObject();
copy({
source: (value: 'window.__packaged = true;'),
dest: ace
});
copy({
source: [__dirname + "/lib/public/vendor/require.js"],
dest: ace,
filter: [copy.filter.moduleDefines],
});
copy({
source: (value: 'define("empty");' + (fs.readFileSync (path.resolve (require.resolve 'jade'), '../runtime.min.js')) + ';define("vendor/jade", jade);'),
dest: ace
});
project.ignoredModules = 'vendor/jade': true, 'vendor/link!': true
copy({
source: [
{
project: (project),
require: [ 'vendor/underscore', 'vendor/zepto' ,'vendor/backbone', 'lib/backbone-socketio']
}
],
filter: [copy.filter.moduleDefines],
dest: ace
})
project.assumeAllFilesLoaded()
copy({
source: [
{
project: (project),
require: [ 'lib/main_build', 'lib/models', 'lib/router', 'lib/views/app', 'lib/views/warning-screen', 'lib/utils']
}
],
filter: filters,
dest: ace
})
copy(source: ace, dest: __dirname + '/lib/public/build/main.js')
project.assumeAllFilesLoaded()
copy({
source: [
{
project: (project),
require: [ 'lib/views/console', 'lib/views/editor' ]
}
],
filter: filters,
dest: __dirname + '/lib/public/build/editor.js'
})
project.assumeAllFilesLoaded()
copy({
source: [
{
project: (project),
require: [ 'lib/editor/autocompleter', 'lib/views/ui/completer', 'lib/views/commandline', 'lib/views/ui/search', 'lib/editor/mousecommands', 'lib/editor/statsmanager' ]
}
],
filter: filters,
dest: __dirname + '/lib/public/build/editor-defer.js'
})
project.assumeAllFilesLoaded()
copy({
source: [
{
project: (project),
require: [ 'lib/views/ui/popup', 'lib/views/ui/imagepreview', 'lib/views/ui/infotip', 'vendor/colorpicker' ]
}
],
filter: filters,
dest: __dirname + '/lib/public/build/editor-optional.js'
})
project.assumeAllFilesLoaded()
copy({
source: [
{
project: (project),
require: [ 'lib/views/newproject', 'lib/views/ui/dirpicker' ]
}
],
filter: [copy.filter.moduleDefines, filter], # , copy.filter.uglifyjs
dest: __dirname + '/lib/public/build/newproject.js'
})
project.assumeAllFilesLoaded()
copy({
source: [
{
project: (project),
require: [ 'lib/views/settings' ]
}
],
filter: [copy.filter.moduleDefines, filter], # , copy.filter.uglifyjs
dest: __dirname + '/lib/public/build/settings.js'
})
project.assumeAllFilesLoaded()
for mode in ['css', 'stylus']
console.log 'Mode for', mode
copy({
source: [
{
project: (project),
require: [ 'lib/editor/' + mode , 'lib/editor/' + mode + 'manager' ]
}
],
filter:filters,
dest: targetDir + "/mode-" + mode + '.js'
});
for mode in ['css', 'stylus']
console.log("worker for " + mode + " mode")
worker = copy.createDataObject()
workerProject = copy.createCommonJsProject
roots: [
__dirname + '/support/ace/lib'
__dirname + '/lib/public'
]
#textPluginPattern: /^ace\/requirejs\/text!/
copy({
source: [
{
project: workerProject,
require: [
'ace/lib/fixoldbrowsers',
'ace/lib/event_emitter',
'ace/lib/oop',
'lib/editor/' + mode + '_worker'
]
}
],
filter: [ copy.filter.moduleDefines ],
dest: worker
});
copy({
source: [
__dirname + "/support/ace/lib/ace/worker/worker.js",
worker
],
dest: targetDir + "/worker-" + mode + ".js"
});