-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.ts
32 lines (24 loc) · 970 Bytes
/
command.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
import { rmSync, mkdirSync } from 'fs';
import type { Logger } from '@chubbyts/chubbyts-log-types/dist/log';
export type CleanDirectoriesCommand = (directoryNames: Array<string>) => number;
export const createCleanDirectoriesCommand = (
directories: Map<string, string>,
logger: Logger,
): CleanDirectoriesCommand => {
return (directoryNames: Array<string>): number => {
const unsupportedDirectoryNames: Array<string> = directoryNames.filter(
(directoryName) => !directories.has(directoryName),
);
if (unsupportedDirectoryNames.length > 0) {
logger.error('Unsupported directory names', { unsupportedDirectoryNames });
return 1;
}
directoryNames.forEach((directoryName) => {
const directory = directories.get(directoryName) as string;
logger.info('Start clean directory', { directoryName, directory });
rmSync(directory, { recursive: true });
mkdirSync(directory);
});
return 0;
};
};