-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
37 lines (32 loc) · 1.17 KB
/
index.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
import inquirer from 'inquirer';
import * as fs from 'fs';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import createDirectoryContents from './createDirectoryContents'
const CURR_DIR = process.cwd();
const __dirname = dirname(fileURLToPath(import.meta.url));
const CHOICES = fs.readdirSync(`${__dirname}/templates`);
const QUESTIONS = [
{
name: 'project-choice',
type: 'list',
message: 'What project template would you like to generate?',
choices: CHOICES,
},
{
name: 'project-name',
type: 'input',
message: 'Project name:',
validate: function (input: string) {
if (/^([A-Za-z\-\\_\d])+$/.test(input)) return true;
else return 'Project name may only include letters, numbers, underscores and hashes.';
},
},
];
inquirer.prompt(QUESTIONS).then(answers => {
const projectChoice: string = answers['project-choice'];
const projectName: string = answers['project-name'];
const templatePath: string = `${__dirname}/templates/${projectChoice}`;
fs.mkdirSync(`${CURR_DIR}/${projectName}`);
createDirectoryContents(templatePath, projectName);
});