@dolphjs/cli 1.1.7 โ†’ 1.1.9

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/README.md CHANGED
@@ -27,7 +27,7 @@ to install all packages .
27
27
  - models
28
28
  - routes
29
29
 
30
- It is recommended to make use of the `generate` command when one was to create these files because it generates code the dolphjs way. In a scenario when you want to create files for all of the above, let's say you want to write code for user logic and functionalities, use the `-a` flag, as in:
30
+ It is recommended to make use of the `generate` command when one wants to create these files because it generates code the dolphjs way. In a scenario when you want to create files for all of the above, let's say you want to write code for user logic and functionalities, use the `-a` flag, as in:
31
31
 
32
32
  ```bash
33
33
  dolph-cli g -a user
@@ -61,4 +61,4 @@ the command above creates a service, controller, model and routes file for `user
61
61
 
62
62
  ## Credit
63
63
 
64
- dolphjs-cli is inspired by methane-cli [https://github.com/adedoyin/methane-cli]
64
+ dolphjs-cli is inspired by methane-cli [https://github.com/adedoyin-Emmanuel/methane-cli]
@@ -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 { resolveControllerContent } from "./resolvers/resolve_controller_content.js";
6
+ import { generateController as generateSpringController } from "./spring/generate_spring_controller.js";
6
7
  const createControllerDirectory = () => {
7
8
  const projectRoot = path.join(process.cwd());
8
9
  const userControllerFilePath = path.join(projectRoot, "/src/controllers");
@@ -34,32 +35,32 @@ export const generateControllerFile = async (name, controllerDir, readConfig) =>
34
35
  });
35
36
  };
36
37
  export const generateController = async (name) => {
37
- if (!name)
38
- chalk.bold(chalk.red("Controller extension or name is required! ๐Ÿคจ"));
39
- let controllerDir = findControllerDirectory();
40
- if (!controllerDir) {
41
- //TODO: create one if it doesn't exist
42
- // console.log(
43
- // chalk.bold(chalk.red("controller directory doesn't exist ๐Ÿคจ"))
44
- // );
45
- // return;
46
- createControllerDirectory();
47
- controllerDir = findControllerDirectory();
38
+ if (readConfig().routing === "spring") {
39
+ generateSpringController(name);
48
40
  }
49
- const controllerDirName = path.join(controllerDir, name);
50
- const controllerFilePath = path.join(controllerDirName + `/${name}.controller.${readConfig().language}`);
51
- try {
52
- // Create the generate controller path
53
- if (readConfig().generateFolder === "true" || true) {
54
- mkdirSync(controllerDirName);
41
+ else {
42
+ if (!name)
43
+ chalk.bold(chalk.red("Controller extension or name is required! ๐Ÿคจ"));
44
+ let controllerDir = findControllerDirectory();
45
+ if (!controllerDir) {
46
+ createControllerDirectory();
47
+ controllerDir = findControllerDirectory();
55
48
  }
56
- //TODO: if no index.ts file, create one too
57
- generateControllerFile(name, path.join(controllerFilePath), readConfig
58
- // controllerDirName,
59
- );
60
- }
61
- catch (e) {
62
- console.log(chalk.bold(chalk.red(e)));
49
+ const controllerDirName = path.join(controllerDir, name);
50
+ const controllerFilePath = path.join(controllerDirName + `/${name}.controller.${readConfig().language}`);
51
+ try {
52
+ // Create the generate controller path
53
+ if (readConfig().generateFolder === "true" || true) {
54
+ mkdirSync(controllerDirName);
55
+ }
56
+ //TODO: if no index.ts file, create one too
57
+ generateControllerFile(name, path.join(controllerFilePath), readConfig
58
+ // controllerDirName,
59
+ );
60
+ }
61
+ catch (e) {
62
+ console.log(chalk.bold(chalk.red(e)));
63
+ }
64
+ console.log(`${chalk.bold(chalk.green(`${name}.controller.${readConfig().language} generated successfully! ๐Ÿ™ƒ`))}`);
63
65
  }
64
- console.log(`${chalk.bold(chalk.green(`${name}.controller.${readConfig().language} generated successfully! ๐Ÿ™ƒ`))}`);
65
66
  };
@@ -0,0 +1,42 @@
1
+ import { existsSync, mkdirSync, writeFile } from "fs";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ import { generateSpringComponent } from "../../generators/templates/spring_component_template.js";
5
+ import { dolphMsg } from "../../helpers/messages.js";
6
+ const createComponentDirectory = (componentName) => {
7
+ const projectRoot = path.join(process.cwd());
8
+ const userComponentPath = path.join(projectRoot, `/src/${componentName}`);
9
+ if (!existsSync(userComponentPath)) {
10
+ mkdirSync(userComponentPath);
11
+ }
12
+ };
13
+ const findComponentDirectory = (componentName) => {
14
+ const rootDir = process.cwd();
15
+ const possibleDirs = [`src/${componentName}`];
16
+ const componentDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
17
+ return componentDir ? path.join(rootDir, componentDir) : null;
18
+ };
19
+ export const generateSpringComponentFile = async (componentName, componentDir) => {
20
+ await writeFile(componentDir, generateSpringComponent(componentName), (error) => {
21
+ if (error) {
22
+ dolphMsg.errorRed(error.toString());
23
+ }
24
+ });
25
+ };
26
+ export const generateComponent = async (name) => {
27
+ if (!name)
28
+ dolphMsg.errorRed("component extension or name is required! ๐Ÿคจ");
29
+ let componentDir = findComponentDirectory(name);
30
+ if (!componentDir) {
31
+ createComponentDirectory(name);
32
+ componentDir = findComponentDirectory(name);
33
+ }
34
+ const componentFilePath = path.join(componentDir + `/${name}.component.ts`);
35
+ try {
36
+ generateSpringComponentFile(name, path.join(componentFilePath));
37
+ }
38
+ catch (e) {
39
+ dolphMsg.errorRed(e);
40
+ }
41
+ dolphMsg.info(`${chalk.blue(`${name}.component.ts`)} generated successfully for ${chalk.blue(`${name}`)} component.`);
42
+ };
@@ -0,0 +1,42 @@
1
+ import { existsSync, mkdirSync, writeFile } from "fs";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ import { generateSpringController } from "../../generators/templates/spring_controller_template.js";
5
+ import { dolphMsg } from "../../helpers/messages.js";
6
+ const createControllerDirectory = (componentName) => {
7
+ const projectRoot = path.join(process.cwd());
8
+ const userCompontrollerPath = path.join(projectRoot, `/src/${componentName}`);
9
+ if (!existsSync(userCompontrollerPath)) {
10
+ mkdirSync(userCompontrollerPath);
11
+ }
12
+ };
13
+ const findControllerDirectory = (componentName) => {
14
+ const rootDir = process.cwd();
15
+ const possibleDirs = [`src/${componentName}`];
16
+ const controllerDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
17
+ return controllerDir ? path.join(rootDir, controllerDir) : null;
18
+ };
19
+ export const generateSpringControllerFile = async (componentName, controllerDir) => {
20
+ await writeFile(controllerDir, generateSpringController(componentName), (error) => {
21
+ if (error) {
22
+ dolphMsg.errorRed(error.toString());
23
+ }
24
+ });
25
+ };
26
+ export const generateController = async (name) => {
27
+ if (!name)
28
+ dolphMsg.errorRed("controller extension or name is required! ๐Ÿคจ");
29
+ let controllerDir = findControllerDirectory(name);
30
+ if (!controllerDir) {
31
+ createControllerDirectory(name);
32
+ controllerDir = findControllerDirectory(name);
33
+ }
34
+ const controllerFilePath = path.join(controllerDir + `/${name}.controller.ts`);
35
+ try {
36
+ generateSpringControllerFile(name, path.join(controllerFilePath));
37
+ }
38
+ catch (e) {
39
+ dolphMsg.errorRed(e);
40
+ }
41
+ dolphMsg.info(`${chalk.blue(`${name}.controller.ts`)} generated successfully for ${chalk.blue(`${name}`)} component.`);
42
+ };
@@ -0,0 +1,42 @@
1
+ import { existsSync, mkdirSync, writeFile } from "fs";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ import { generateSpringModel } from "../../generators/templates/spring_model_template.js";
5
+ import { dolphMsg } from "../../helpers/messages.js";
6
+ const createModelDirectory = (componentName) => {
7
+ const projectRoot = path.join(process.cwd());
8
+ const userModelPath = path.join(projectRoot, `/src/${componentName}`);
9
+ if (!existsSync(userModelPath)) {
10
+ mkdirSync(userModelPath);
11
+ }
12
+ };
13
+ const findModelDirectory = (componentName) => {
14
+ const rootDir = process.cwd();
15
+ const possibleDirs = [`src/${componentName}`];
16
+ const modelDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
17
+ return modelDir ? path.join(rootDir, modelDir) : null;
18
+ };
19
+ export const generateSpringModelFile = async (componentName, modelDir, isMongo, isMySql) => {
20
+ await writeFile(modelDir, generateSpringModel(componentName, isMongo, isMySql), (error) => {
21
+ if (error) {
22
+ dolphMsg.errorRed(error.toString());
23
+ }
24
+ });
25
+ };
26
+ export const generateModel = async (name, isMongo, isMySql) => {
27
+ if (!name)
28
+ dolphMsg.errorRed("model extension or name is required! ๐Ÿคจ");
29
+ let modelDir = findModelDirectory(name);
30
+ if (!modelDir) {
31
+ createModelDirectory(name);
32
+ modelDir = findModelDirectory(name);
33
+ }
34
+ const modelFilePath = path.join(modelDir + `/${name}.model.ts`);
35
+ try {
36
+ generateSpringModelFile(name, path.join(modelFilePath), isMongo, isMySql);
37
+ }
38
+ catch (e) {
39
+ dolphMsg.errorRed(e);
40
+ }
41
+ dolphMsg.info(`${chalk.blue(`${name}.model.ts`)} generated successfully for ${chalk.blue(`${name}`)} component.`);
42
+ };
@@ -0,0 +1,42 @@
1
+ import { existsSync, mkdirSync, writeFile } from "fs";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ import { generateSpringService } from "../../generators/templates/spring_service_template.js";
5
+ import { dolphMsg } from "../../helpers/messages.js";
6
+ const createServiceDirectory = (componentName) => {
7
+ const projectRoot = path.join(process.cwd());
8
+ const userServicePath = path.join(projectRoot, `/src/${componentName}`);
9
+ if (!existsSync(userServicePath)) {
10
+ mkdirSync(userServicePath);
11
+ }
12
+ };
13
+ const findServiceDirectory = (componentName) => {
14
+ const rootDir = process.cwd();
15
+ const possibleDirs = [`src/${componentName}`];
16
+ const serviceDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
17
+ return serviceDir ? path.join(rootDir, serviceDir) : null;
18
+ };
19
+ export const generateSpringServiceFile = async (componentName, serviceDir, isMongo, isMySql) => {
20
+ await writeFile(serviceDir, generateSpringService(componentName, isMongo, isMySql), (error) => {
21
+ if (error) {
22
+ dolphMsg.errorRed(error.toString());
23
+ }
24
+ });
25
+ };
26
+ export const generateService = async (name, isMongo, isMySql) => {
27
+ if (!name)
28
+ dolphMsg.errorRed("service extension or name is required! ๐Ÿคจ");
29
+ let serviceDir = findServiceDirectory(name);
30
+ if (!serviceDir) {
31
+ createServiceDirectory(name);
32
+ serviceDir = findServiceDirectory(name);
33
+ }
34
+ const serviceFilePath = path.join(serviceDir + `/${name}.service.ts`);
35
+ try {
36
+ generateSpringServiceFile(name, path.join(serviceFilePath), isMongo, isMySql);
37
+ }
38
+ catch (e) {
39
+ dolphMsg.errorRed(e);
40
+ }
41
+ dolphMsg.info(`${chalk.blue(`${name}.service.ts`)} generated successfully for ${chalk.blue(`${name}`)} component.`);
42
+ };
@@ -0,0 +1,12 @@
1
+ export const generateSpringComponent = (componentName) => {
2
+ const capitalizeFirstLetter = (str) => {
3
+ return str.charAt(0).toUpperCase() + str.slice(1);
4
+ };
5
+ const className = capitalizeFirstLetter(componentName) + "Component";
6
+ const template = `import { Component } from "@dolphjs/dolph/decorators";
7
+
8
+ @Component({ controllers: [] })
9
+ export class ${className} {}
10
+ `;
11
+ return template;
12
+ };
@@ -0,0 +1,28 @@
1
+ export const generateSpringController = (componentName) => {
2
+ const capitalizeFirstLetter = (str) => {
3
+ return str.charAt(0).toUpperCase() + str.slice(1);
4
+ };
5
+ const className = capitalizeFirstLetter(componentName) + "Controller";
6
+ const template = `import { DolphControllerHandler } from "@dolphjs/dolph/classes";
7
+ import {
8
+ Dolph,
9
+ SuccessResponse,
10
+ DRequest,
11
+ DResponse
12
+ } from "@dolphjs/dolph/common";
13
+ import { Get, Route } from "@dolphjs/dolph/decorators";
14
+
15
+ @Route('${componentName}')
16
+ export class ${className} extends DolphControllerHandler<Dolph> {
17
+ constructor() {
18
+ super();
19
+ }
20
+
21
+ @Get("greet")
22
+ async greet (req: DRequest, res: DResponse) {
23
+ SuccessResponse({ res, body: { message: "you've reached the ${componentName} endpoint." } });
24
+ }
25
+ }
26
+ `;
27
+ return template;
28
+ };
@@ -0,0 +1,40 @@
1
+ export const generateSpringModel = (componentName, isMongo, isMysql) => {
2
+ let template;
3
+ const capitalizeFirstLetter = (str) => {
4
+ return str.charAt(0).toUpperCase() + str.slice(1);
5
+ };
6
+ if (isMongo) {
7
+ template = `import { Schema, Document, model } from "mongoose";
8
+
9
+ export interface I${capitalizeFirstLetter(componentName)} extends Document {
10
+
11
+ }
12
+
13
+ const ${capitalizeFirstLetter(componentName)}Schema = new Schema(
14
+ {
15
+
16
+ }
17
+ );
18
+
19
+ export const ${capitalizeFirstLetter(componentName)}Model = model<I${capitalizeFirstLetter(componentName)}>("${componentName.charAt(0) !== "s" ? `${componentName}s` : componentName}", ${capitalizeFirstLetter(componentName)}Schema);
20
+ `;
21
+ }
22
+ if (isMysql) {
23
+ template = `import { sequelizeInstance } from "@/shared/configs/db.configs";
24
+ import { DataTypes } from "sequelize";
25
+
26
+ export const ${capitalizeFirstLetter(componentName)} = sequelizeInstance.define("${componentName}", {
27
+ id: {
28
+ type: DataTypes.INTEGER,
29
+ allowNull: false,
30
+ primaryKey: true,
31
+ autoIncrement: true,
32
+ },
33
+ });
34
+ `;
35
+ }
36
+ if (!isMongo && !isMysql) {
37
+ template = ``;
38
+ }
39
+ return template;
40
+ };
@@ -0,0 +1,86 @@
1
+ export const generateSpringService = (componentName, isMongo, isMySql) => {
2
+ let template;
3
+ const capitalizeFirstLetter = (str) => {
4
+ return str.charAt(0).toUpperCase() + str.slice(1);
5
+ };
6
+ const className = capitalizeFirstLetter(componentName) + "Service";
7
+ if (isMongo && isMySql) {
8
+ template = `
9
+ import { DolphServiceHandler } from "@dolphjs/dolph/classes";
10
+ import { Dolph } from "@dolphjs/dolph/common";
11
+ import { InjectMongo, InjectMySQL } from "@dolphjs/dolph/decorators";
12
+ import { Model } from "mongoose";
13
+ import { ModelStatic, Model as SqlModel } from "sequelize";
14
+ import { ${capitalizeFirstLetter(componentName)}Model, I${capitalizeFirstLetter(componentName)} } from "./${componentName}.model";
15
+
16
+
17
+ @InjectMongo("${componentName}Model", ${capitalizeFirstLetter(componentName)}Model)
18
+ @InjectMySQL("${componentName}SqlModel", )
19
+ export class ${className} extends DolphServiceHandler<Dolph> {
20
+ ${componentName}Model!: Model<${capitalizeFirstLetter(componentName)}>;
21
+ ${componentName}SqlModel!: ModelStatic<SqlModel<any, any>>;
22
+
23
+
24
+ constructor() {
25
+ super("${className.toLowerCase()}");
26
+ }
27
+ }
28
+
29
+ `;
30
+ }
31
+ if (isMongo) {
32
+ template = `
33
+ import { DolphServiceHandler } from "@dolphjs/dolph/classes";
34
+ import { Dolph } from "@dolphjs/dolph/common";
35
+ import { InjectMongo} from "@dolphjs/dolph/decorators";
36
+ import { Model } from "mongoose";
37
+ import { ${capitalizeFirstLetter(componentName)}Model, I${capitalizeFirstLetter(componentName)} } from "./${componentName}.model";
38
+
39
+
40
+ @InjectMongo("${componentName}Model", ${capitalizeFirstLetter(componentName)}Model)
41
+ export class ${className} extends DolphServiceHandler<Dolph> {
42
+ ${componentName}Model!: Model<>;
43
+
44
+ constructor() {
45
+ super("${className.toLowerCase()}");
46
+ }
47
+ }
48
+
49
+ `;
50
+ }
51
+ if (isMySql) {
52
+ template = `
53
+ import { DolphServiceHandler } from "@dolphjs/dolph/classes";
54
+ import { Dolph } from "@dolphjs/dolph/common";
55
+ import { InjectMySQL } from "@dolphjs/dolph/decorators";
56
+ import { ModelStatic, Model } from "sequelize";
57
+
58
+
59
+ @InjectMySQL("${componentName}Model", )
60
+ export class ${className} extends DolphServiceHandler<Dolph> {
61
+ ${componentName}Model!: ModelStatic<Model<any, any>>;
62
+
63
+
64
+ constructor() {
65
+ super("${className.toLowerCase()}");
66
+ }
67
+ }
68
+
69
+ `;
70
+ }
71
+ if (!isMongo && !isMySql) {
72
+ template = `
73
+ import { DolphServiceHandler } from "@dolphjs/dolph/classes";
74
+ import { Dolph } from "@dolphjs/dolph/common";
75
+
76
+
77
+ export class ${className} extends DolphServiceHandler<Dolph> {
78
+
79
+ constructor() {
80
+ super("${className.toLowerCase()}");
81
+ }
82
+ }
83
+ `;
84
+ }
85
+ return template;
86
+ };
@@ -0,0 +1,9 @@
1
+ import chalk from "chalk";
2
+ export const dolphMsg = {
3
+ infoGreen: (message) => console.log(chalk.bold(chalk.green("[DOLPH INFO]: ")) + chalk.greenBright(message)),
4
+ infoYellow: (message) => console.log(chalk.bold(chalk.yellow("[DOLPH INFO]: ")) + chalk.yellowBright(message)),
5
+ infoBlue: (message) => console.log(chalk.bold(chalk.blue("[DOLPH INFO]: ")) + chalk.blueBright(message)),
6
+ info: (message) => console.log(chalk.bold(chalk.blue("[DOLPH INFO]: " + chalk.white(message)))),
7
+ errorRed: (message) => console.log(chalk.bold(chalk.red("[DOLPH ERROR]: ")) + chalk.redBright(message)),
8
+ errorGray: (message) => console.log(chalk.bold(chalk.bgGrey("[DOLPH ERROR]: ")) + chalk.grey(message)),
9
+ };
@@ -0,0 +1,64 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
+ import { dolphMsg } from "../helpers/messages.js";
3
+ import path from "path";
4
+ const createSrcDirectory = () => {
5
+ const projectRoot = path.join(process.cwd());
6
+ const userComponentPath = path.join(projectRoot, `/src`);
7
+ if (!existsSync(userComponentPath)) {
8
+ mkdirSync(userComponentPath);
9
+ }
10
+ };
11
+ const findSrcDirectory = () => {
12
+ const rootDir = process.cwd();
13
+ const possibleDirs = [`src`];
14
+ const srcDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
15
+ return srcDir ? path.join(rootDir, srcDir) : null;
16
+ };
17
+ export const addComponentToServerFile = (componentName) => {
18
+ if (!componentName) {
19
+ dolphMsg.errorRed("component extension or name is required! ๐Ÿคจ");
20
+ }
21
+ const serverDir = findSrcDirectory();
22
+ if (!serverDir) {
23
+ dolphMsg.errorRed("something went wrong, please make sure to use the `new` command when creating a dolph project.");
24
+ return;
25
+ }
26
+ const serverPath = path.join(serverDir, "server.ts");
27
+ const capitalizedString = componentName.charAt(0).toUpperCase() + componentName.slice(1);
28
+ const importStatement = `import { ${capitalizedString}Component } from "./${componentName}/${componentName}.component.ts";`;
29
+ try {
30
+ if (!existsSync(serverPath)) {
31
+ const fileContent = `import { DolphFactory } from "@dolphjs/dolph";
32
+ ${importStatement}
33
+ const dolph = new DolphFactory([${capitalizedString}Component]);
34
+ dolph.start();
35
+ `;
36
+ writeFileSync(serverPath, fileContent);
37
+ }
38
+ else {
39
+ const fileContent = readFileSync(serverPath, "utf8");
40
+ const newComponentInstance = `${capitalizedString}Component`;
41
+ if (!fileContent.includes(importStatement)) {
42
+ const updatedContent = `
43
+ ${importStatement}\n${fileContent}}`;
44
+ writeFileSync(serverPath, updatedContent);
45
+ }
46
+ if (fileContent.includes(`const dolph`)) {
47
+ // add new controller class to the existing array
48
+ const routesArrayMatch = fileContent.match(/const dolph = new DolphFactory\[([\s\S]]+?)\];/);
49
+ if (routesArrayMatch) {
50
+ const existingCode = routesArrayMatch[1].trim();
51
+ let fileContents;
52
+ fileContents = fileContent.replace(existingCode, `${existingCode.length > 0 ? existingCode + ", " : ""}${newComponentInstance}`);
53
+ const updatedContents = `${importStatement}\n${fileContents}`;
54
+ writeFileSync(serverPath, updatedContents);
55
+ }
56
+ }
57
+ }
58
+ dolphMsg.info(`added ${capitalizedString}Component to components array in server.ts file.`);
59
+ process.exit(0);
60
+ }
61
+ catch (e) {
62
+ dolphMsg.errorRed(e.toString());
63
+ }
64
+ };
@@ -1,7 +1,6 @@
1
1
  import chalk from "chalk";
2
2
  import { existsSync, readFileSync, writeFileSync } from "fs";
3
3
  import path from "path";
4
- // removed other possible dirs to enforce dolphjs style guide
5
4
  const findRoutesDirectory = () => {
6
5
  const rootDir = process.cwd();
7
6
  const possibleDirs = [
@@ -2,16 +2,16 @@ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
2
  import inquirer from "inquirer";
3
3
  import path from "path";
4
4
  import yaml from "js-yaml";
5
- import chalk from "chalk";
6
5
  import { writeSwcrc } from "./write_swrcc.js";
7
6
  import { writeTsConfigFile } from "./write_tsconfig.js";
8
7
  import { writeDolphConfig } from "./write_dolph_config.js";
9
8
  import { writePackageJsonFile } from "./write_package_json.js";
10
9
  import { writeGitignore } from "./write_gitignore.js";
10
+ import { dolphMsg } from "../helpers/messages.js";
11
11
  export const initDolphCli = (appname) => {
12
12
  let projectName = appname;
13
13
  if (appname.length === 0) {
14
- console.log(chalk.red(chalk.bold("Provide a name for you project or indicate with a '.' to use current directory ")));
14
+ dolphMsg.errorGray("provide a name for you project or indicate with a '.' to use current directory.");
15
15
  return;
16
16
  }
17
17
  if (appname !== ".") {
@@ -35,6 +35,7 @@ export const initDolphCli = (appname) => {
35
35
  paradigm: "oop",
36
36
  database: "mongo",
37
37
  generateFolder: true,
38
+ routing: "express",
38
39
  };
39
40
  if (!existsSync(userConfigFilePath)) {
40
41
  inquirer
@@ -60,20 +61,23 @@ export const initDolphCli = (appname) => {
60
61
  choices: ["mongo", "mysql", "postgresql", "other"],
61
62
  default: "mongo",
62
63
  },
63
- // {
64
- // type: "list",
65
- // name: "generateFolder",
66
- // message:
67
- // "Generate folder and files for the Services, Models, Controllers and Routes",
68
- // choices: ["true", "false"],
69
- // default: "true",
70
- // },
64
+ {
65
+ type: "list",
66
+ name: "routing",
67
+ message: "Which dolph routing architecture would you be using? (choosing 'spring' means that you are making use of both 'oop' & 'typescript')",
68
+ choices: ["express", "spring"],
69
+ default: "express",
70
+ },
71
71
  ])
72
72
  .then((replies) => {
73
73
  // TODO: add this to the config file:
74
- // # this is an auto generate file, please do not edit manually
74
+ const comment = "# this is an auto-generated file, please do not edit manually\n";
75
+ if ((replies.routing = "spring")) {
76
+ replies.paradigm = "oop";
77
+ replies.language = "ts";
78
+ }
75
79
  const userConfig = { ...defaultConfig, ...replies };
76
- const yamlString = yaml.dump(userConfig);
80
+ const yamlString = comment + yaml.dump(userConfig);
77
81
  writeFileSync(userConfigFilePath, yamlString, "utf8");
78
82
  if (userConfig.language === "ts") {
79
83
  writeSwcrc();
@@ -82,12 +86,12 @@ export const initDolphCli = (appname) => {
82
86
  writeDolphConfig();
83
87
  writePackageJsonFile(projectName, userConfig.language);
84
88
  writeGitignore();
85
- console.log(chalk.green(chalk.bold("dolph cli configurations have been initialized successfully ๐Ÿ˜Ž.")));
86
- console.log(chalk.green(chalk.bold("run yarn install to install dependencies in project directory and start coding ๐Ÿ˜‰.")));
89
+ dolphMsg.infoBlue("dolph configurations have been initialized successfully โœจ.");
90
+ dolphMsg.infoYellow("run `yarn install` to install dependencies in project directory and start building ๐Ÿš€.");
87
91
  process.exit(0);
88
92
  });
89
93
  }
90
94
  else {
91
- console.log(chalk.bold(chalk.cyan("I see you already have your dolph cli configurations present ๐Ÿ˜‰.")));
95
+ dolphMsg.info("I see you already have your dolph configurations present, so I'll abort gently ... ๐Ÿ˜‰.");
92
96
  }
93
97
  };
@@ -3,5 +3,5 @@ import { program } from "commander";
3
3
  export const packageDescription = () => {
4
4
  program
5
5
  .version("1.1.0")
6
- .description(chalk.cyan("The dolphjs-cli is a tool for efficient intialization and management of a dolphjs project"));
6
+ .description(chalk.cyan("The dolph-cli is a tool for efficient intialization and management of a dolphjs project"));
7
7
  };
@@ -8,23 +8,21 @@ import * as mysqlGen from "../generators/generate_mysql.js";
8
8
  import { readConfig } from "./read_user_config_path.js";
9
9
  import { addRoutesIndexFile } from "../registers/register_routes.js";
10
10
  import { addServerFile } from "../registers/server_file_routes.js";
11
+ import { dolphMsg } from "../helpers/messages.js";
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
+ import { addComponentToServerFile } from "../registers/register_component.js";
11
16
  export const packageGenerator = () => {
12
17
  program
13
18
  .command("generate")
14
19
  .alias("g")
15
20
  .option("-s, --service" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs service file.")
16
21
  .option("-c, --controller" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs controller file.")
17
- .option("-r, --routes" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs routes file.")
18
- .option("-m, --models" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs models file.")
19
- .option("-a, --all" + chalk.bold(chalk.blue("<name>")), "Generates dolphjs ocntrollers, routes, models and services files for the name paramter.")
20
- // .option(
21
- // "-in, --interfaces" + chalk.bold(chalk.blue("<name>")),
22
- // "Generates a dolphjs interfaces file."
23
- // )
24
- // .option(
25
- // "-hp, --helper" + chalk.bold(chalk.blue("<name>")),
26
- // "Generates a dolphjs helper file."
27
- // )
22
+ .option("-r, --route" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs routes file.")
23
+ .option("-m, --model" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs models file.")
24
+ .option("-com, --component" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs spring component file.")
25
+ .option("-a, --all" + chalk.bold(chalk.blue(" <name> ")), "Generates dolphjs controllers, routes, models and services files for the name paramter.")
28
26
  .action(async (name, _options) => {
29
27
  Object.entries(name).forEach(([key, value]) => {
30
28
  // generates controller files for the paramter name
@@ -33,31 +31,65 @@ export const packageGenerator = () => {
33
31
  }
34
32
  // generates service files for the paramter name
35
33
  if (key && key.toLowerCase().includes("service") && value) {
36
- serviceGen.generateService(value.toString());
34
+ if (readConfig().routing === "express") {
35
+ serviceGen.generateService(value.toString());
36
+ }
37
+ else {
38
+ generateService(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
39
+ }
37
40
  }
38
41
  // generatess routes files for the paramter name
39
- if (key && key.toLowerCase().includes("routes") && value) {
40
- routesGen.generateRouter(value.toString());
41
- addRoutesIndexFile(value.toString(), readConfig);
42
+ if (key && key.toLowerCase().includes("route") && value) {
43
+ if (readConfig().routing === "spring") {
44
+ dolphMsg.errorGray("cannot create routes file for spring routing.");
45
+ }
46
+ else {
47
+ routesGen.generateRouter(value.toString());
48
+ addRoutesIndexFile(value.toString(), readConfig);
49
+ }
42
50
  }
43
51
  // generatess model fles for the paramter name
44
- if (key && key.toLowerCase().includes("models") && value) {
45
- modelGen.generateModel(value.toString());
46
- if (readConfig().database === "mysql") {
47
- mysqlGen.generateConfig(value.toString());
52
+ if (key && key.toLowerCase().includes("model") && value) {
53
+ if (readConfig().routing === "express") {
54
+ modelGen.generateModel(value.toString());
55
+ if (readConfig().database === "mysql") {
56
+ mysqlGen.generateConfig(value.toString());
57
+ }
48
58
  }
59
+ else {
60
+ generateModel(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
61
+ }
62
+ }
63
+ if (key && key.toLowerCase().includes("component") && value) {
64
+ generateComponent(value.toString());
49
65
  }
50
66
  // generates files for all the above options
51
67
  if (key && key.toLowerCase().includes("all") && value) {
52
- modelGen.generateModel(value.toString());
68
+ if (readConfig().routing === "express") {
69
+ modelGen.generateModel(value.toString());
70
+ }
71
+ else {
72
+ generateModel(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
73
+ }
53
74
  if (readConfig().database === "mysql") {
54
75
  mysqlGen.generateConfig(value.toString());
55
76
  }
56
- serviceGen.generateService(value.toString());
57
- controllerGen.generateController(value.toString());
58
- routesGen.generateRouter(value.toString());
59
- addRoutesIndexFile(value.toString(), readConfig);
60
- addServerFile(readConfig);
77
+ if (readConfig().routing === "express") {
78
+ serviceGen.generateService(value.toString());
79
+ controllerGen.generateController(value.toString());
80
+ }
81
+ else {
82
+ generateService(value.toString(), readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
83
+ }
84
+ if (readConfig().routing === "express") {
85
+ routesGen.generateRouter(value.toString());
86
+ addRoutesIndexFile(value.toString(), readConfig);
87
+ addServerFile(readConfig);
88
+ }
89
+ else {
90
+ generateComponent(value.toString());
91
+ addComponentToServerFile(value.toString());
92
+ }
61
93
  }
62
94
  });
63
95
  // const controllerName = controller ? `${controller}` : undefined;
@@ -2,6 +2,7 @@ import { program } from "commander";
2
2
  import chalk from "chalk";
3
3
  import { readConfig } from "./read_user_config_path.js";
4
4
  import { writeConfig } from "./write_user_config.js";
5
+ import { dolphMsg } from "../helpers/messages.js";
5
6
  const dbOptions = ["mongo", "postgresql", "mysql", "other"];
6
7
  export const configurePackage = () => {
7
8
  program
@@ -18,63 +19,37 @@ export const configurePackage = () => {
18
19
  if (key && key.toLocaleLowerCase().includes("language") && value) {
19
20
  console.log(value.toString(), value);
20
21
  if (value.toString() !== "js" && value.toString() !== "ts") {
21
- console.log(chalk.red(`Invalid project language, format must be either ${chalk.bold("js")} or ${chalk.bold("ts")}`));
22
+ dolphMsg.errorRed(`invalid project language, format must be either ${chalk.bold("js")} or ${chalk.bold("ts")}`);
22
23
  return;
23
24
  }
24
25
  config.language = value;
25
26
  writeConfig(config);
26
- console.log(chalk.cyan(`Default project language is now ${chalk.bold(config.language)}`));
27
+ dolphMsg.info(`default project language is now ${chalk.bold(config.language)}`);
27
28
  return;
28
29
  }
29
30
  if (key && key.toLocaleLowerCase().includes("paradigm") && value) {
30
31
  if (value.toString() !== "oop" && value.toString() !== "functional") {
31
- console.log(chalk.red(`Invalid programming paradigm, must be either ${chalk.bold("oop")} or ${chalk.bold("functional")}`));
32
+ dolphMsg.errorRed(`invalid programming paradigm, must be either ${chalk.bold("oop")} or ${chalk.bold("functional")}`);
32
33
  return;
33
34
  }
34
35
  config.paradigm = value;
35
36
  writeConfig(config);
36
- console.log(chalk.cyan(`Default programming paradigm is now ${chalk.bold(config.paradigm)}`));
37
+ dolphMsg.info(`default programming paradigm is now ${chalk.bold(config.paradigm)}`);
37
38
  return;
38
39
  }
39
40
  if (key && key.toLocaleLowerCase().includes("database") && value) {
40
41
  if (!dbOptions.includes(value.toString())) {
41
- console.log(chalk.red(`Invalid database value, must be either of these: ${dbOptions.join(", ")} `));
42
+ dolphMsg.errorRed(`invalid database value, must be either of these: ${dbOptions.join(", ")} `);
42
43
  return;
43
44
  }
44
45
  config.database = value;
45
46
  writeConfig(config);
46
- console.log(chalk.cyan(`Default project database is now ${chalk.bold(config.database)}`));
47
+ dolphMsg.info(`default project database is now ${chalk.bold(config.database)}`);
47
48
  return;
48
49
  }
49
50
  });
50
- // validate generateFolder
51
- // if (options.generateFolder) {
52
- // if (
53
- // options.generateFolder !== "true" &&
54
- // options.generateFolder !== "false"
55
- // ) {
56
- // console.log(
57
- // chalk.red(
58
- // `Invalid folder generation value, value must be ${chalk.bold(
59
- // "true"
60
- // )} or ${chalk.bold("false")}`
61
- // )
62
- // );
63
- // return;
64
- // }
65
- // config.generateFolder = options.generateFolder;
66
- // writeConfig(config);
67
- // console.log(
68
- // chalk.cyan(
69
- // `Generation of folder files for the Services, Models, Controllers and Routes set to ${chalk.bold(
70
- // config.generateFolder
71
- // )}`
72
- // )
73
- // );
74
- // return;
75
- // }
76
51
  if (Object.keys(options).length === 0) {
77
- console.log(chalk.yellow(chalk.bold(`No configurations applied, run ${chalk.white("dolph config --help")} to see available commands`)));
52
+ dolphMsg.errorGray(`no configurations applied, run ${chalk.green("dolph config --help")} to see available commands`);
78
53
  }
79
54
  process.exit(0);
80
55
  });
@@ -27,7 +27,6 @@ export function writePackageJsonFile(name, extension) {
27
27
  "devDependencies": {
28
28
  "@swc/cli": "^0.1.62",
29
29
  "@swc/core": "^1.3.91",
30
- "@types/express": "^4.17.18",
31
30
  "@types/node": "^20.8.2",
32
31
  "ts-node": "^10.9.1",
33
32
  "tsc-alias": "^1.8.8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphjs/cli",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
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",