-
Notifications
You must be signed in to change notification settings - Fork 10
/
Projfile.coffee
197 lines (169 loc) · 5.4 KB
/
Projfile.coffee
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
fs = require('fs')
async = require('async')
pkg = require('./package.json')
exports.project = (pm) ->
{f, $, Utils} = pm
$.registerExecutable 'git'
pm.filters require('pm-tutdown')
pm.load require('./Projtest.coffee'), ns: 'test'
changeToDist = f.tap (asset) ->
asset.filename = asset.filename.replace(/^src/, 'dist')
changeExtname = (extname) ->
return f.tap (asset) ->
asset.filename = Utils.changeExtname(asset.filename, extname)
updateVersion = f.tap (asset) -> asset.text = asset.text.replace('{{VERSION}}', pkg.version)
getFileSize = (path) ->
file = fs.statSync(path)
(Math.round(file.size / 100) / 10) + 'k'
replaceFileSize = (asset, match, file) ->
asset.text = asset.text.replace(match, getFileSize('dist/' + file))
updateFileSize = f.tap (asset) ->
replaceFileSize asset, /\{\{FILE_SIZE_CONTRIB_MIN\}\}/g, 'backbone.giraffe.contrib.min.js'
replaceFileSize asset, /\{\{FILE_SIZE_CONTRIB\}\}/g, 'backbone.giraffe.contrib.js'
replaceFileSize asset, /\{\{FILE_SIZE_MIN\}\}/g, 'backbone.giraffe.min.js'
replaceFileSize asset, /\{\{FILE_SIZE\}\}/g, 'backbone.giraffe.js'
all: ['clean', 'giraffe', 'miniGiraffe', 'readme', 'docs', 'stylesheets', 'staticFiles', 'test:all']
giraffe:
desc: 'Builds Giraffe'
files: 'src/backbone*.coffee'
dev: [
updateVersion
f.coffee
f.writeFile _filename: {replace: [/^src/, 'dist']}
f.writeFile _filename: {replace: [/^dist/, 'dist/docs']}
]
miniGiraffe:
desc: 'Builds Minified Giraffe'
files: 'src/backbone*.coffee'
dev: [
updateVersion
f.coffee
f.uglify
f.tap (asset) ->
asset.dirname = 'dist'
asset.basename = asset.basename.replace(/\.js$/, '.min.js')
f.writeFile _filename: {replace: [/^src/, 'dist']}
f.writeFile _filename: {replace: [/^dist/, 'dist/docs']}
]
readme:
desc: 'Builds README.md'
files: '_README.md'
dev: [
f.preproc root: process.cwd()
updateVersion
updateFileSize
f.writeFile _filename: {replace: [/\_/, '']}
]
# _docs
_copyLicense:
desc: 'Copies LICENSE to be made into an HTML file'
files: ['LICENSE']
dev: [
f.tap (asset) ->
asset.filename = switch asset.filename
when 'LICENSE' then 'src/docs/license.md'
f.writeFile
]
_deleteTempLicense:
desc: 'Deletes copied LICENSE'
dev: ->
$.rm 'src/docs/license.md'
_toc:
files: 'src/docs/_toc.md'
dev: [
f.tutdown assetsDirname: 'dist/docs/assets'
f.writeFile _filename: 'dist/docs/_toc.html'
]
_docs:
desc: 'Builds docs'
deps: ['_toc']
files: [
'src/docs/*.md'
'!src/docs/_toc.md'
]
dev: [
f.preproc root: process.cwd()
updateVersion
updateFileSize
f.tutdown
templates:
example: fs.readFileSync('src/docs/_example.mustache', 'utf8')
uml: fs.readFileSync('src/docs/_uml.mustache', 'utf8')
assetsDirname: 'dist/docs/assets'
f.tap (asset) ->
asset.nav = fs.readFileSync('dist/docs/_toc.html')
f.template
delimiters: 'mustache'
filename: 'src/docs/_layout.mustache'
navHeader: ''
f.tap (asset) ->
asset.filename = asset.filename.replace(/^src/, 'dist')
f.writeFile
]
_api:
desc: 'Builds API documentation'
deps: ['stylesheets', 'staticFiles']
files: ['src/backbone.giraffe.coffee']
dev: [
f.tutdown commentFiller: '* ' #, debug:true
f.template
delimiters: 'mustache'
filename: 'src/docs/_layout.mustache'
navHeader:
"""
<h2><a href="index.html">Examples</a></h2>
<h2><a href="backbone.giraffe.html">Giraffe API</a></h2>
<!-- <h2><a href="backbone.giraffe.contrib.html">Giraffe.Contrib API</a></h2> -->
"""
f.tap (asset) -> asset.dirname = 'dist/docs'
f.writeFile
]
docs:
desc: 'Builds the docs'
deps: ['prep', '_copyLicense', '_docs', '_deleteTempLicense', '_api']
stylesheets:
desc: 'Builds less files'
files: ['src/docs/css/*.less']
dev: [
f.less dumpLineNumbers: null
changeToDist
f.writeFile
]
staticFiles:
desc: 'Copies static files'
dev: ->
$.cp '-rf', 'src/docs/img', 'dist/docs'
# needed since we only copy dist/docs/* to gh-pages
#$.cp 'dist/backbone.giraffe*js', 'dist/docs'
prep: ->
$.mkdir '-p', 'dist/docs/assets'
clean: ->
$.rm '-rf', 'dist'
$.rm '-f', 'README.md'
"gh-pages":
desc: "Creates/updates gh-pages branch"
dev: (cb) ->
this.timeout = 30000
GH_PAGES = '_gh-pages'
ensureGhPagesBranch = (cb) ->
if $.test('-d', GH_PAGES)
cb()
else
$ .git "clone [email protected]:barc/backbone.giraffe #{GH_PAGES}", (err) ->
return cb(err) if err
$.inside GH_PAGES, (popcb) ->
$.git "checkout -t origin/gh-pages", popcb(cb)
updateRepo = (cb) ->
$.inside GH_PAGES, (popcb) ->
$ .git("checkout gh-pages")
.git("pull origin gh-pages")
.start popcb(cb)
updateFiles = (cb) ->
$.cp '-rf', 'dist/docs/*', GH_PAGES
cb()
async.series [ensureGhPagesBranch, updateRepo, updateFiles], (err) ->
if err
$.error 'ERROR', err
else
$.info '_gh-pages updated. cd into it and `git push origin gh-pages`'
cb()