-
Notifications
You must be signed in to change notification settings - Fork 53
/
Cakefile.windows
217 lines (183 loc) · 7.01 KB
/
Cakefile.windows
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
fs = require 'fs'
{spawn, exec} = require 'child_process'
path = require 'path'
findit = require 'findit'
util = require 'util'
glob = require 'glob'
{print} = require 'sys'
mkdirp = require 'mkdirp'
watcher = require 'watch-tree-maintained'
requirejs = require 'requirejs'
requirejs.config
baseUrl: '.\\build\\js',
nodeRequire: require
global.define = require('requirejs');
SRCDIR=".\\src"
TGTDIR="."
find_all = (srcdir, src_prefix) ->
mkr = (r) -> new RegExp r.replace /\./, '\\.'
twoDigits = (val) ->
if val < 10 then return "0#{val}"
return val
#######################################
build = (src_extension, targ_extension, command, options) ->
findit.find(SRCDIR).on 'file', (source, stats) ->
if path.extname(source) == src_extension
source_path = path.dirname(source)
source_file = path.basename(source)
target_path = source_path.replace(mkr('^' + SRCDIR), TGTDIR)
target = path.join(target_path, source_file)
target_file = path.basename(target)
fs.mkdir target_path, '0755', (err) ->
#if err and err.code != 'EEXIST'
#console.log err
#throw err
cmd = command.replace(/\$source/, source)
.replace(/\$target_path/, target_path)
.replace(/\$source_path/, source_path)
.replace(/\$target_file/, target_file)
.replace(/\$source_file/, source_file)
.replace(/\$target/, target)
exec cmd, (error, stderr, stdout) ->
if error
throw source + ' ' + error
if options.verbose
console.log(stdout)
if stderr
console.log(stderr)
copyTemplate = (src_path)->
file = src_path
rootdir = file.split(path.sep)[0]
if rootdir == "src"
fileName = path.basename(file)
splitPath = file.split(path.sep)
outPath = splitPath[1..splitPath.length-2].join(path.sep)
splitBase = __filename.split(path.sep)
basePath = splitBase[0..splitBase.length-2].join(path.sep)
inPath = basePath+path.sep+file
outPath = basePath+path.sep+ outPath+"\\"
#print "Copying #{inPath} to #{outPath}\n\n"
mkdirp outPath, '0755', (err) ->
if err and err.code != 'EEXIST'
throw err
outPath = outPath+ fileName
cp = spawn 'copy', [inPath, outPath]
cp.stderr.on 'data', (data) ->
process.stderr.write data.toString()
cp.stdout.on 'data', (data) ->
util.log data.toString()
ts = new Date()
ts = "#{twoDigits(ts.getHours())}:#{twoDigits(ts.getMinutes())}:#{twoDigits(ts.getSeconds())}"
print("#{ts} - copied #{src_path}\n")
deleteTemplate = (src_path)->
file = src_path
rootdir = file.split(path.sep)[0]
fileName = path.basename(file)
splitPath = file.split(path.sep)
outPath = splitPath[1..splitPath.length-2].join(path.sep)
splitBase = __filename.split(path.sep)
basePath = splitBase[0..splitBase.length-2].join(path.sep)
inPath = basePath+path.sep+file
outPath = basePath+path.sep+ outPath+"\\"+ fileName
fs.unlink outPath, (err) ->
if (err) then throw err
ts = new Date()
ts = "#{twoDigits(ts.getHours())}:#{twoDigits(ts.getMinutes())}:#{twoDigits(ts.getSeconds())}"
print("#{ts} - deleted #{src_path}\n")
task 'test', 'run unit tests',(options) ->
exec('jasmine-node --coffee --verbose .\\src\\test\\spec\\editors', (err, stdout, stderr) ->
if err
process.stderr.write(stderr)
else
process.stdout.write(stdout)
)
task 'docs', 'generate api documentation', (options) ->
#coffeedoc = spawn 'coffeedoc.cmd' , []
exec "coffeedoc --output .\\doc\\api --parser commonjs .\\src\\app"
task 'watch', 'Watch src for changes',(options) ->
coffee = spawn 'coffee.cmd', ['--bare','-w', '-c', '-o', TGTDIR, SRCDIR]
#watchTree's match does not work correctly for newly created files hence the hacks below
watcher = watcher.watchTree("src", {'sample-rate': 2})#,'match':'(.*)[.]tmpl'})
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
print data.toString()
watcher.on 'filePreexisted', (srcPath,stats)->
if path.extname(srcPath) == ".tmpl"
copyTemplate(srcPath)
watcher.on 'fileCreated', (srcPath, stats) ->
if path.extname(srcPath) == ".tmpl"
copyTemplate(srcPath)
watcher.on 'fileModified', (srcPath, stats) ->
if path.extname(srcPath) == ".tmpl"
copyTemplate(srcPath)
watcher.on 'fileDeleted', (srcPath) ->
if path.extname(srcPath) == ".tmpl"
deleteTemplate(srcPath)
task 'serve', 'minimal web server for testing', (options) ->
connect = require('connect')
servePath = path.resolve('.')
server = connect.createServer connect.static(servePath)
console.log "Sever starting: at http://127.0.0.1:8090/"
server.listen(8090)
task 'serveWatch', 'serve the files and run the watch task', (options) ->
invoke('serve')
invoke('watch')
task 'cpTemplates', 'Copy all templates into the correct folders', ->
exec "xcopy/s/y .\\src\\*.tmpl ."
task 'build', 'build all the components', (options) ->
invoke('cpTemplates')
exec "coffee --compile -o . .\\src"
task 'release', 'build, minify , prep for release' , (options) ->
#test buildconf for csg sub package
buildConf = {
baseUrl: "app",
dir: "build",
#mainConfigFile: "app\\main.js",
modules:[
{
name: "modules\\core\\projects\\csg\\csg"
}
],
optimize: "none"
}
#full build conf
buildConf = {
baseUrl: "app",
#dir: "build",
mainConfigFile: "app\\main.js",
out: 'build\\main.min.js'
name:".",
optimize: "uglify",
#removeCombined:true
}
###
c = {baseUrl: 'app'
,name: 'main.max'
,out: 'build\\app\\main.min.js'
,optimize:'uglify'}###
requirejs.optimize(buildConf, console.log)
task 'package_alt', 'package project for node-webkit', (options) ->
zip = new require('node-zip')()
finder = findit.find("app")
finder.on 'file', (source, stats) =>
console.log "file: "+ source
if path.extname(source) == ".js"
fs.readFile source, null, (err,data)->
if (err)
return console.log(err)
console.log(data)
zip.file(source,data)
finder.on 'end', ()=>
console.log "done"
data = zip.generate({base64:false,compression:'DEFLATE'})
fs.writeFile('coffeescad.nw', data, 'binary');
task 'package' , 'package project for node-webkit', (options) ->
pkgFile = 'CoffeeSCad.nw'
zip = spawn('zip', ['-9', '-r', pkgFile, '.\\app', '.\\assets', 'index.html','package.json','favicon.ico','readme.md'])
###
zip.on 'exit', (code, signal)->
zip2 = spawn('zip', ['-9', '-r', '-g', 'toto.zip', '.\\assets', 'index.html'])
zip2.on 'exit', (code, signal)->
zip3 = spawn('zip', ['-9', '-r', '-g', 'toto.zip', 'package.json'])
###