-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.ts
63 lines (53 loc) · 1.83 KB
/
remove.ts
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
import chalk from 'chalk';
const { red } = chalk;
import { remove } from 'fs-extra';
import { env } from 'process';
const quietDefault = env.FSE_CLI_QUIET && env.FSE_CLI_QUIET === 'true';
import * as logger from '../logger.js';
const removeDef = {
name: 'remove',
spec: {
'--quiet': Boolean,
'-q': '--quiet'
},
'default': {
quiet: quietDefault
},
options: (args: { _: unknown[], [key: string]: unknown }): Record<string, unknown> => ({
quiet: args['--quiet'] || removeDef.default.quiet,
dir: args._[0] // TODO a list of files or directories?
}),
questions: (options: { dir: unknown; quiet: unknown }): Record<string, unknown>[] => {
const questions: Record<string, unknown>[] = [];
if (!options.dir) {
questions.push({
type: 'input',
name: 'dir',
message: "Please fill in the file or directory to remove",
validate: (input: string) => (input && input.trim()) ? true : "A file or directory is required"
});
}
return questions;
}
};
export const def = removeDef;
/**
* Wrapper for node-fs-extra remove function.
* https://github.com/jprichardson/node-fs-extra/blob/master/docs/remove.md
*/
export function job ({ dir, quiet }: { dir: string; quiet?: boolean }): void {
function info(message: string, ...params: unknown[]) {
logger.info(message, { quiet, params });
}
function error(message: string, ...params: unknown[]) {
logger.error(message, { quiet, params });
}
info(`Removing directory ${dir} ...`);
remove(dir, err => {
if (err) {
error(`${red.bold('ERROR')} thrown while removing file or directory: `, err);
return;
}
info(`File or directory ${dir} removed.`);
});
}