@mahjongg/mern-mvc
Version:
A CLI that will build a MERN stack application using create-react-app
59 lines (48 loc) • 2.17 kB
JavaScript
const program = require("commander");
const {create, routes} = require("./commands");
const pkg = require('./package.json');
function list(val) {
return val.split(', ');
}
program
.version(pkg.version)
.description("Builds a MERN stack MVC folder structure");
program
.command("create <name>")
.alias("c")
.description("\tCreates a full stack MERN application with the given name." +
"\n\tBe aware of using generic app names, as the database will be created using the name given."+
"\n\tYou can always adjust this after creation in '/server.js'.")
.option("-x, --no-passport", "Builds the app without passport authentication")
.action((name, cmd)=>{
const options = {
noPassport : !cmd.passport //commander will automatically flip this boolean for me, but i don't want that.
};
create(name, options);
});
program
.command("route <name>")
.alias("r")
.description("\tCreates a route folder with the specified options.\n\tThis should be run from within your 'routes' folder.")
.option("-p, --no-passport", "Builds the route without passport being passed into the export function.")
.option("-f, --no-functionBased", "Builds the route exporting the Router directly, rather than a function that returns a Router.")
.option("-r, --routes [paths]",
"Allows you to specify a list of paths to include in your new route file.\n\t" +
"All routes are created as GET routes. There is no need to include a beginning '/' before your names.\n\t"+
"If more than one route is desired, include the route names in double quotes and separate with a comma and a space. ex:\n\t"+
'mern-mvc route -r "signIn, signUp, signOut"',
list
).action((name, cmd)=>{
const options = {
noPassport: !cmd.passport,
notFunctionBased: !cmd.functionBased,
routes: cmd.routes || []
};
routes(name, options);
});
//other options to add...
// -r | no-react(for when the user has a premade react app)
// -s | simple-routes (routes files are created as simple exports, rather than functions)
// -n | no-npm (skips npm install, for quicker creation on slow connections. Still writes to package.json)
program.parse(process.argv);