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 | module.exports = function(distPath, cwdPath, opts, next) {
|
17 |
|
18 |
|
19 |
|
20 | const isSafePath = isPathInside(distPath, cwdPath)
|
21 |
|
22 | if (isSafePath===false) {
|
23 | return next(new Error(`Specified distPath must be inside the current working directory to prevent us from deleting ourself`))
|
24 | }
|
25 |
|
26 | if (opts.verbose===true) log(`{cyan:Deleting folder: {grey:${ distPath }`)
|
27 |
|
28 | fse.remove(distPath, (err) => {
|
29 |
|
30 | if (err!=null) return next(err)
|
31 |
|
32 | if (opts.verbose===true) log(`{cyan:Deleted folder: {grey:${ distPath }`)
|
33 |
|
34 | next()
|
35 |
|
36 | })
|
37 |
|
38 | } |
\ | No newline at end of file |