-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
46 lines (37 loc) · 1.36 KB
/
index.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
path = require 'path'
Plugin = require 'broccoli-plugin'
walk = require 'walk-sync'
mkdirp = require 'mkdirp'
{sync: isDir} = require 'is-directory'
{sync: symlink} = require 'symlink-or-copy'
minimatch = require 'minimatch'
class BroccoliRm extends Plugin
constructor: (inputNodes, options) ->
unless @ instanceof BroccoliRm
return new BroccoliRm inputNodes, options
@paths = options?.paths or []
super inputNodes, options
build: ->
for inputPath in @inputPaths
# This way, we exclude everything _within_ an excluded folder.
excludes = @paths.map (exclude) ->
if isDir path.join inputPath, exclude
path.join exclude, '**', '*'
else exclude
files = walk.entries inputPath
for file in files
continue if file.isDirectory()
{basePath, relativePath} = file
shouldExclude = false
for exclude in excludes
# Curiously, this line doesn't parse if we get rid of the parentheses.
# CoffeeScript bug?
if minimatch relativePath, exclude, {dot: true}
shouldExclude = true
break
continue if shouldExclude
outputPath = path.join @outputPath, relativePath
mkdirp.sync path.dirname outputPath
fullPath = path.join basePath, relativePath
symlink fullPath, outputPath
module.exports = BroccoliRm