Skip to content

Commit

Permalink
feat: added JS-NoDB-Template functionality #367
Browse files Browse the repository at this point in the history
feat: added JS-NoDB-Template functionality
  • Loading branch information
sharafdin authored Apr 30, 2024
2 parents 72fdda0 + f91ab60 commit 0ced33e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 29 deletions.
7 changes: 4 additions & 3 deletions packages/yonode/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

import { execSync } from "child_process";
import fs from "fs";
import path, { basename } from "path";
import inquirer from "inquirer";
import path, { basename } from "path";
import "./lib/programOptions.js";
import { databaseType } from "./lib/prompt/db.js";
import { databaseConfirmQuestion } from "./lib/prompt/db.js";
import { languageType } from "./lib/questions.js";

export const options = {
language_type: "",
database: true,
database_type: "",
orm_type: "",
auth: false,
Expand Down Expand Up @@ -144,7 +145,7 @@ function main() {
process.exit(0);
}
options.language_type = answer.language_type;
databaseType();
databaseConfirmQuestion();
})
.catch((error) => {
if (error.isTtyError) {
Expand Down
47 changes: 21 additions & 26 deletions packages/yonode/src/lib/prompt/db.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import inquirer from 'inquirer'
import { mongodbOrm } from '../../orm/mongoDB.js';
import { ormType } from '../../orm/orm.js';
import { options } from '../../index.js';
import { databaseQuestion } from '../questions.js';
import inquirer from "inquirer";
import { options } from "../../index.js";
import { dbQuestion } from "../questions.js";
import { repoConditions } from "../repoConditions.js";
import { databaseType } from "./dbType.js";

export const databaseType = () => {
inquirer.prompt(
databaseQuestion
).then(answer => {
if (answer.database_type === 'MongoDB') {
options.database_type = answer.database_type
mongodbOrm()
} else if (answer.database_type === 'MySQL') {
options.database_type = answer.database_type
ormType()
}
else {
options.database_type = answer.database_type
ormType()
}
export const databaseConfirmQuestion = () => {
inquirer
.prompt(dbQuestion)
.then((answer) => {
if (answer.dbQuestion === true) {
databaseType();
} else if(answer.dbQuestion === false) {
options.database = answer.dbQuestion;
repoConditions();
}
})
.catch((error) => {
if (error.isTtyError) {
} else {
}
});
}
.catch((error) => {
if (error.isTtyError) {
} else {
}
});
};
28 changes: 28 additions & 0 deletions packages/yonode/src/lib/prompt/dbType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import inquirer from 'inquirer'
import { mongodbOrm } from '../../orm/mongoDB.js';
import { ormType } from '../../orm/orm.js';
import { options } from '../../index.js';
import { databaseQuestion } from '../questions.js';

export const databaseType = () => {
inquirer.prompt(
databaseQuestion
).then(answer => {
if (answer.database_type === 'MongoDB') {
options.database_type = answer.database_type
mongodbOrm()
} else if (answer.database_type === 'MySQL') {
options.database_type = answer.database_type
ormType()
}
else {
options.database_type = answer.database_type
ormType()
}
})
.catch((error) => {
if (error.isTtyError) {
} else {
}
});
}
8 changes: 8 additions & 0 deletions packages/yonode/src/lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export const languageType = {
default: "JavaScript",
}

export const dbQuestion = [
{
type: "confirm",
name: "dbQuestion",
message: "Do you need database?",
},
]

export const databaseQuestion = [
{
type: "list",
Expand Down
6 changes: 6 additions & 0 deletions packages/yonode/src/lib/repoConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export const repoConditions = () => {
switch (true) {
// JavaScript for NoAuth

// NoDB
case options.language_type === "JavaScript" &&
options.database === false:
cloneRepo(projectName, "JS-NoDB-Template");
break;

// MongoDB
case options.language_type === "JavaScript" &&
options.database_type === "MongoDB" &&
Expand Down

0 comments on commit 0ced33e

Please sign in to comment.