This repository was archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseClean.js
67 lines (59 loc) · 1.73 KB
/
baseClean.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import BaseRecipe from './baseRecipe'
import Preset from './preset'
import del from 'del'
export const Default = {
presetType: `macro`, // allows direct instantiation
debug: false,
task: false,
watch: false,
sync: true, // necessary so that tasks can be run in a series, can be overriden for other purposes
options: {}
}
const BaseClean = class extends BaseRecipe {
/**
*
* @param gulp - gulp instance
* @param preset - base preset configuration - either one from preset.js or a custom hash
* @param configs - customized overrides for this recipe
*/
constructor(gulp, preset, ...configs) {
let config = Preset.resolveConfig(preset, Default, ...configs)
let destGlob = {} // assume no glob - directory and contents will be deleted
if(config.glob){
destGlob = {dest: `${config.dest}/${config.glob}`}
}
super(gulp, preset, config, destGlob)
}
createDescription(){
// use the config to generate the dynamic help
return `Cleans ${this.config.dest}`
}
run(done, watching = false) {
if (this.config.sync) {
this.debug(`deleting ${this.config.dest}`)
let paths = del.sync(this.config.dest, this.config.options)
this.logDeleted(paths)
}
else {
this.debug(`deleting ${this.config.dest}`)
return del(this.config.dest, this.config.options)
.then((paths) => {
this.logDeleted(paths)
})
.catch((error) => {
error.plugin = 'del'
this.notifyError(error, watching)
})
}
this.donezo(done)
}
logDeleted(paths) {
if (paths.length > 0) {
this.log(`Deleted files and folders:`)
for(let path of paths){
this.log(` ${path}`)
}
}
}
}
export default BaseClean