UNPKG

ptjs-cli

Version:

A tool for quickly creating projects based on templates

102 lines (99 loc) 2.59 kB
#!/usr/bin/env node const program = require('commander'); const package_config = require('../package.json'); const { logo } = require('../lib'); const { add, list, create, del, version_config } = require('../cmd'); const chalk = require('chalk'); /** * Commander input */ module.exports = new class { cmd() { // Check Update version_config.configDirCheck(); // Version version_config.versionCheck(); let cmdValue; program.version( package_config.version, '-v, --version' ); // Add a new project Path to labels program .command('add') .description('add a new tepmlate info') .action((Command) => { cmdValue = Command._name; add() .then(() => { console.log(chalk.green('Finished!')); logo.show(); }) .catch((err) => { console.log(chalk.red('something error:', err)); }); }); // List Labels program .command('list') .description('show tepmlate-name list') .action((Command) => { cmdValue = Command._name; list() .then(() => { console.log(chalk.green('Finished!')); logo.show(); }) .catch((err) => { console.log(chalk.red('Something Error:', err)); }); }); // Pull a New Project From Label program .command('new') .description('create a project from template-name') .option( '-i, --init', 'init project ; such as run [ npm -i / pip install -r requirements.txt ] ' ) .action((Command) => { cmdValue = Command._name; create(Command.init) .then(() => { console.log(chalk.green('Finished!')); logo.show(); }) .catch((err) => { console.log(chalk.red('something error:', err)); }); // console.log(name, cmdValue, Command.init); }); // Delete Project Template program .command('delete') .description('delete a project template') .action((Command) => { cmdValue = Command._name; del() .then(() => { console.log(chalk.green('Finished!')); logo.show(); }) .catch((err) => { console.log(chalk.red('something error:', err)); }); // console.log(name, cmdValue, Command.init); }); program.parse(process.argv); // no Correct cmd if (typeof cmdValue === 'undefined') { logo.show(); } } }();