-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
66 lines (56 loc) · 1.8 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
fs = require 'fs'
{print} = require 'util'
{spawn, exec} = require 'child_process'
COFFEE_FILES = [
"jquery.slugger.coffee",
"slugger.coffee",
"utils.coffee"
]
task "build", "Package Slugger for distribution", ->
fs.readFile 'VERSION', 'utf8', (err, data) ->
throw err if err
version = data
emptyLib()
compileCoffee(false, version)
task "build:tag", "Tag the git repo with the version number", ->
fs.readFile 'VERSION', 'utf8', (err, data) ->
throw err if err
execute "git", ["tag", data]
task "build:development", "Watch for changes in src and update development package", ->
compileCoffee(true)
emptyLib = ->
execute "rm", ["-r", "lib"]
compileCoffee = (development, version = null) ->
behavior = if development then "-w" else "-c"
outputPath = if development then "development/lib" else "lib"
outputFilename = "jquery.slugger.js"
options = [
"-j",
outputFilename,
behavior,
"-o",
outputPath
]
# Add files to compile in proper order
options.push "src/#{file}" for file in COFFEE_FILES
execute "coffee", options, ->
markVersion("#{outputPath}/#{outputFilename}", version)
markVersion = (file, version) ->
comment = """
/*
Slugger #{version}
Built by Nick Giancola: https://github.com/patbenatar
Details and source: https://github.com/patbenatar/jquery-slugger
Demo: https://patbenatar.github.com/jquery-slugger
*/
"""
tmpFile = "#{file}.tmp"
exec "echo \"#{comment}\" | cat - #{file} > #{tmpFile} && mv #{tmpFile} #{file}"
execute = (command, options, callback = null) ->
command = spawn command, options
command.stderr.on 'data', (data) ->
process.stderr.write data.toString()
command.stdout.on 'data', (data) ->
print data.toString()
command.on 'exit', (code) ->
callback?() if code is 0