-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstylus.ls
More file actions
58 lines (54 loc) · 2.07 KB
/
Copy pathstylus.ls
File metadata and controls
58 lines (54 loc) · 2.07 KB
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
require! <[fs path fs-extra stylus uglifycss @plotdb/colors]>
require! <[./base ../aux ../adapter]>
stylusbuild = (opt={}) -> @init({srcdir: 'src/styl', desdir: 'static/css'} <<< opt)
stylusbuild.prototype = Object.create(base.prototype) <<< do
get-dependencies: (file) ->
code = fs.read-file-sync file .toString!
ret = code
.split \\n
.map -> /\s*(@import)\s+(.+)$/.exec(it)
.filter -> it
.map -> it.2.replace(/'/g, '').replace(/(\.styl)?$/, '.styl')
.map ~> path.join(@srcdir,it)
root = path.resolve('.') + '/'
return (ret or []).map ~> it.replace(root, '')
is-supported: (file) -> /\.styl$/.exec(file) and file.startsWith(@srcdir)
resolve: (file) ->
re = new RegExp("^#{@desdir}/(.+?)(\.min)?\.css")
ret = re.exec(file)
if ret => return path.join(@srcdir, "#{ret.1}.styl")
return null
map: (file) ->
src: file
des: file.replace(@srcdir, @desdir).replace(/\.styl$/, '.css')
des-min: file.replace(@srcdir, @desdir).replace(/\.styl$/, '.min.css')
build: (files) ->
for {file, mtime} in files =>
{src,des,des-min} = @map file
if !fs.exists-sync(src) or aux.newer(des, mtime) => continue
try
t1 = Date.now!
code = fs.read-file-sync src .toString!
if /^\/\/- ?(module) ?/.exec(code) => continue
desdir = path.dirname(des)
fs-extra.ensure-dir-sync desdir
stylus code
.set \filename, src
.render (e, css) ~>
if e => throw e
code-min = uglifycss.processString(css, uglyComments: true)
fs.write-file-sync des, css
fs.write-file-sync des-min, code-min
t2 = Date.now!
@log.info "#src --> #des / #des-min ( #{t2 - t1}ms )"
catch
@log.error "#src failed: ".red
@log.error e.message.toString!
purge: (files) ->
for {file, mtime} in files =>
{src,des,des-min} = @map(file)
[des,des-min].filter (f) ~>
if !fs.exists-sync f => return
fs.unlink-sync f
@log.warn "#src --> #f deleted.".yellow
module.exports = stylusbuild