-
Notifications
You must be signed in to change notification settings - Fork 1
/
bebop.coffee
108 lines (89 loc) · 2.45 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
102
103
104
105
106
107
108
fs = require 'fs'
path = require 'path'
debounce = require 'debounce'
writeFile = (dst, content) ->
fs.writeFile dst, content, 'utf8', (err) ->
console.error err if err?
compilePug = (src, dst) ->
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
compileCoffee = ->
handroll = require 'handroll'
opts =
entry: 'src/js/app.coffee'
output: 'public/js/app.js'
format: 'iife'
browser: false
commonjs: true
es3: false
external: false
compilers:
coffee: version: 1
inject:
$: 'jquery'
if process.env.PRODUCTION
opts.minify = true
handroll.write opts
true
compileStylus = ->
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'
src = 'src/css/app.styl'
dst = 'public/css/app.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:
pug: compilePug
coffee: debounce compileCoffee, 10
styl: debounce compileStylus, 10