-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.js
More file actions
45 lines (38 loc) · 1.12 KB
/
Copy pathinstaller.js
File metadata and controls
45 lines (38 loc) · 1.12 KB
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
38
39
40
41
42
43
44
45
#!/usr/bin/env node
import inquirer from 'inquirer';
import fs from "fs";
import ncp from "ncp";
import path from 'path';
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const CURR_DIR = process.cwd();
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) {
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 = answers["project-choice"];
const templatePath = `${__dirname}/templates/${projectChoice}`;
const projectName = answers["project-name"];
const targetFolderPath = `${CURR_DIR}/${projectName}`;
ncp(templatePath, targetFolderPath, (err) => {
if (err) return console.error(err);
console.log("done");
});
});