UNPKG

1.42 kBPlain TextView Raw
1import { fsPath, log, inquirer } from './common';
2import * as newFile from 'new-file';
3
4export type ITemplate = {
5 name: string;
6 dir: string;
7};
8
9export async function create() {
10 log.info();
11 log.info('👇');
12
13 const targetDir = fsPath.resolve('.');
14 const settingsPath = fsPath.join(__dirname, '../templates.yml');
15 const res = await newFile.create({
16 targetDir,
17 settingsPath,
18 });
19 log.info();
20
21 if (!res.success) {
22 return;
23 }
24
25 // Finish up.
26 const dir = res.dir;
27 logComplete({ dir });
28}
29
30/**
31 * INTERNAL
32 */
33function logComplete(args: { dir: string }) {
34 const dir = fsPath.basename(args.dir);
35 log.info.gray(`See ${log.blue('https://uiharness.com')} for more.`);
36 log.info.gray('🖐 To start your development server:\n');
37 log.info.cyan(` cd ${log.white(dir)}`);
38 log.info.cyan(` yarn start`);
39 log.info();
40 log.info.gray('👉 To see all available UIHarness commands:\n');
41 log.info.cyan(` cd ${log.white(dir)}`);
42 log.info.cyan(` yarn ui`);
43 log.info();
44}
45
46async function promptForTemplate(templates: ITemplate[]) {
47 const choices = templates.map(item => ({ name: item.name, value: item.dir }));
48 const confirm = {
49 type: 'list',
50 name: 'path',
51 message: 'Select a template',
52 choices,
53 };
54 const { path } = (await inquirer.prompt(confirm)) as { path: string };
55 const result = templates.find(item => item.dir === path);
56 return result;
57}