1 | 'use strict'
|
2 |
|
3 | const fse = require('fs-extra')
|
4 | const isPathInside = require('is-path-inside')
|
5 | const log = require('./log')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | module.exports = function(distPath, cwdPath, opts, next) {
|
18 |
|
19 |
|
20 |
|
21 | const isSafePath = isPathInside(distPath, cwdPath)
|
22 |
|
23 | if (isSafePath===false) {
|
24 | return next(new Error(`Specified distPath must be inside the current working directory to prevent us from deleting ourself`))
|
25 | }
|
26 |
|
27 | if (opts.verbose===true) log(`{cyan:Deleting folder: {grey:${ distPath }`)
|
28 |
|
29 | fse.remove(distPath, (err) => {
|
30 |
|
31 | if (err!=null) return next(err)
|
32 |
|
33 | if (opts.verbose===true) log(`{cyan:Deleted folder: {grey:${ distPath }`)
|
34 |
|
35 | next()
|
36 |
|
37 | })
|
38 |
|
39 | } |
\ | No newline at end of file |