@dolphjs/cli 1.1.9 โ 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
5
|
import { resolveModelContent } from "./resolvers/resolve_model_content.js";
|
|
6
|
+
import { generateModel as generateSpringModel } from "./spring/generate_spring_model.js";
|
|
6
7
|
const createModelDirectory = () => {
|
|
7
8
|
const projectRoot = path.join(process.cwd());
|
|
8
9
|
const userModelFilePath = path.join(projectRoot, "/src/models");
|
|
@@ -34,28 +35,33 @@ export const generateModelFile = async (name, modelDir, readConfig) => {
|
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
37
|
export const generateModel = async (name) => {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
let modelDir = findModelDirectory();
|
|
40
|
-
if (!modelDir) {
|
|
41
|
-
//TODO: create one if it doesn't exist
|
|
42
|
-
// console.log(chalk.bold(chalk.red("Model directory doesn't exist ๐คจ")));
|
|
43
|
-
// return;
|
|
44
|
-
createModelDirectory();
|
|
45
|
-
modelDir = findModelDirectory();
|
|
38
|
+
if (readConfig().routing === "spring") {
|
|
39
|
+
generateSpringModel(name, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
else {
|
|
42
|
+
if (!name)
|
|
43
|
+
chalk.bold(chalk.red("Model extension or name is required! ๐คจ"));
|
|
44
|
+
let modelDir = findModelDirectory();
|
|
45
|
+
if (!modelDir) {
|
|
46
|
+
//TODO: create one if it doesn't exist
|
|
47
|
+
// console.log(chalk.bold(chalk.red("Model directory doesn't exist ๐คจ")));
|
|
48
|
+
// return;
|
|
49
|
+
createModelDirectory();
|
|
50
|
+
modelDir = findModelDirectory();
|
|
51
|
+
}
|
|
52
|
+
const modelDirName = path.join(modelDir, name);
|
|
53
|
+
const modelFilePath = path.join(modelDirName + `/${name}.model.${readConfig().language}`);
|
|
54
|
+
try {
|
|
55
|
+
// Create the generate controller path
|
|
56
|
+
mkdirSync(modelDirName);
|
|
57
|
+
//TODO: if no index.ts file, create one too
|
|
58
|
+
generateModelFile(name, path.join(modelFilePath), readConfig
|
|
59
|
+
// modelDirName,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
64
|
+
}
|
|
65
|
+
console.log(`${chalk.bold(chalk.green(`${name}.model.${readConfig().language} generated successfully! ๐`))}`);
|
|
59
66
|
}
|
|
60
|
-
console.log(`${chalk.bold(chalk.green(`${name}.model.${readConfig().language} generated successfully! ๐`))}`);
|
|
61
67
|
};
|
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
5
|
import { resolveServiceContent } from "./resolvers/resolve_service_content.js";
|
|
6
|
+
import { generateService as generateSpringService } from "./spring/generate_spring_service.js";
|
|
6
7
|
const createServiceDirectory = () => {
|
|
7
8
|
const projectRoot = path.join(process.cwd());
|
|
8
9
|
const userServiceFilePath = path.join(projectRoot, "/src/services");
|
|
@@ -34,30 +35,37 @@ export const generateServiceFile = async (name, serviceDir, readConfig) => {
|
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
37
|
export const generateService = async (name) => {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
let serviceDir = findServiceDirectory();
|
|
40
|
-
if (!serviceDir) {
|
|
41
|
-
//TODO: create one if it doesn't exist
|
|
42
|
-
// console.log(chalk.bold(chalk.red("Service directory doesn't exist ๐คจ")));
|
|
43
|
-
// return;
|
|
44
|
-
createServiceDirectory();
|
|
45
|
-
serviceDir = findServiceDirectory();
|
|
38
|
+
if (readConfig().routing === "spring") {
|
|
39
|
+
generateSpringService(name, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
else {
|
|
42
|
+
{
|
|
43
|
+
if (!name)
|
|
44
|
+
chalk.bold(chalk.red("Service extension or name is required! ๐คจ"));
|
|
45
|
+
let serviceDir = findServiceDirectory();
|
|
46
|
+
if (!serviceDir) {
|
|
47
|
+
//TODO: create one if it doesn't exist
|
|
48
|
+
// console.log(chalk.bold(chalk.red("Service directory doesn't exist ๐คจ")));
|
|
49
|
+
// return;
|
|
50
|
+
createServiceDirectory();
|
|
51
|
+
serviceDir = findServiceDirectory();
|
|
52
|
+
}
|
|
53
|
+
const serviceDirName = path.join(serviceDir, name);
|
|
54
|
+
const serviceFilePath = path.join(serviceDirName + `/${name}.service.${readConfig().language}`);
|
|
55
|
+
try {
|
|
56
|
+
// Create the generate controller path
|
|
57
|
+
if (readConfig().generateFolder === "true" || true) {
|
|
58
|
+
mkdirSync(serviceDirName);
|
|
59
|
+
}
|
|
60
|
+
//TODO: if no index.ts file, create one too
|
|
61
|
+
generateServiceFile(name, path.join(serviceFilePath), readConfig
|
|
62
|
+
// serviceDirName,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
67
|
+
}
|
|
53
68
|
}
|
|
54
|
-
|
|
55
|
-
generateServiceFile(name, path.join(serviceFilePath), readConfig
|
|
56
|
-
// serviceDirName,
|
|
57
|
-
);
|
|
69
|
+
console.log(`${chalk.bold(chalk.green(`${name}.service.${readConfig().language} generated successfully! ๐`))}`);
|
|
58
70
|
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
console.log(chalk.bold(chalk.red(e)));
|
|
61
|
-
}
|
|
62
|
-
console.log(`${chalk.bold(chalk.green(`${name}.service.${readConfig().language} generated successfully! ๐`))}`);
|
|
63
71
|
};
|
|
@@ -25,7 +25,7 @@ export const addComponentToServerFile = (componentName) => {
|
|
|
25
25
|
}
|
|
26
26
|
const serverPath = path.join(serverDir, "server.ts");
|
|
27
27
|
const capitalizedString = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
28
|
-
const importStatement = `import { ${capitalizedString}Component } from "./${componentName}/${componentName}.component
|
|
28
|
+
const importStatement = `import { ${capitalizedString}Component } from "./${componentName}/${componentName}.component";`;
|
|
29
29
|
try {
|
|
30
30
|
if (!existsSync(serverPath)) {
|
|
31
31
|
const fileContent = `import { DolphFactory } from "@dolphjs/dolph";
|
|
@@ -39,13 +39,12 @@ dolph.start();
|
|
|
39
39
|
const fileContent = readFileSync(serverPath, "utf8");
|
|
40
40
|
const newComponentInstance = `${capitalizedString}Component`;
|
|
41
41
|
if (!fileContent.includes(importStatement)) {
|
|
42
|
-
const updatedContent =
|
|
43
|
-
${importStatement}\n${fileContent}}`;
|
|
42
|
+
const updatedContent = `${importStatement}\n${fileContent}`;
|
|
44
43
|
writeFileSync(serverPath, updatedContent);
|
|
45
44
|
}
|
|
46
45
|
if (fileContent.includes(`const dolph`)) {
|
|
47
46
|
// add new controller class to the existing array
|
|
48
|
-
const routesArrayMatch = fileContent.match(/const dolph = new DolphFactory\
|
|
47
|
+
const routesArrayMatch = fileContent.match(/const dolph = new DolphFactory\(([^)]+)\);/);
|
|
49
48
|
if (routesArrayMatch) {
|
|
50
49
|
const existingCode = routesArrayMatch[1].trim();
|
|
51
50
|
let fileContents;
|
|
@@ -10,8 +10,6 @@ import { addRoutesIndexFile } from "../registers/register_routes.js";
|
|
|
10
10
|
import { addServerFile } from "../registers/server_file_routes.js";
|
|
11
11
|
import { dolphMsg } from "../helpers/messages.js";
|
|
12
12
|
import { generateComponent } from "../generators/spring/generate_spring_component.js";
|
|
13
|
-
import { generateService } from "../generators/spring/generate_spring_service.js";
|
|
14
|
-
import { generateModel } from "../generators/spring/generate_spring_model.js";
|
|
15
13
|
import { addComponentToServerFile } from "../registers/register_component.js";
|
|
16
14
|
export const packageGenerator = () => {
|
|
17
15
|
program
|
|
@@ -31,12 +29,7 @@ export const packageGenerator = () => {
|
|
|
31
29
|
}
|
|
32
30
|
// generates service files for the paramter name
|
|
33
31
|
if (key && key.toLowerCase().includes("service") && value) {
|
|
34
|
-
|
|
35
|
-
serviceGen.generateService(value.toString());
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
generateService(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
39
|
-
}
|
|
32
|
+
serviceGen.generateService(value.toString());
|
|
40
33
|
}
|
|
41
34
|
// generatess routes files for the paramter name
|
|
42
35
|
if (key && key.toLowerCase().includes("route") && value) {
|
|
@@ -50,14 +43,9 @@ export const packageGenerator = () => {
|
|
|
50
43
|
}
|
|
51
44
|
// generatess model fles for the paramter name
|
|
52
45
|
if (key && key.toLowerCase().includes("model") && value) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
mysqlGen.generateConfig(value.toString());
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
generateModel(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
46
|
+
modelGen.generateModel(value.toString());
|
|
47
|
+
if (readConfig().database === "mysql") {
|
|
48
|
+
mysqlGen.generateConfig(value.toString());
|
|
61
49
|
}
|
|
62
50
|
}
|
|
63
51
|
if (key && key.toLowerCase().includes("component") && value) {
|
|
@@ -65,22 +53,12 @@ export const packageGenerator = () => {
|
|
|
65
53
|
}
|
|
66
54
|
// generates files for all the above options
|
|
67
55
|
if (key && key.toLowerCase().includes("all") && value) {
|
|
68
|
-
|
|
69
|
-
modelGen.generateModel(value.toString());
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
generateModel(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
73
|
-
}
|
|
56
|
+
modelGen.generateModel(value.toString());
|
|
74
57
|
if (readConfig().database === "mysql") {
|
|
75
58
|
mysqlGen.generateConfig(value.toString());
|
|
76
59
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
controllerGen.generateController(value.toString());
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
generateService(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
83
|
-
}
|
|
60
|
+
serviceGen.generateService(value.toString());
|
|
61
|
+
controllerGen.generateController(value.toString());
|
|
84
62
|
if (readConfig().routing === "express") {
|
|
85
63
|
routesGen.generateRouter(value.toString());
|
|
86
64
|
addRoutesIndexFile(value.toString(), readConfig);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "The dolphjs-cli is a tool for efficient intialization and management of a dolphjs project",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"repository": "https://github.com/dolphjs/dolph-cli.git",
|