-
Notifications
You must be signed in to change notification settings - Fork 6
/
Cakefile
82 lines (71 loc) · 2.29 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
fs = require 'fs'
{print} = require 'util'
{spawn, exec} = require 'child_process'
COFFEE_FILES = [
"jquery.crevasse.coffee",
"crevasse.coffee",
"events.coffee",
"editor.coffee",
"previewer.coffee",
"utils.coffee"
]
task "build", "Package Crevasse for distribution", ->
fs.readFile 'VERSION', 'utf8', (err, data) ->
throw err if err
version = data
emptyLib()
compileCoffee(false, version)
compileSass(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)
compileSass(true)
emptyLib = ->
execute "rm", ["-r", "lib"]
compileCoffee = (development, version = null) ->
behavior = if development then "-w" else "-c"
outputPath = if development then "development/lib/js" else "lib/js"
outputFilename = "crevasse.js"
options = [
"-j",
outputFilename,
behavior,
"-o",
outputPath
]
# Add files to compile in proper order
options.push "src/coffee/#{file}" for file in COFFEE_FILES
execute "coffee", options, ->
markVersion("#{outputPath}/#{outputFilename}", version)
compileSass = (development, version = null) ->
behavior = if development then "--watch" else "--update"
outputPath = if development then "development/lib/css" else "lib/css"
outputFilename = "crevasse.css"
options = [
behavior,
"src/sass/crevasse.scss:#{outputPath}/#{outputFilename}"
]
execute "sass", options, ->
markVersion("#{outputPath}/#{outputFilename}", version)
markVersion = (file, version) ->
comment = """
/*
Crevasse #{version}
Built by Nick Giancola: https://github.com/patbenatar
Details and source: https://github.com/patbenatar/crevasse
Demo: https://patbenatar.github.com/crevasse
*/
"""
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