UNPKG

@webloop/create-dev-project

Version:

This is a simple command line interface to install packages

49 lines (40 loc) 1.51 kB
#!/usr/bin/env node import inquirer from "inquirer"; import chalk from "chalk"; import * as fs from "fs"; import { dirname } from "path"; import { fileURLToPath } from "url"; import createDirectoryContents from "./createDirectoryContents.js"; const CURR_DIR = process.cwd(); const __dirname = dirname(fileURLToPath(import.meta.url)); const CHOICES = fs.readdirSync(`${__dirname}/templates`); const logPrint = chalk.hex("#FFA500"); const QUESTIONS = [ { name: "project-choice", type: "list", message: chalk.magenta("Select template for your project!"), prefix: chalk.redBright("?"), choices: CHOICES, }, { name: "project-name", type: "input", message: chalk.magenta("Project name:"), validate: function (input) { if (/^([A-Za-z\-\\_\d])+$/.test(input)) return true; else console.log(chalk.red("\n\n%s Project name may only include letters, numbers, underscores and hashes.\n\n"), "ERROR:"); }, }, ]; inquirer.prompt(QUESTIONS).then((answers) => { const projectChoice = answers["project-choice"]; const projectName = answers["project-name"]; const templatePath = `${__dirname}/templates/${projectChoice}`; fs.mkdirSync(`${CURR_DIR}/${projectName}`); createDirectoryContents(templatePath, projectName); console.log(chalk.green(`\n%s Your project created successfully!`), "DONE:"); console.log(logPrint(`\ncd ${projectName}`)); console.log(logPrint(`npm install`)); console.log(chalk.greenBright(`\n\n\n Happy Hacking!`)); });