@dolphjs/cli 1.1.15 → 1.1.17
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.
|
@@ -38,7 +38,7 @@ export const generateComponent = async (name) => {
|
|
|
38
38
|
}
|
|
39
39
|
const componentFilePath = path.join(componentDir + `/${name}.component.ts`);
|
|
40
40
|
try {
|
|
41
|
-
|
|
41
|
+
generateSpringComponentFile(name, path.join(componentFilePath));
|
|
42
42
|
dolphMsg.info(`${chalk.blue(`${name}.component.ts`)} generated successfully for ${chalk.blue(`${name}`)} component.`);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
@@ -7,7 +7,7 @@ const findComponentsDirectory = (componentName) => {
|
|
|
7
7
|
const srcDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
8
8
|
return srcDir ? path.join(rootDir, srcDir) : null;
|
|
9
9
|
};
|
|
10
|
-
export const addControllerInComponentFIle = (componentName) => {
|
|
10
|
+
export const addControllerInComponentFIle = async (componentName) => {
|
|
11
11
|
if (!componentName) {
|
|
12
12
|
dolphMsg.errorRed("component extension or name is required! 🤨");
|
|
13
13
|
}
|
|
@@ -22,6 +22,8 @@ export const addControllerInComponentFIle = (componentName) => {
|
|
|
22
22
|
try {
|
|
23
23
|
if (!existsSync(componentPath)) {
|
|
24
24
|
const fileContent = `import { Component } from "@dolphjs/dolph/decorators";
|
|
25
|
+
import { ${capitalizedString}Controller } from "./${componentName}.controller";
|
|
26
|
+
|
|
25
27
|
@Component({ controllers: [${capitalizedString}Controller] })
|
|
26
28
|
export class ${capitalizedString}Component {}
|
|
27
29
|
`;
|
|
@@ -31,8 +33,16 @@ export class ${capitalizedString}Component {}
|
|
|
31
33
|
const fileContent = readFileSync(componentPath, "utf8");
|
|
32
34
|
const newComponentInstance = `${capitalizedString}Controller`;
|
|
33
35
|
if (!fileContent.includes(importStatement)) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
+
const controllersArrayMatch = fileContent.match(/@Component\(\s*{\s*controllers:\s*\[([^\]]*)\]\s*}\s*\)/);
|
|
37
|
+
if (controllersArrayMatch) {
|
|
38
|
+
const existingCode = controllersArrayMatch[1].trim();
|
|
39
|
+
let fileContents;
|
|
40
|
+
fileContents = fileContent.replace(existingCode, `${existingCode.length > 0
|
|
41
|
+
? existingCode + `, ${newComponentInstance}`
|
|
42
|
+
: newComponentInstance}`);
|
|
43
|
+
const updatedContents = `${importStatement}\n${fileContents}`;
|
|
44
|
+
writeFileSync(componentPath, updatedContents);
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
47
|
if (fileContent.includes(`const dolph`)) {
|
|
38
48
|
// add new controller class to the existing array
|
|
@@ -23,54 +23,50 @@ export const packageGenerator = () => {
|
|
|
23
23
|
.option("-com, --component" + chalk.bold(chalk.blue(" <name>")), "Generates a dolphjs spring component file.")
|
|
24
24
|
.option("-a, --all" + chalk.bold(chalk.blue(" <name> ")), "Generates dolphjs controllers, routes, models and services files for the name paramter.")
|
|
25
25
|
.action(async (name, _options) => {
|
|
26
|
-
Object.entries(name).
|
|
27
|
-
// generates controller files for the paramter name
|
|
26
|
+
const promises = Object.entries(name).map(async ([key, value]) => {
|
|
28
27
|
if (key && key.toLowerCase().includes("controller") && value) {
|
|
29
|
-
controllerGen.generateController(value.toString());
|
|
28
|
+
await controllerGen.generateController(value.toString());
|
|
30
29
|
}
|
|
31
|
-
// generates service files for the paramter name
|
|
32
30
|
if (key && key.toLowerCase().includes("service") && value) {
|
|
33
|
-
serviceGen.generateService(value.toString());
|
|
31
|
+
await serviceGen.generateService(value.toString());
|
|
34
32
|
}
|
|
35
|
-
// generatess routes files for the paramter name
|
|
36
33
|
if (key && key.toLowerCase().includes("route") && value) {
|
|
37
34
|
if (readConfig().routing === "spring") {
|
|
38
35
|
dolphMsg.errorGray("cannot create routes file for spring routing.");
|
|
39
36
|
}
|
|
40
37
|
else {
|
|
41
|
-
routesGen.generateRouter(value.toString());
|
|
42
|
-
addRoutesIndexFile(value.toString(), readConfig);
|
|
38
|
+
await routesGen.generateRouter(value.toString());
|
|
39
|
+
await addRoutesIndexFile(value.toString(), readConfig);
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
// generatess model fles for the paramter name
|
|
46
42
|
if (key && key.toLowerCase().includes("model") && value) {
|
|
47
|
-
modelGen.generateModel(value.toString());
|
|
43
|
+
await modelGen.generateModel(value.toString());
|
|
48
44
|
if (readConfig().database === "mysql") {
|
|
49
|
-
mysqlGen.generateConfig(value.toString());
|
|
45
|
+
await mysqlGen.generateConfig(value.toString());
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
if (key && key.toLowerCase().includes("component") && value) {
|
|
53
|
-
generateComponent(value.toString());
|
|
49
|
+
await generateComponent(value.toString());
|
|
54
50
|
}
|
|
55
|
-
// generates files for all the above options
|
|
56
51
|
if (key && key.toLowerCase().includes("all") && value) {
|
|
57
|
-
modelGen.generateModel(value.toString());
|
|
52
|
+
await modelGen.generateModel(value.toString());
|
|
58
53
|
if (readConfig().database === "mysql") {
|
|
59
|
-
mysqlGen.generateConfig(value.toString());
|
|
54
|
+
await mysqlGen.generateConfig(value.toString());
|
|
60
55
|
}
|
|
61
|
-
serviceGen.generateService(value.toString());
|
|
62
|
-
controllerGen.generateController(value.toString());
|
|
56
|
+
await serviceGen.generateService(value.toString());
|
|
57
|
+
await controllerGen.generateController(value.toString());
|
|
63
58
|
if (readConfig().routing === "express") {
|
|
64
|
-
routesGen.generateRouter(value.toString());
|
|
65
|
-
addRoutesIndexFile(value.toString(), readConfig);
|
|
66
|
-
addServerFile(readConfig);
|
|
59
|
+
await routesGen.generateRouter(value.toString());
|
|
60
|
+
await addRoutesIndexFile(value.toString(), readConfig);
|
|
61
|
+
await addServerFile(readConfig);
|
|
67
62
|
}
|
|
68
63
|
else {
|
|
69
|
-
generateComponent(value.toString());
|
|
70
|
-
addControllerInComponentFIle(value.toString());
|
|
71
|
-
addComponentToServerFile(value.toString());
|
|
64
|
+
await generateComponent(value.toString());
|
|
65
|
+
await addControllerInComponentFIle(value.toString());
|
|
66
|
+
await addComponentToServerFile(value.toString());
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
69
|
});
|
|
70
|
+
await Promise.all(promises);
|
|
75
71
|
});
|
|
76
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
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",
|