@mongez/gnz
Version:
Generator Z, the next generation of scaffolding tools.
36 lines (35 loc) • 2.27 kB
JavaScript
;var reinforcements=require('@mongez/reinforcements'),commander=require('commander'),path=require('path'),index=require('../../index.js'),main=require('../../../../main.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var path__default=/*#__PURE__*/_interopDefault(path);const generateMongoDBModelCommand = new commander.Command("gn:model")
.arguments("<name>")
.option("-c, --class-name <className>", "Model Class name")
.option("-p, --path <path>", "Path to save the component to")
.option("-wi, --with-index <withIndex>", "Whether to generate an index file or not")
.option("-fn, --file-name <fileName>", "File name")
.option("-c, --columns <columns>", "Columns types: column=type,column2=type2...")
.option("-i, --indexes <indexes>", "Column that will be indexed, separate with comma")
.option("-u, --unique <unique>", "Column that will be unique, separate with comma")
.option("-t, --text <text>", "Column that will be text indexed, separate with comma")
.option("-g, --geo <geo>", "Column that will be geo indexed, separate with comma")
.option("-m, --migration <withMigration>", "Whether to generate a migration file or not")
.action(async (name, options) => {
const { className, index: index$1, path, fileName, migration, columns, geo, text, unique, indexes, } = options;
const columnList = columns
? columns.split(",").reduce((prev, current) => {
const [key, value] = current.split("=");
prev[reinforcements.trim(key)] = reinforcements.trim(value);
return prev;
}, {})
: {};
await main.gnz.execute(index.generateMongoDBModel.execute({
collection: name,
className,
columns: columnList,
saveTo: path__default.default.resolve(process.cwd(), path || ""),
withIndex: index$1 !== "false",
fileName,
withMigration: migration !== "false",
geo: geo ? geo.split(",") : [],
text: text ? text.split(",") : [],
unique: unique ? unique.split(",") : [],
index: indexes ? indexes.split(",") : [],
}));
});exports.generateMongoDBModelCommand=generateMongoDBModelCommand;//# sourceMappingURL=generate-mongodb-model-command.js.map