UNPKG

1.03 kBPlain TextView Raw
1import {Dependency} from "./Depedency";
2import {Group} from "./classLibrary/Group";
3import path from "path";
4import chalk from "chalk";
5import {Template} from "./classLibrary/Template";
6import rimraf = require("rimraf");
7
8async function RemoveTemplate(dep: Dependency, key: string, group: string): Promise<string> {
9 const g: Group = new Group(dep.core, dep.objex, path.resolve(__dirname, '../templates'), dep.util);
10 if (!g.Exist(group)) return chalk.red(`Group ${chalk.cyanBright(key)} does not exist!`);
11 const template: Template = new Template(group, key, "", "", g);
12 if (!template.Exist()) return chalk.red(`Template ${chalk.cyanBright(key)} does not exist within Group ${chalk.cyanBright(group)}`);
13 const sure = await dep.autoInquirer.InquirePredicate(`Are you sure you want to remove ${key} from Group ${group}? This cannot be undone.`);
14 if (!sure) return "User cancelled";
15 rimraf.sync(template.Target);
16 template.DeleteGroupEntry();
17 return chalk.greenBright("Template successfully deleted");
18}
19
20export {RemoveTemplate}