@codephez/cli
Version:
cli for generate vue project example
71 lines (60 loc) • 1.95 kB
JavaScript
import inquirer from 'inquirer';
import * as fs from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import createDirectoryContents from './createDirectoryContents.js';
import chalk from 'chalk';
import figlet from 'figlet';
import {Command} from 'commander'
const program = new Command();
if(process.argv[2]){
program.option("-v, --version, -V, --Version", "Chek Version")
program.version('1.0.5')
program.parse(process.argv)
// const packageJSON = join(process.cwd(), 'package.json');
// console.log(chalk.yellow('pleace type --help') )
// const version = fs.readFileSync(packageJSON).toString()
} else {
console.log('',)
console.log('',)
console.log(
chalk.green(
figlet.textSync('codephez', {
horizontalLayout: 'full',
font: 'ANSI Shadow'
})
)
);
console.log('',)
console.log('👋👋👋 Welcome in codephez cli 🙂🙂🙂🙂🙂')
console.log('',)
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) {
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 projectName = answers['project-name'];
const templatePath = `${__dirname}/templates/${projectChoice}`;
fs.mkdirSync(`${CURR_DIR}/${projectName}`);
createDirectoryContents(templatePath, projectName);
console.log(`cd ${projectName} && npm install`)
});
}