This repository has been archived by the owner on Dec 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.coffee
121 lines (104 loc) · 3.47 KB
/
build.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
path = require 'path'
helpers = require './helpers'
stamp = Date.now()
checkpoint = (name, start) ->
end = Date.now()
time = (end - start) / 1000
console.log("#{name} +#{time}s")
end
axis = require './node_modules/axis'
jeet = require './node_modules/jeet'
Metalsmith = require './node_modules/metalsmith'
rm = require './node_modules/rimraf'
end = checkpoint 'require base', stamp
fingerprint = require './node_modules/metalsmith-fingerprint-ignore'
htmlMinifier = require './node_modules/metalsmith-html-minifier'
beautify = require './node_modules/metalsmith-beautify'
mithril = require './node_modules/metalsmith-mithril'
msIf = require './node_modules/metalsmith-if'
uglify = require './node_modules/metalsmith-uglify'
linkcheck = require './node_modules/metalsmith-linkcheck'
end = checkpoint 'require metalsmith plugins', end
browserify = require './plugins/browserify'
cleanCSS = require './plugins/clean-css'
compress = require './plugins/compress'
ignore = require './plugins/ignore'
markdown = require './plugins/markdown'
preempt = require './plugins/preempt'
stylus = require './plugins/stylus'
time = require './plugins/time'
end = checkpoint 'require local plugins', end
config = require './config'
js = config.paths.js
end = checkpoint 'set config', end
_ = helpers._
Runner = require('./node_modules/metalsmith-start').Runner
app = new Metalsmith(__dirname)
.use time plugin: 'start', start: end
.source config.paths.source
.destination config.paths.dest
.metadata config
.use time plugin: 'metadata'
.use preempt()
.use time plugin: 'preempt'
.use ignore()
.use time plugin: 'ignore'
.use markdown()
.use time plugin: 'markdown'
.use stylus
compress: false
use: [axis(), jeet()]
.use time plugin: 'stylus'
.use browserify
destFolder: js
plugin: if config.prod then [] else ['watchify']
debug: not config.prod
.use time plugin: 'browserify'
.use fingerprint pattern: ['**/*.css', '**/*.js']
.use time plugin: 'fingerprint'
.use mithril.layouts ext: '.coffee'
.use time plugin: 'mithril'
.use msIf not config.serve, linkcheck()
.use time plugin: 'linkcheck'
.use msIf config.prod, cleanCSS
files: "#{config.paths.css}/main*.css"
rename: false
sourceMap: false
cleanCSS: rebase: true
.use msIf config.prod, time plugin: 'cleanCSS'
.use msIf config.prod, uglify sourceMap: false, nameTemplate: '[name].[ext]'
.use msIf config.prod, time plugin: 'uglify'
.use msIf config.prod, htmlMinifier()
.use msIf config.prod, time plugin: 'htmlMinifier'
.use msIf not config.prod, beautify()
.use msIf not config.prod, time plugin: 'beautify'
.use msIf config.prod, compress overwrite: false
.use msIf config.prod, time plugin: 'compress'
build = (clean) ->
afterProcess = (err, files) ->
if err
console.log "process error: #{err.message}"
else
app.write files, (err) ->
endTime = (Date.now() - stamp) / 1000
if err
console.log "write error: #{err.message} "
else
_.keys(files).length
console.log "Successfully built #{_.keys(files).length} files"
# for filename, data of _files
# console.log "built #{filename}"
console.log "built site in #{endTime}s "
if clean
rm path.join(app.destination(), '*'), (err) ->
if err
console.log "rimraf error: #{err.message}"
else
app.process afterProcess
else
app.process afterProcess
if config.serve
r = new Runner(app)
r.start()
else
build true