Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 0ced33e

Browse files
authored
feat: added JS-NoDB-Template functionality #367
feat: added JS-NoDB-Template functionality
2 parents 72fdda0 + f91ab60 commit 0ced33e

File tree

5 files changed

+67
-29
lines changed

5 files changed

+67
-29
lines changed

packages/yonode/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
import { execSync } from "child_process";
1111
import fs from "fs";
12-
import path, { basename } from "path";
1312
import inquirer from "inquirer";
13+
import path, { basename } from "path";
1414
import "./lib/programOptions.js";
15-
import { databaseType } from "./lib/prompt/db.js";
15+
import { databaseConfirmQuestion } from "./lib/prompt/db.js";
1616
import { languageType } from "./lib/questions.js";
1717

1818
export const options = {
1919
language_type: "",
20+
database: true,
2021
database_type: "",
2122
orm_type: "",
2223
auth: false,
@@ -144,7 +145,7 @@ function main() {
144145
process.exit(0);
145146
}
146147
options.language_type = answer.language_type;
147-
databaseType();
148+
databaseConfirmQuestion();
148149
})
149150
.catch((error) => {
150151
if (error.isTtyError) {

packages/yonode/src/lib/prompt/db.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
import inquirer from 'inquirer'
2-
import { mongodbOrm } from '../../orm/mongoDB.js';
3-
import { ormType } from '../../orm/orm.js';
4-
import { options } from '../../index.js';
5-
import { databaseQuestion } from '../questions.js';
1+
import inquirer from "inquirer";
2+
import { options } from "../../index.js";
3+
import { dbQuestion } from "../questions.js";
4+
import { repoConditions } from "../repoConditions.js";
5+
import { databaseType } from "./dbType.js";
66

7-
export const databaseType = () => {
8-
inquirer.prompt(
9-
databaseQuestion
10-
).then(answer => {
11-
if (answer.database_type === 'MongoDB') {
12-
options.database_type = answer.database_type
13-
mongodbOrm()
14-
} else if (answer.database_type === 'MySQL') {
15-
options.database_type = answer.database_type
16-
ormType()
17-
}
18-
else {
19-
options.database_type = answer.database_type
20-
ormType()
21-
}
7+
export const databaseConfirmQuestion = () => {
8+
inquirer
9+
.prompt(dbQuestion)
10+
.then((answer) => {
11+
if (answer.dbQuestion === true) {
12+
databaseType();
13+
} else if(answer.dbQuestion === false) {
14+
options.database = answer.dbQuestion;
15+
repoConditions();
16+
}
2217
})
23-
.catch((error) => {
24-
if (error.isTtyError) {
25-
} else {
26-
}
27-
});
28-
}
18+
.catch((error) => {
19+
if (error.isTtyError) {
20+
} else {
21+
}
22+
});
23+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import inquirer from 'inquirer'
2+
import { mongodbOrm } from '../../orm/mongoDB.js';
3+
import { ormType } from '../../orm/orm.js';
4+
import { options } from '../../index.js';
5+
import { databaseQuestion } from '../questions.js';
6+
7+
export const databaseType = () => {
8+
inquirer.prompt(
9+
databaseQuestion
10+
).then(answer => {
11+
if (answer.database_type === 'MongoDB') {
12+
options.database_type = answer.database_type
13+
mongodbOrm()
14+
} else if (answer.database_type === 'MySQL') {
15+
options.database_type = answer.database_type
16+
ormType()
17+
}
18+
else {
19+
options.database_type = answer.database_type
20+
ormType()
21+
}
22+
})
23+
.catch((error) => {
24+
if (error.isTtyError) {
25+
} else {
26+
}
27+
});
28+
}

packages/yonode/src/lib/questions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ export const languageType = {
66
default: "JavaScript",
77
}
88

9+
export const dbQuestion = [
10+
{
11+
type: "confirm",
12+
name: "dbQuestion",
13+
message: "Do you need database?",
14+
},
15+
]
16+
917
export const databaseQuestion = [
1018
{
1119
type: "list",

packages/yonode/src/lib/repoConditions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ export const repoConditions = () => {
44
switch (true) {
55
// JavaScript for NoAuth
66

7+
// NoDB
8+
case options.language_type === "JavaScript" &&
9+
options.database === false:
10+
cloneRepo(projectName, "JS-NoDB-Template");
11+
break;
12+
713
// MongoDB
814
case options.language_type === "JavaScript" &&
915
options.database_type === "MongoDB" &&

0 commit comments

Comments
 (0)