-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cakefile
executable file
·213 lines (169 loc) · 6.13 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
fs = require 'fs'
{exec, spawn} = require 'child_process'
util = require 'util'
sys = require "sys"
path = require "path"
targetName = "psd"
###
CoffeeScript Options
###
strictMode = false
csSrcDir = "src"
csTargetDir = "lib"
depsDir = "deps"
targetCoffee = "#{csSrcDir}/build"
targetCoreJS = "#{csTargetDir}/#{targetName}.js"
targetCoreMinJS = "#{csTargetDir}/#{targetName}.min.js"
coffeeCoreOpts = "-j #{targetName}.js -o #{csTargetDir} -c #{targetCoffee}.coffee"
# All source files listed in include order
coffeeFiles = [
"psdassert"
"psdconstants"
"parser"
"psd"
"psdcolor"
"psddescriptor"
"psdfile"
"psdheader"
"psdimage"
"psdchannelimage"
"psdlayer"
"psdlayermask"
"layerdata/enginedataparser"
"layerdata/blackwhite"
"layerdata/brightnesscontrast"
"layerdata/colorbalance"
"layerdata/curves"
"layerdata/exposure"
"layerdata/gradient"
"layerdata/huesaturation"
"layerdata/invert"
"layerdata/layereffect"
"layerdata/levels"
"layerdata/pattern"
"layerdata/photofilter"
"layerdata/posterize"
"layerdata/selectivecolor"
"layerdata/solidcolor"
"layerdata/threshold"
"layerdata/typetool"
"layerdata/vibrance"
"psdresource"
"util"
"log"
]
###
Event System
###
finishedCallback = {}
finished = (type) ->
finishedCallback[type]() if finishedCallback[type]?
finishListener = (type, cb) ->
finishedCallback[type] = cb
###
Options
###
option '-f', '--file [FILE]', 'Test file to load (for debugging)'
###
Tasks
###
task 'debug', 'Run psd.js in debug mode with node-inspector', (opts) ->
throw "Must specify a file with -f" if not opts.file
debug = spawn 'coffee', ['--nodejs', '--debug-brk', opts.file]
debug.stdout.on 'data', (data) -> console.log data
insp = spawn 'node-inspector'
insp.stdout.on 'data', (data) -> util.log data
exec 'open http://127.0.0.1:8080/debug?port=5858'
task 'docs', 'Generates documentation for the coffee files', ->
util.log 'Invoking docco on the CoffeeScript source files'
files = coffeeFiles
files[i] = "#{csSrcDir}/#{files[i]}.coffee" for i in [0...files.length]
exec "./node_modules/docco/bin/docco #{files.join(' ')}", (err, stdout, stderr) ->
util.log err if err
util.log "Documentation built into docs/ folder."
task 'test', 'Run all unit tests', ->
reporter = require('nodeunit').reporters.default
process.chdir __dirname
console.log "=> Running unit tests"
reporter.run ['test/unit_tests'], null, ->
{TargetPractice} = require './test/targetpractice'
tp = new TargetPractice "psd.tp/**/*.json"
console.log "\n=> Running TargetPractice"
tp.runTests()
task 'watch', 'Automatically recompile the CoffeeScript files when updated', ->
util.log "Watching for changes in #{csSrcDir}"
for jsFile in coffeeFiles then do (jsFile) ->
fs.watchFile "#{csSrcDir}/#{jsFile}.coffee", (curr, prev) ->
if +curr.mtime isnt +prev.mtime
util.log "#{csSrcDir}/#{jsFile}.coffee updated"
invoke 'build'
invoke 'deploy'
task 'build', 'Compile and minify all CoffeeScript source files', ->
invoke 'compile'
task 'compile', 'Compile all CoffeeScript source files', (opts) ->
util.log "Building #{targetCoreJS}"
contents = []
remaining = coffeeFiles.length
util.log "Appending #{coffeeFiles.length} files to #{targetCoffee}.coffee"
for file, index in coffeeFiles then do (file, index) ->
fs.readFile "#{csSrcDir}/#{file}.coffee", "utf8", (err, fileContents) ->
util.log err if err
contents[index] = fileContents
util.log "[#{index + 1}] #{file}.coffee"
process() if --remaining is 0
process = ->
contents.unshift "###\nEND DEPENDENCIES\n###\n\n"
deps = fs.readdirSync depsDir
for dep in deps
util.log "Adding dependency #{dep}"
contents.unshift "`" + fs.readFileSync("#{depsDir}/#{dep}", "utf8") + "`\n\n"
contents.unshift fs.readFileSync("#{csSrcDir}/license.coffee") + "\n\n"
contents.unshift "\"use strict\"" if strictMode
core = contents.join("\n\n")
fs.writeFile "#{targetCoffee}.coffee", core, "utf8", (err) ->
util.log err if err
exec "./node_modules/.bin/coffee #{coffeeCoreOpts}", (err, stdout, stderr) ->
util.log err if err
util.log "Compiled #{targetCoreJS}"
fs.unlink "#{targetCoffee}.coffee"
finished('js')
task 'minify', 'Minify the CoffeeScript files', ->
util.log "Minifying #{targetCoreJS}"
fs.readFile targetCoreJS, "utf8", (err, contents) ->
fs.writeFile targetCoreMinJS, jsmin(contents), "utf8", (err) ->
util.log err if err
task 'run:worker', 'Run workers by listening to global redis queue', ->
ResqueTasks = require "./tasks"
Resque = require "./src/resque"
connection = Resque.get_connection()
worker = connection.worker "psdjs_processor", ResqueTasks
worker.on 'error', (err, worker, queue, job) ->
if jobs?
console.log "#{err} on running #{JSON.stringify(job.args)} on #{queue}"
else
console.log err
worker.on 'success', (worker, queue, job, result) ->
console.log "Successfully ran #{JSON.stringify(job.args)} on #{queue}."
worker.start()
task 'test:enqueue', 'Testing resque job queue by populating dummy objects', ->
Resque = require "coffee-resque"
connection = Resque.connect()
design_data = {
"user": "[email protected]"
"design": "Social_Media_Buttons_PSD_psd-5015d36e4588ce0008000001"
"store": "store_production"
}
connection.enqueue 'psdjs_processor', 'PsdjsProcessorJob', [design_data]
task 'test:walk', 'walking', ->
FileUtils = require "file"
test_folder = '/tmp/store/[email protected]/Social_Media_Buttons_PSD_psd-5015d36e4588ce0008000001/psdjsprocessed'
FileUtils.walk test_folder, (dummy, dirPath, dirs, files) ->
for file in files
relative_path = path.relative(path.join("/tmp", "store"), file)
task 'test:config', 'config variables', ->
yaml = require "js-yaml"
config_file = require "./local_constants.yml"
console.log config_file
task 'deploy', 'Copy files to transformer-web project', ->
exec 'cp lib/psd.js ../transformers-web/lib/psdjs'
exec 'cp package.json ../transformers-web/lib/psdjs'