/
rmrf.js
54 lines (32 loc) · 1.15 KB
/
rmrf.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
module.exports = {
friendlyName: 'Remove (rm)',
description: 'Completely remove a file or directory (like rm -rf).',
extendedDescription: 'If the provided path is a directory, all contents will be removed recursively. If nothing exists at the provided path, the success exit will be triggered, but nothing will be deleted.',
sideEffects: 'idempotent',
inputs: {
path: {
example: '/Users/mikermcneil/.tmp/foo',
description: 'The absolute path to the file or directory to remove.',
required: true
}
},
exits: {
success: {
description: 'The specified file or directory was removed.'
}
},
fn: function (inputs, exits) {
// Import `path` and `fs-extra`.
var path = require('path');
var fsx = require('fs-extra');
// Ensure absolute path.
inputs.path = path.resolve(inputs.path);
// Attempt to remove the path and all its descendents.
fsx.remove(inputs.path, function(err) {
// Return any errors through the `error` exit.
if (err) {return exits.error(err);}
// If successful, return through the `success` exit.
return exits.success();
});
}
};