Skip to content

Commit e20f894

Browse files
authored
Remove mongoose choice (#6)
* Rename Package * Remove Mongoose Schema Choice, It's must
1 parent 763bed9 commit e20f894

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

bin/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
22

3-
require = require("esm")(module /*, options*/);
4-
require("../src/cli").cli(process.argv);
3+
const cli = require("../src/cli");
4+
5+
cli(process.argv);

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
2-
"name": "mongodb-schema-cli",
3-
"version": "1.0.1",
2+
"name": "mongoose-schema-cli",
3+
"version": "1.1.0",
44
"description": "A MongoDB Schema Generator CLI",
55
"main": "index.js",
66
"bin": {
77
"msc-gen": "bin/index.js"
88
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/eKhattak/mongoose-schema-cli"
12+
},
913
"keywords": [
1014
"mongodb",
1115
"mongoose",
@@ -19,7 +23,6 @@
1923
"dependencies": {
2024
"arg": "^4.1.3",
2125
"chalk": "^4.1.0",
22-
"esm": "^3.2.25",
2326
"inquirer": "^7.3.3",
2427
"listr": "^0.14.3"
2528
}

src/cli.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import arg from "arg";
2-
import inquirer from "inquirer";
1+
const arg = require("arg");
2+
const inquirer = require("inquirer");
33
const schema = require("./main");
44

55
// export var schemaDetails = {};
66
function parseArgumentsIntoOptions(rawArgs) {
77
const args = arg(
88
{
99
"--typescript": Boolean,
10-
"--mongoose": Boolean,
1110
"--filepath": String,
1211
// Aliases
1312
"-t": "--typescript",
@@ -19,15 +18,13 @@ function parseArgumentsIntoOptions(rawArgs) {
1918
);
2019
return {
2120
language: args["--typescript"] || undefined,
22-
mongoose: args["--mongoose"] || false,
2321
filePath: args["--filepath"] || "/",
2422
};
2523
}
2624

2725
async function promptForMissingOptions(options) {
2826
const defaultOptions = {
2927
language: "Javascript",
30-
mongoose: false,
3128
schema: "default",
3229
};
3330
// if (options.skipPrompts) {
@@ -48,15 +45,6 @@ async function promptForMissingOptions(options) {
4845
});
4946
}
5047

51-
if (!options.mongoose) {
52-
questions.push({
53-
type: "confirm",
54-
name: "mongoose",
55-
message: "Do you want to have it in mongoose?",
56-
default: defaultOptions.mongoose,
57-
});
58-
}
59-
6048
questions.push({
6149
type: "input",
6250
name: "schema",
@@ -73,7 +61,7 @@ async function promptForMissingOptions(options) {
7361
};
7462
}
7563

76-
export async function promptForSchemaObject() {
64+
async function promptForSchemaObject() {
7765
console.log();
7866
const defaultOptions = {
7967
name: "default",
@@ -122,9 +110,8 @@ export async function promptForSchemaObject() {
122110
};
123111
}
124112

125-
export async function cli(args) {
113+
async function cli(args) {
126114
var options = parseArgumentsIntoOptions(args);
127-
// Initial Inputs
128115
options = await promptForMissingOptions(options);
129116

130117
const { schemaKeys } = await inquirer.prompt({
@@ -146,10 +133,7 @@ export async function cli(args) {
146133
schemaKeys,
147134
};
148135

149-
// schemaDetails = {
150-
// options,
151-
// schemaKeyValues,
152-
// };
153-
154-
await schema.createSchema(options, schemaKeyValues);
136+
await schema(options, schemaKeyValues);
155137
}
138+
139+
module.exports = cli;

src/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const chalk = require("chalk");
88
const writeFile = promisify(fs.writeFile);
99
const appendFile = promisify(fs.appendFile);
1010

11-
export async function createSchema(options, schemaKeyValues) {
11+
async function createSchema(options, schemaKeyValues) {
1212
const schemaOptions = {
1313
...options,
1414
dirPath: path.resolve(__dirname, "../template"),
15-
outPath: path.resolve(process.cwd(), `./${options.schema}.js`),
15+
outPath: path.resolve(process.cwd(), "./models/"`./${options.schema}.js`),
1616
};
1717

1818
console.log();
@@ -36,3 +36,5 @@ async function createObjects(outPath, schemaKeyValues) {
3636
}
3737
await appendFile(outPath, schema.schemaBottom());
3838
}
39+
40+
module.exports = createSchema;

template/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function createSchemaObject(options) {
1+
function createSchemaObject(options) {
22
const { schemaName, type, isRequired, defaultValue } = options;
33
return `
44
${schemaName}: {
@@ -9,7 +9,7 @@ export function createSchemaObject(options) {
99
`;
1010
}
1111

12-
export function schemaTop() {
12+
function schemaTop() {
1313
return `
1414
const mongoose = require("mongoose");
1515
const Schema = mongoose.Schema;
@@ -18,10 +18,16 @@ const userSchema = new Schema({
1818
`;
1919
}
2020

21-
export function schemaBottom() {
21+
function schemaBottom() {
2222
return `
2323
timestamps: { createdAt: "created_at", updatedAt: "updated_at" }
2424
});
2525
module.exports = userSchema;
2626
`;
2727
}
28+
29+
module.exports = {
30+
createSchemaObject,
31+
schemaTop,
32+
schemaBottom,
33+
};

0 commit comments

Comments
 (0)