-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathCakefile
109 lines (96 loc) · 3.54 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
coffee = require 'coffee-script'
util = require 'util'
{exec} = require 'child_process'
glob = require 'glob'
fs = require 'fs'
path = require 'path'
yaml = require 'js-yaml'
coffeeCompile = (file) ->
code = fs.readFileSync(file).toString()
jsFile = file
.replace('.coffee', '.js')
.replace('coffeescripts', 'javascripts')
fs.writeFileSync jsFile, coffee.compile(code)
task 'run', 'start up development', ->
invoke 'clean'
invoke 'compile'
invoke 'concat'
invoke 'watch'
invoke 'build'
task 'build','build extension to install or distribute', ->
console.log 'Building extension'
exec 'make build'
task 'clean', 'remove all generated javascript', ->
console.log "Cleaning javascript"
for file in glob.sync("extension/javascripts/**/*.js")
unless file.match(/framework/)
fs.unlinkSync(file)
task 'compile', 'compile extension coffee', ->
console.log "Compiling coffee"
for file in glob.sync("extension/**/*.coffee")
coffeeCompile(file)
task 'concat', 'concat templates and js', ->
invoke 'concat:templates'
invoke 'concat:js'
task 'concat:templates', 'concat templates', ->
console.log "Concating templates"
filepaths = glob.sync("extension/templates/*.html")
concatedTemplates = ''
for filepath in filepaths
key = path.basename(filepath, '.html')
code = fs.readFileSync(filepath).toString()
template = code.replace(/\n/g, '').replace(/\"/, '\"')
concatedTemplates += "BH.Templates.#{key} = \"#{template}\";\n\n"
filepath = 'extension/javascripts/templates.js'
fs.writeFileSync filepath, concatedTemplates
task 'concat:js', 'concat javascript', ->
console.log "Concating javascript"
assets = fs.readFileSync('extension/assets.yml')
assets = yaml.load assets.toString()
for section in ['extension', 'background']
concatedFile = "extension/javascripts/generated_#{section}.js"
if fs.existsSync concatedFile
fs.unlinkSync concatedFile
license = fs.readFileSync("LICENSE")
packaged = "/* \n#{license}*/\n"
for asset in assets[section]
if asset.match(/\*/)
filepaths = glob.sync("extension/javascripts/#{asset}")
for filepath in filepaths
packaged += "\n\n// #{filepath}\n"
packaged += fs.readFileSync(filepath)
else
filepath = "extension/javascripts/#{asset}.js"
packaged += "\n\n// #{filepath}\n"
packaged += fs.readFileSync(filepath)
sectionPath = "extension/javascripts/generated_#{section}.js"
fs.writeFileSync(sectionPath, packaged)
task 'watch', 'watch coffee and template files', ->
invoke 'watch:coffee'
invoke 'watch:templates'
invoke 'watch:locales'
invoke 'watch:styles'
task 'watch:coffee', 'watch coffee for changes', ->
for filepath in glob.sync("extension/coffeescripts/**/*.coffee")
fs.watchFile filepath, {}, ->
console.log '== Coffee changed'
invoke 'compile'
invoke 'concat:js'
invoke 'build'
task 'watch:templates', 'watch templates for changes', ->
for filepath in glob.sync("extension/templates/*.html")
fs.watchFile filepath, {}, ->
console.log '== Template Changed'
invoke 'concat:templates'
invoke 'concat:js'
invoke 'build'
task 'watch:locales', 'watch locales for changed', ->
for filepath in glob.sync("extension/_locales/**/*.json")
fs.watchFile filepath, {}, ->
console.log '== Locale Changed'
invoke 'build'
task 'watch:styles', 'watch styles for changed', ->
for filepath in glob.sync("extension/styles/**/*.css")
fs.watchFile filepath, {}, ->
console.log '== Styles Changed'
invoke 'build'