@dolphjs/cli 1.0.2 → 1.0.4
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 +64 -0
- package/dist/daemon/watcher.js +36 -0
- package/dist/daemon/watcherConfig.js +12 -0
- package/dist/generators/templates/controller_template.js +4 -8
- package/dist/generators/templates/model_template.js +7 -14
- package/dist/index.js +2 -0
- package/dist/utils/package_description.js +3 -2
- package/dist/utils/write_gitignore.js +1 -0
- package/package.json +1 -1
- package/dist/utils/read_package_json.js +0 -9
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# dolphjs cli
|
|
2
|
+
|
|
3
|
+
The dolphjs-cli is a tool used for efficient initialization and management of a dolphjs project.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
**new**: the alias for this command is `n`. This command is used to initialize / start a new project. It takes the name of the project as an option
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
dolph-cli new <project-name>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or use `' . '` in place of `<project-name>` to initialize the project in current directory.
|
|
14
|
+
|
|
15
|
+
After this, you'll be prompted with few questions which would be used to configure your dolphjs project. Navigate to the project folder and run
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
to install all packages .
|
|
22
|
+
|
|
23
|
+
**generate**: the alias for this command is `g` and is used to generate files and folders with setup code for :
|
|
24
|
+
|
|
25
|
+
- controllers
|
|
26
|
+
- services
|
|
27
|
+
- models
|
|
28
|
+
- routes
|
|
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:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
dolph-cli g -a user
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
the command above creates a service, controller, model and routes file for `user` and set's you up for writing business logic. Alternatively, you might want to create one of the files (controllers, models, services, routes) so you make use of their independent flags:
|
|
37
|
+
|
|
38
|
+
- controller:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
dolph-cli g -c <name>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- service:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
dolph-cli g -s <name>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- model:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
dolph-cli g -m <name>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- route:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
dolph-cli g -r <name>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Credit
|
|
63
|
+
|
|
64
|
+
dolphjs-cli is inspired by methane-cli [https://github.com/adedoyin/methane-cli]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { watch } from "fs";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { getRootDirectory } from "../utils/get_root_dir_path.js";
|
|
5
|
+
import { readConfig } from "../utils/read_user_config_path.js";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
let fileExtension = "";
|
|
8
|
+
let runtimeEngine = "ts-node";
|
|
9
|
+
let indexFilePath = "";
|
|
10
|
+
export const startApp = () => {
|
|
11
|
+
fileExtension = readConfig().language;
|
|
12
|
+
if (fileExtension === "js")
|
|
13
|
+
runtimeEngine = "node";
|
|
14
|
+
indexFilePath = join(getRootDirectory(), `index.${fileExtension}`);
|
|
15
|
+
const child = spawn(runtimeEngine, [indexFilePath], { stdio: "inherit" });
|
|
16
|
+
child.on("close", (code) => {
|
|
17
|
+
if (code === 1) {
|
|
18
|
+
console.log(chalk.bold(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("exiting watch mode ...")}`));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export const watchFile = () => {
|
|
24
|
+
console.log(chalk.bold(`${chalk.green("[DOLPH INFO]: ")} ${chalk.greenBright("watching files for changes ...")}`));
|
|
25
|
+
fileExtension = readConfig().language;
|
|
26
|
+
if (fileExtension === "js")
|
|
27
|
+
runtimeEngine = "node";
|
|
28
|
+
watch(indexFilePath, { recursive: true }, (_event, filenamae) => {
|
|
29
|
+
if (filenamae && filenamae.endsWith(`.${fileExtension}`)) {
|
|
30
|
+
console.log(chalk.bold(`${chalk.green("[DOLPH INFO]: ")} ${chalk.greenBright("file changed" + `[${filenamae}]`)}`));
|
|
31
|
+
startApp();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
// startApp();
|
|
36
|
+
// watchFile();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import { startApp, watchFile } from "./watcher.js";
|
|
3
|
+
export const watcherConfig = () => {
|
|
4
|
+
program
|
|
5
|
+
.command("start")
|
|
6
|
+
.description("starts the dolphjs application")
|
|
7
|
+
.action(() => startApp());
|
|
8
|
+
program
|
|
9
|
+
.command("watch")
|
|
10
|
+
.description("starts the dolphjs application in watch mode")
|
|
11
|
+
.action(() => watchFile());
|
|
12
|
+
};
|
|
@@ -4,8 +4,7 @@ const generateOopTsTemplate = (controllerName) => {
|
|
|
4
4
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
5
5
|
};
|
|
6
6
|
const className = capitalizeFirstLetter(controllerName) + "Controller";
|
|
7
|
-
template = `
|
|
8
|
-
import { DolphControllerHandler } from "@dolphjs/dolph/classes";
|
|
7
|
+
template = `import { DolphControllerHandler } from "@dolphjs/dolph/classes";
|
|
9
8
|
import {
|
|
10
9
|
Dolph,
|
|
11
10
|
SuccessResponse,
|
|
@@ -33,8 +32,7 @@ const generateOopJsTemplate = (controllerName) => {
|
|
|
33
32
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
34
33
|
};
|
|
35
34
|
const className = capitalizeFirstLetter(controllerName) + "Controller";
|
|
36
|
-
template = `
|
|
37
|
-
const { DolphControllerHandler } = require("@dolphjs/dolph/classes");
|
|
35
|
+
template = `const { DolphControllerHandler } = require("@dolphjs/dolph/classes");
|
|
38
36
|
const {
|
|
39
37
|
SuccessResponse,
|
|
40
38
|
TryCatchAsyncFn,
|
|
@@ -56,8 +54,7 @@ module.exports = { ${className} }
|
|
|
56
54
|
};
|
|
57
55
|
const generateFnTsTemplate = (controllerName) => {
|
|
58
56
|
let template;
|
|
59
|
-
template = `
|
|
60
|
-
import { TryCatchAsyncFn, SuccessResponse, DRequest, DResponse } from "@dolphjs/dolph/common";
|
|
57
|
+
template = `import { TryCatchAsyncFn, SuccessResponse, DRequest, DResponse } from "@dolphjs/dolph/common";
|
|
61
58
|
|
|
62
59
|
export const defaultFunc = TryCatchAsyncFn(async (req: DRequest, res: DResponse) => {
|
|
63
60
|
SuccessResponse({ res, body: { message: "${controllerName} working!" } });
|
|
@@ -68,8 +65,7 @@ export const defaultFunc = TryCatchAsyncFn(async (req: DRequest, res: DResponse)
|
|
|
68
65
|
};
|
|
69
66
|
const generateFnJsTemplate = (controllerName) => {
|
|
70
67
|
let template;
|
|
71
|
-
template = `
|
|
72
|
-
const { TryCatchAsyncFn, SuccessResponse } = require("@dolphjs/dolph/common");
|
|
68
|
+
template = `const { TryCatchAsyncFn, SuccessResponse } = require("@dolphjs/dolph/common");
|
|
73
69
|
|
|
74
70
|
const defaultFunc = TryCatchAsyncFn(async (req, res) => {
|
|
75
71
|
SuccessResponse({ res, body: { message: "${controllerName} working!" } });
|
|
@@ -20,8 +20,7 @@ export const ${capitalizeFirstLetter(modelName)}Model = model<I${capitalizeFirst
|
|
|
20
20
|
`;
|
|
21
21
|
}
|
|
22
22
|
if (isMysql) {
|
|
23
|
-
template = `
|
|
24
|
-
import { sequelizeInstance } from "@/configs/db.configs";
|
|
23
|
+
template = `import { sequelizeInstance } from "@/configs/db.configs";
|
|
25
24
|
import { DataTypes } from "sequelize";
|
|
26
25
|
|
|
27
26
|
export const ${capitalizeFirstLetter(modelName)} = sequelizeInstance.define("${modelName}", {
|
|
@@ -45,8 +44,7 @@ const generateOopJsTemplate = (modelName, isMongo, isMysql) => {
|
|
|
45
44
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
46
45
|
};
|
|
47
46
|
if (isMongo) {
|
|
48
|
-
template = `
|
|
49
|
-
const { Schema, model } = require("mongoose");
|
|
47
|
+
template = `const { Schema, model } = require("mongoose");
|
|
50
48
|
|
|
51
49
|
const ${capitalizeFirstLetter(modelName)}Schema = new Schema(
|
|
52
50
|
{
|
|
@@ -60,8 +58,7 @@ module.exports = { ${capitalizeFirstLetter(modelName)}Model }
|
|
|
60
58
|
`;
|
|
61
59
|
}
|
|
62
60
|
if (isMysql) {
|
|
63
|
-
template = `
|
|
64
|
-
const { sequelizeInstance } = require("../../../configs/db.configs");
|
|
61
|
+
template = `const { sequelizeInstance } = require("../../../configs/db.configs");
|
|
65
62
|
const { DataTypes } = require("sequelize");
|
|
66
63
|
|
|
67
64
|
const User = sequelizeInstance.define("user", {
|
|
@@ -87,8 +84,7 @@ const generateFnTsTemplate = (modelName, isMongo, isMysql) => {
|
|
|
87
84
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
88
85
|
};
|
|
89
86
|
if (isMongo) {
|
|
90
|
-
template = `
|
|
91
|
-
import { Schema, Document, model } from "mongoose";
|
|
87
|
+
template = `import { Schema, Document, model } from "mongoose";
|
|
92
88
|
|
|
93
89
|
export interface I${capitalizeFirstLetter(modelName)} extends Document {
|
|
94
90
|
|
|
@@ -104,8 +100,7 @@ export const ${capitalizeFirstLetter(modelName)}Model = model<I${capitalizeFirst
|
|
|
104
100
|
`;
|
|
105
101
|
}
|
|
106
102
|
if (isMysql) {
|
|
107
|
-
template = `
|
|
108
|
-
import { sequelizeInstance } from "@/configs/db.configs";
|
|
103
|
+
template = `import { sequelizeInstance } from "@/configs/db.configs";
|
|
109
104
|
import { DataTypes } from "sequelize";
|
|
110
105
|
|
|
111
106
|
export const ${capitalizeFirstLetter(modelName)} = sequelizeInstance.define("${modelName}", {
|
|
@@ -129,8 +124,7 @@ const generateFnJsTemplate = (modelName, isMongo, isMysql) => {
|
|
|
129
124
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
130
125
|
};
|
|
131
126
|
if (isMongo) {
|
|
132
|
-
template = `
|
|
133
|
-
const { Schema, model } = require("mongoose");
|
|
127
|
+
template = `const { Schema, model } = require("mongoose");
|
|
134
128
|
|
|
135
129
|
const ${capitalizeFirstLetter(modelName)}Schema = new Schema(
|
|
136
130
|
{
|
|
@@ -144,8 +138,7 @@ module.exports = { ${capitalizeFirstLetter(modelName)}Model };
|
|
|
144
138
|
`;
|
|
145
139
|
}
|
|
146
140
|
if (isMysql) {
|
|
147
|
-
template = `
|
|
148
|
-
const { sequelizeInstance } = require("../../../configs/db.configs");
|
|
141
|
+
template = `const { sequelizeInstance } = require("../../../configs/db.configs");
|
|
149
142
|
const { DataTypes } = require("sequelize");
|
|
150
143
|
|
|
151
144
|
const User = sequelizeInstance.define("user", {
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { packageDescription } from "./utils/package_description.js";
|
|
|
6
6
|
import { configurePackage } from "./utils/read_user_config.js";
|
|
7
7
|
import { InitDolphCli } from "./utils/package_init.js";
|
|
8
8
|
import { packageGenerator } from "./utils/package_generator.js";
|
|
9
|
+
import { watcherConfig } from "./daemon/watcherConfig.js";
|
|
9
10
|
figlet.text("dolphjs cli", {
|
|
10
11
|
font: "Big",
|
|
11
12
|
horizontalLayout: "default",
|
|
@@ -22,6 +23,7 @@ figlet.text("dolphjs cli", {
|
|
|
22
23
|
packageDescription();
|
|
23
24
|
configurePackage();
|
|
24
25
|
packageGenerator();
|
|
26
|
+
watcherConfig();
|
|
25
27
|
program.command("*", { hidden: true }).action(() => {
|
|
26
28
|
console.log(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("unknown command. See list of available commands: ")}`);
|
|
27
29
|
program.help();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { program } from "commander";
|
|
3
|
-
import { description, version } from "./read_package_json.js";
|
|
4
3
|
export const packageDescription = () => {
|
|
5
|
-
program
|
|
4
|
+
program
|
|
5
|
+
.version("1.0.3")
|
|
6
|
+
.description(chalk.cyan("The dolphjs-cli is a tool for efficient intialization and management of a dolphjs project"));
|
|
6
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
4
|
-
const packageJsonContent = readFileSync(packageJsonPath, "utf8");
|
|
5
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
6
|
-
const version = packageJson.version;
|
|
7
|
-
const name = packageJson.name;
|
|
8
|
-
const description = packageJson.description;
|
|
9
|
-
export { version, name, description };
|