-
Notifications
You must be signed in to change notification settings - Fork 1
/
bebop.coffee
101 lines (81 loc) · 2.37 KB
/
bebop.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
fs = require 'fs'
path = require 'path'
debounce = (fn, wait = 100) ->
last = {}
(file) ->
now = new Date
# Return if we haven't waited long enough
return if last[file]? and (now - last[file]) < wait
last[file] = now
fn.apply null, arguments
writeFile = (dst, content) ->
fs.writeFile dst, content, 'utf8', (err) ->
console.error err if err?
compilePug = (src, dst) ->
console.log 'compiling with pug', src
return if src.match /modules/
filename = path.basename src
return if filename.charAt(0) == '_'
pug = require 'pug'
opts =
basedir: __dirname + '/src'
pretty: true
production: if process.env.PRODUCTION then true else false
for k,v of require './settings'
opts[k] = v
src = path.join 'src', filename
dst = path.join 'public', filename.replace '.pug', '.html'
html = pug.renderFile src, opts
writeFile dst, html
true
compileStylus = ->
src = 'src/css/app.styl'
dst = 'public/css/app.css'
stylus = require 'stylus'
postcss = require 'poststylus'
autoprefixer = require 'autoprefixer'
comments = require 'postcss-discard-comments'
lost = require 'lost-stylus'
rupture = require 'rupture'
CleanCSS = require 'clean-css'
style = stylus fs.readFileSync src, 'utf8'
.set 'filename', src
.set 'paths', [
__dirname + '/src/css'
__dirname + '/node_modules'
]
.set 'include css', true
# .set 'sourcemap',
# basePath: ''
# sourceRoot: '../'
.use lost()
.use rupture()
.use postcss [
autoprefixer browsers: '> 1%'
'lost'
'rucksack-css'
'css-mqpacker'
comments removeAll: true
]
style.render (err, css) ->
return console.error err if err
# if process.env.PRODUCTION
# minifier = new CleanCSS
# aggressiveMerging: false
# semanticMerging: false
# minified = minifier.minify css
# writeFile dst, minified.styles
# else
# sourceMapURL = (path.basename dst) + '.map'
# css = css + "/*# sourceMappingURL=#{sourceMapURL} */"
writeFile dst, css
# writeFile dst + '.map', JSON.stringify style.sourcemap
true
module.exports =
assetDir: __dirname + '/src'
buildDir: __dirname + '/public'
compilers:
coffee: -> false
pug: debounce compilePug
styl: debounce compileStylus
page404: 'public/index.html'