1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 | const fse = require('fs-extra')
|
5 | const junk = require('junk')
|
6 | const mm = require('micromatch')
|
7 | const globEscape = require('glob-escape')
|
8 | const log = require('./log')
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const getIgnoredFiles = function(routes, customFiles, srcPath) {
|
18 |
|
19 |
|
20 | const ignoredFiles = [
|
21 | '**/CVS',
|
22 | '**/.git',
|
23 | '**/.svn',
|
24 | '**/.hg',
|
25 | '**/.lock-wscript',
|
26 | '**/.wafpickle-N'
|
27 | ]
|
28 |
|
29 |
|
30 | const saveSrcPath = globEscape(srcPath)
|
31 |
|
32 |
|
33 | const ignoredRoutes = routes.map((route) => path.join(saveSrcPath, route.path))
|
34 |
|
35 |
|
36 | return [
|
37 | ...ignoredFiles,
|
38 | ...ignoredRoutes,
|
39 | ...customFiles
|
40 | ]
|
41 |
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | module.exports = function(routes, srcPath, distPath, opts, next) {
|
54 |
|
55 | const ignoredFiles = getIgnoredFiles(routes, opts.ignore, srcPath)
|
56 |
|
57 | const fseOpts = {
|
58 | filter: (filePath) => {
|
59 |
|
60 | const fileName = path.parse(filePath).base
|
61 |
|
62 | const isIgnored = mm.any(filePath, ignoredFiles)
|
63 | const isJunk = junk.is(fileName)
|
64 |
|
65 |
|
66 | const copy = isIgnored===false && isJunk===false
|
67 |
|
68 | if (opts.verbose===true) {
|
69 |
|
70 | if (copy===false) log(`{cyan:Skipping file: {grey:${ filePath }`)
|
71 | if (copy===true) log(`{cyan:Copying file: {grey:${ filePath }`)
|
72 |
|
73 | }
|
74 |
|
75 |
|
76 | return copy
|
77 |
|
78 | }
|
79 | }
|
80 |
|
81 | fse.copy(srcPath, distPath, fseOpts, next)
|
82 |
|
83 | } |
\ | No newline at end of file |