@bmstravel/nvp-cli
Version:
π Command line tool
84 lines (71 loc) β’ 2.05 kB
JavaScript
#!/usr/bin/env node
/* nvp-cli
* Copyright (c) 2022
* MIT Licensed
*/
import path from "path";
import minimist from "minimist";
import { Plop, run } from "plop";
import yargs from 'yargs/yargs';
import fs from 'fs';
import inquirer from 'inquirer';
const args = process.argv.slice(2);
const argv0 = minimist(args);
// import { dirname } from "node:path";
// import { fileURLToPath } from "node:url";
// const __dirname = dirname(fileURLToPath(import.meta.url));
const _dirname = process.cwd();
const askName = async () => {
const answers = await inquirer.prompt([
{
message: 'Chα»n template?',
type: "list",
name: "kindTemplate",
choices: ["base_api", "base_admin"],
}
]);
if (answers.kindTemplate == 'base_api') {
Plop.prepare({
cwd: argv0.cwd,
configPath: path.join(_dirname, 'node_modules/@bmstravel/nvp-cli','/es/plopfile.js'),
preload: argv0.preload || [],
completion: argv0.completion
}, env => Plop.execute(env, run));
} else {
console.log(`π ~ ...developing`);
}
};
askName()
/* const argv1 = yargs(args)
.usage('Usage: $0 <command> [options]')
.command('ask', 'use inquirer to prompt for your name', () => { }, askName)
.alias('a', 'ask')
.nargs('a', 1)
.describe('a', 'use inquirer')
.command('sing', 'a classic yargs command without prompting', () => { }, sing)
.demandCommand(1, 1, 'choose a command: ask or sing')
// .strict()
.help('h')
.alias('h', 'help')
.argv; */
/* const argv1 = yargs(args)
.usage('Usage: $0 <command> [options]')
.command('count', 'Count the lines in a file')
.example('$0 count -f foo.js', 'generate by in the given file')
.alias('f', 'file')
.nargs('f', 1)
.describe('f', 'Load a file')
.demandOption(['f'])
.help('h')
.alias('h', 'help')
.epilog('copyright 2022')
.argv;
var s = fs.createReadStream(argv1.file);
console.log(`π ~ file: nvp.js ~ line 37 ~ argv1.file`, argv1.file);
var lines = 0;
s.on('data', function (buf) {
lines += buf.toString().match(/\n/g).length;
});
s.on('end', function () {
console.log(lines);
}); */