-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCakefile
More file actions
97 lines (86 loc) · 3.22 KB
/
Copy pathCakefile
File metadata and controls
97 lines (86 loc) · 3.22 KB
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
fs = require 'fs'
path = require 'path'
{exec} = require 'child_process'
# Constants
masterVersion = '2.0'
# omit src/ and .js to make the below lines a little shorter
baseLibFiles = [
'header'
]
libFiles =
'1.0': baseLibFiles.concat [
'footer']
'1.1': baseLibFiles.concat [
'footer']
'2.0': baseLibFiles.concat [
'canvas-snapshot'
'footer']
'2.0-lite': baseLibFiles.concat [
'canvas-snapshot'
'footer']
concatSrcFiles = (files, callback) ->
contents = new Array files.length
remaining = files.length
for file, index in files then do (file, index) ->
fs.readFile "src/#{file}.js", 'utf8', (err, fileContents) ->
throw err if err
contents[index] = fileContents
(callback contents) if --remaining is 0 and callback?
task 'build', "Concatenate source files into a single library file", ->
exec "mkdir -p 'build'", (err, stdout, stderr) ->
# Translate concatenated file
output = (version) -> (contents) ->
distFileName = "dist/glquery-ext-#{version}.js"
fs.writeFile distFileName, (contents.join '\n'), 'utf8', (err) ->
throw err if err
console.log "...Done(#{distFileName})"
if version == masterVersion
((fs.createReadStream distFileName).pipe fs.createWriteStream 'dist/glquery-ext.js').on "close", ->
console.log "...Done(dist/glquery-ext.js)"
return
return
return
# Concatenate files
for version, files of libFiles
concatSrcFiles files, output version
return
task 'fetch:npm', "Fetch the npm package manager", ->
exec "curl http://npmjs.org/install.sh | sudo sh", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "...Done(fetch npm package manager)"
task 'fetch:uglifyjs', "Fetch the UglifyJS minification tool", ->
exec "npm install uglify-js", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "...Done(fetch UglifyJS)"
###
task 'fetch:extra-modules', "Fetch additional glquery modules that are useful", ->
fileNames = [
'glquery.math.module.js',
'glquery.math.module.min.js']
repoUrl = 'https://github.com/glQuery/glQuery-math/raw/master/dist'
wgetCommand = ""
for fileName in fileNames
wgetCommand += "wget -q -O dist/extra/#{fileName} #{repoUrl}/#{fileName};"
exec wgetCommand, (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "...Done(fetch extra modules)"
###
task 'minify', "Minify the resulting application file after build", ->
path.exists 'node_modules/.bin/uglifyjs', (exists) ->
if exists
exec "node_modules/.bin/uglifyjs dist/glquery-ext.js --comments /publicdomain/ > dist/glquery-ext.min.js", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "...Done(minify)"
else
exec "uglifyjs dist/glquery-ext.js > dist/glquery-ext.min.js", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
console.log "...Done(minify)"
task 'clean', "Cleanup all build files and distribution files", ->
exec "rm -rf build;rm dist/glquery-ext.js;rm dist/glquery-ext.min.js", (err, stdout, stderr) ->
console.log stdout + stderr
console.log "...Done(clean)"