UNPKG

951 BPlain TextView Raw
1import {GitSimulator} from "./classLibrary/GitSimulator";
2import chalk from "chalk";
3import * as path from "path";
4import {GenerateTemplate, Interrogate} from "./generator";
5import * as rimraf from "rimraf";
6import {Dependency} from "./Depedency";
7
8
9export async function Try(dep: Dependency, from: string, to: string, git: boolean, copyNode: boolean): Promise<string> {
10 let f: string = path.resolve(process.cwd(), from);
11 if (git) {
12 let gitSimulate: GitSimulator = new GitSimulator(dep.core);
13 f = await gitSimulate.SimulateGit(process.cwd(), from);
14 console.log(chalk.blueBright(f));
15 }
16 let ret = "";
17 try {
18 let cyanSafe = await Interrogate(dep, dep.autoInquirer, f, to);
19
20 let logger = console.log;
21 console.log = function (...args) {
22 logger.apply(console, args);
23 };
24
25 ret = await GenerateTemplate(dep, f, to, cyanSafe, copyNode);
26
27 } catch (e) {
28 ret = chalk.redBright(e);
29 }
30 if (git) {
31 rimraf.sync(f);
32 }
33 return ret;
34}