werkzeug
Version:
compiles ts, coffee, sass/scss, less/ stylus and packs browser ready bundles
92 lines (67 loc) • 2.37 kB
text/coffeescript
Path = require 'path'
TYPES =
scss: 'sass'
sass: 'sass'
less: 'less'
styl: 'styl'
ts: 'ts'
coffee: 'coffee'
#TODO: generalize types together with compilers
class PathHelper
: /\.sass$|\.scss$/
: /\.less$/
: /\.styl$/
: /\.ts$|\.tsx$/
: /\.coffee$/
: /\.js$/
: /\.js\.map$/
: /\.css$/
: /\.css\.map$/
: (path) -> . test path
: (path) -> . test path
: (path) -> . test path
: (path) -> . test path
: (path) -> .test path
: (path) -> . test path
: (path) -> . test path
: (path) -> . test path
: (path) -> .test path
= (path) ->
return path.replace(, '.css') if (path)
return path.replace(, '.css') if (path)
return path.replace(, '.css') if (path)
return path.replace(, '.js') if (path)
return path.replace(, '.js') if (path)
path
: (cfg, type) ->
c = cfg[type]
p = if c and c.in then c.in else cfg.in
Path.join cfg.base, p
: (cfg, type) ->
c = cfg[type]
p = if c and c.out then c.out else cfg.out
Path.join cfg.base, p
: (path) ->
result = /\.(\w*)$/.exec(path)
ext = if result then result[1] else null
TYPES[ext] or 'assets'
: (cfg, type, path, correct) ->
type = (path) if not type
inPath = cfg, type
outPath = cfg, type
rel = path.replace inPath, outPath
return rel if not correct
PathHelper.correctOut rel
: (cfg) ->
base = cfg.base
outPaths = []
out = cfg.out
if out and out != cfg.in
outPaths.push Path.join base, out
for type of cfg
out = cfg[type]?.out
if out and out != cfg[type].in
out = Path.join base, out
outPaths.push(out) if outPaths.indexOf(out) == -1
outPaths
module.exports = PathHelper