@dolphjs/cli 1.1.23 → 1.2.0
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.
- package/dist/generators/spring/generate_spring_service.js +1 -1
- package/dist/generators/spring/generate_spring_socket_service.js +46 -0
- package/dist/generators/templates/socket_service_template.js +25 -0
- package/dist/generators/templates/spring_service_template.js +4 -8
- package/dist/utils/package_generator.js +7 -0
- package/dist/utils/write_package_json.js +2 -2
- package/package.json +1 -1
|
@@ -23,7 +23,7 @@ export const generateSpringServiceFile = async (componentName, serviceDir, isMon
|
|
|
23
23
|
await writeFileAsync(serviceDir, generateSpringService(componentName, isMongo, isMySql));
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
|
-
dolphMsg.errorRed(error.toString());
|
|
26
|
+
dolphMsg.errorRed(error.message.toString());
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
export const generateService = async (name, isMongo, isMySql) => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFile } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { promisify } from "util";
|
|
4
|
+
import { dolphMsg } from "../../helpers/messages.js";
|
|
5
|
+
import { generateSocketService } from "../templates/socket_service_template.js";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
const writeFileAsync = promisify(writeFile);
|
|
8
|
+
const createServiceDirectory = (componentName) => {
|
|
9
|
+
const projectRoot = path.join(process.cwd());
|
|
10
|
+
const userServicePath = path.join(projectRoot, `src/shared/${componentName}`);
|
|
11
|
+
if (!existsSync(userServicePath)) {
|
|
12
|
+
mkdirSync(userServicePath);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const findServiceDirectory = (componentName) => {
|
|
16
|
+
const rootDir = process.cwd();
|
|
17
|
+
const possibleDirs = [`src/shared/${componentName}`];
|
|
18
|
+
const serviceDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
19
|
+
return serviceDir ? path.join(rootDir, serviceDir) : null;
|
|
20
|
+
};
|
|
21
|
+
export const generateSocketServiceFIle = async (componentName, serviceDir) => {
|
|
22
|
+
try {
|
|
23
|
+
await writeFileAsync(serviceDir, generateSocketService(componentName));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
dolphMsg.errorRed(error.message.toString());
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const generateSocket = async (name) => {
|
|
30
|
+
if (!name) {
|
|
31
|
+
name = "";
|
|
32
|
+
}
|
|
33
|
+
let serviceDir = findServiceDirectory("socket");
|
|
34
|
+
if (!serviceDir) {
|
|
35
|
+
createServiceDirectory("socket");
|
|
36
|
+
serviceDir = findServiceDirectory("socket");
|
|
37
|
+
}
|
|
38
|
+
const serviceFilePath = path.join(serviceDir + `/${name.length ? name : "events"}.socket.service.ts`);
|
|
39
|
+
try {
|
|
40
|
+
await generateSocketServiceFIle(name, path.join(serviceFilePath));
|
|
41
|
+
dolphMsg.info(`${chalk.blue(`${name}.socket.service.ts`)} generated successfully.`);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
dolphMsg.errorRed(e);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const generateSocketService = (componentName) => {
|
|
2
|
+
let template;
|
|
3
|
+
const capitalizeFirstLetter = (str) => {
|
|
4
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
5
|
+
};
|
|
6
|
+
const className = capitalizeFirstLetter(componentName || "") + "SocketService";
|
|
7
|
+
template = `import { DolphSocketServiceHandler } from '@dolphjs/dolph/classes';
|
|
8
|
+
import { Dolph } from '@dolphjs/dolph/common';
|
|
9
|
+
|
|
10
|
+
export class ${className} extends DolphSocketServiceHandler<Dolph> {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.socketService;
|
|
14
|
+
this.handleEvents();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private handleEvents() {
|
|
18
|
+
this.socket.on('connection', (socket) => {
|
|
19
|
+
socket.emit('connected', 'connection successful');
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
return template;
|
|
25
|
+
};
|
|
@@ -5,8 +5,7 @@ export const generateSpringService = (componentName, isMongo, isMySql) => {
|
|
|
5
5
|
};
|
|
6
6
|
const className = capitalizeFirstLetter(componentName) + "Service";
|
|
7
7
|
if (isMongo && isMySql) {
|
|
8
|
-
template = `
|
|
9
|
-
import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
8
|
+
template = `import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
10
9
|
import { Dolph } from "@dolphjs/dolph/common";
|
|
11
10
|
import { InjectMongo, InjectMySQL } from "@dolphjs/dolph/decorators";
|
|
12
11
|
import { Model } from "mongoose";
|
|
@@ -29,8 +28,7 @@ export class ${className} extends DolphServiceHandler<Dolph> {
|
|
|
29
28
|
`;
|
|
30
29
|
}
|
|
31
30
|
if (isMongo) {
|
|
32
|
-
template = `
|
|
33
|
-
import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
31
|
+
template = `import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
34
32
|
import { Dolph } from "@dolphjs/dolph/common";
|
|
35
33
|
import { InjectMongo} from "@dolphjs/dolph/decorators";
|
|
36
34
|
import { Model } from "mongoose";
|
|
@@ -49,8 +47,7 @@ export class ${className} extends DolphServiceHandler<Dolph> {
|
|
|
49
47
|
`;
|
|
50
48
|
}
|
|
51
49
|
if (isMySql) {
|
|
52
|
-
template = `
|
|
53
|
-
import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
50
|
+
template = `import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
54
51
|
import { Dolph } from "@dolphjs/dolph/common";
|
|
55
52
|
import { InjectMySQL } from "@dolphjs/dolph/decorators";
|
|
56
53
|
import { ModelStatic, Model } from "sequelize";
|
|
@@ -69,8 +66,7 @@ export class ${className} extends DolphServiceHandler<Dolph> {
|
|
|
69
66
|
`;
|
|
70
67
|
}
|
|
71
68
|
if (!isMongo && !isMySql) {
|
|
72
|
-
template = `
|
|
73
|
-
import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
69
|
+
template = `import { DolphServiceHandler } from "@dolphjs/dolph/classes";
|
|
74
70
|
import { Dolph } from "@dolphjs/dolph/common";
|
|
75
71
|
|
|
76
72
|
|
|
@@ -12,6 +12,7 @@ import { dolphMsg } from "../helpers/messages.js";
|
|
|
12
12
|
import { generateComponent } from "../generators/spring/generate_spring_component.js";
|
|
13
13
|
import { addComponentToServerFile } from "../registers/register_component.js";
|
|
14
14
|
import { addControllerInComponentFIle } from "../registers/register_controllers_in_components.js";
|
|
15
|
+
import { generateSocket } from "../generators/spring/generate_spring_socket_service.js";
|
|
15
16
|
export const packageGenerator = () => {
|
|
16
17
|
program
|
|
17
18
|
.command("generate")
|
|
@@ -21,6 +22,7 @@ export const packageGenerator = () => {
|
|
|
21
22
|
.option("-r, --route" + chalk.bold(chalk.blue(" <name>")), "Generates a dolphjs routes file.")
|
|
22
23
|
.option("-m, --model" + chalk.bold(chalk.blue(" <name>")), "Generates a dolphjs models file.")
|
|
23
24
|
.option("-com, --component" + chalk.bold(chalk.blue(" <name>")), "Generates a dolphjs spring component file.")
|
|
25
|
+
.option("-soc, --socket" + chalk.bold(chalk.blue(" <name> ")), "Generate a dolphjs socket service and component.")
|
|
24
26
|
.option("-a, --all" + chalk.bold(chalk.blue(" <name> ")), "Generates dolphjs controllers, routes, models and services files for the name paramter.")
|
|
25
27
|
.action(async (name, _options) => {
|
|
26
28
|
const promises = Object.entries(name).map(async ([key, value]) => {
|
|
@@ -45,6 +47,11 @@ export const packageGenerator = () => {
|
|
|
45
47
|
await mysqlGen.generateConfig(value.toString());
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
if (key && key.toLowerCase().includes("socket") && value) {
|
|
51
|
+
// create socket service
|
|
52
|
+
await generateSocket(value.toString());
|
|
53
|
+
// create socket component
|
|
54
|
+
}
|
|
48
55
|
if (key && key.toLowerCase().includes("component") && value) {
|
|
49
56
|
await generateComponent(value.toString());
|
|
50
57
|
}
|
|
@@ -22,7 +22,7 @@ export function writePackageJsonFile(name, extension) {
|
|
|
22
22
|
"clean": "rm -r app && rm -r logs"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@dolphjs/dolph": "1.
|
|
25
|
+
"@dolphjs/dolph": "^1.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/cli": "^0.1.62",
|
|
@@ -52,7 +52,7 @@ export function writePackageJsonFile(name, extension) {
|
|
|
52
52
|
"start": "dolph start"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@dolphjs/dolph": "1.
|
|
55
|
+
"@dolphjs/dolph": "^1.2.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|