@dolphjs/cli 1.2.4 → 1.4.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/daemon/watcher.js
CHANGED
|
@@ -5,40 +5,63 @@ import { getRootDirectory } from "../utils/get_root_dir_path.js";
|
|
|
5
5
|
import { readConfig } from "../utils/read_user_config_path.js";
|
|
6
6
|
import { join } from "path";
|
|
7
7
|
import _ from "lodash";
|
|
8
|
+
import { exec } from "child_process";
|
|
8
9
|
let fileExtension = "";
|
|
9
10
|
let indexFilePath = "";
|
|
10
|
-
let child;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let child = null;
|
|
12
|
+
const killProcess = (processToKill) => {
|
|
13
|
+
if (processToKill) {
|
|
14
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("Stopping previous Dolph server...")}`);
|
|
15
|
+
// Windows: Use taskkill
|
|
16
|
+
if (process.platform === "win32") {
|
|
17
|
+
exec(`taskkill /PID ${processToKill.pid} /F /T`, (err) => {
|
|
18
|
+
if (err) {
|
|
19
|
+
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`Failed to kill process: ${err}`)}`);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Linux/macOS: Kill process normally
|
|
25
|
+
processToKill.kill("SIGTERM");
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
processToKill.kill("SIGKILL");
|
|
28
|
+
}, 1000);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const startApp = (useBun = false) => {
|
|
33
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("Starting Dolph server...")}`);
|
|
13
34
|
fileExtension = readConfig().language;
|
|
14
35
|
indexFilePath = join(getRootDirectory(), "src", `server.${fileExtension}`);
|
|
15
|
-
|
|
36
|
+
// Kill previous process before starting a new one
|
|
37
|
+
if (child) {
|
|
38
|
+
killProcess(child);
|
|
39
|
+
}
|
|
40
|
+
let spawnArgs = [
|
|
16
41
|
"-r",
|
|
17
42
|
"tsconfig-paths/register",
|
|
18
43
|
"--transpile-only",
|
|
44
|
+
indexFilePath,
|
|
19
45
|
];
|
|
20
|
-
let spawnArgs = [...additionalOptions, indexFilePath];
|
|
21
46
|
if (fileExtension === "js") {
|
|
22
47
|
spawnArgs = [indexFilePath];
|
|
23
48
|
}
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
if (useBun) {
|
|
50
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO:] "))} ${chalk.greenBright("Using Bun to start the server...")}`);
|
|
51
|
+
child = spawn("bun", [indexFilePath], { stdio: "inherit" });
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
child = spawn(fileExtension === "ts" ? "ts-node" : "node", spawnArgs, {
|
|
55
|
+
stdio: "inherit",
|
|
27
56
|
});
|
|
28
|
-
// If child process is already running, gracefully close it before restarting
|
|
29
|
-
// child.kill("SIGTERM");
|
|
30
|
-
child.kill("SIGKILL");
|
|
31
57
|
}
|
|
32
|
-
child = spawn(fileExtension === "ts" ? "ts-node" : "node", spawnArgs, {
|
|
33
|
-
stdio: "inherit",
|
|
34
|
-
});
|
|
35
58
|
child.on("error", (err) => {
|
|
36
59
|
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`);
|
|
37
60
|
process.exit(1);
|
|
38
61
|
});
|
|
39
62
|
child.on("close", (code) => {
|
|
40
63
|
if (code === 1) {
|
|
41
|
-
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("
|
|
64
|
+
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("Exiting watch mode...")}`);
|
|
42
65
|
child = null;
|
|
43
66
|
process.exit(1);
|
|
44
67
|
}
|
|
@@ -76,32 +99,17 @@ export const buildApp = () => {
|
|
|
76
99
|
}
|
|
77
100
|
});
|
|
78
101
|
};
|
|
79
|
-
export const startProdApp = async () => {
|
|
102
|
+
export const startProdApp = async (useBun = false) => {
|
|
80
103
|
try {
|
|
81
104
|
fileExtension = readConfig().language;
|
|
105
|
+
if (child) {
|
|
106
|
+
killProcess(child);
|
|
107
|
+
}
|
|
82
108
|
if (fileExtension === "ts") {
|
|
83
|
-
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("
|
|
109
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("Compiling to JavaScript...")}`);
|
|
84
110
|
indexFilePath = join(getRootDirectory(), "src", `server.ts`);
|
|
85
111
|
const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
|
|
86
|
-
|
|
87
|
-
child.on("exit", () => {
|
|
88
|
-
child = null;
|
|
89
|
-
});
|
|
90
|
-
child.kill("SIGTERM");
|
|
91
|
-
}
|
|
92
|
-
child = spawn("swc", spawnArgs, {
|
|
93
|
-
stdio: "inherit",
|
|
94
|
-
});
|
|
95
|
-
child.on("error", (err) => {
|
|
96
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
|
|
97
|
-
process.exit(1);
|
|
98
|
-
});
|
|
99
|
-
child.on("close", (code) => {
|
|
100
|
-
if (code === 1) {
|
|
101
|
-
console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting compilation ...")}`);
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
112
|
+
child = spawn("swc", spawnArgs, { stdio: "inherit" });
|
|
105
113
|
await new Promise((resolve, reject) => {
|
|
106
114
|
child.on("close", (code) => {
|
|
107
115
|
if (code === 0) {
|
|
@@ -117,17 +125,17 @@ export const startProdApp = async () => {
|
|
|
117
125
|
fileExtension === "ts"
|
|
118
126
|
? join(getRootDirectory(), "app", "src", "server.js")
|
|
119
127
|
: join(getRootDirectory(), "src", "server.js");
|
|
120
|
-
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("
|
|
121
|
-
|
|
122
|
-
stdio: "inherit"
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}
|
|
128
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("Starting Dolph server...")}`);
|
|
129
|
+
child = useBun
|
|
130
|
+
? spawn("bun", [indexFilePath], { stdio: "inherit" })
|
|
131
|
+
: spawn("node", [indexFilePath], { stdio: "inherit" });
|
|
132
|
+
child.on("error", (err) => {
|
|
133
|
+
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`);
|
|
126
134
|
process.exit(1);
|
|
127
135
|
});
|
|
128
|
-
|
|
136
|
+
child.on("close", (code) => {
|
|
129
137
|
if (code === 1) {
|
|
130
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("
|
|
138
|
+
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("Exiting production mode...")}`);
|
|
131
139
|
process.exit(1);
|
|
132
140
|
}
|
|
133
141
|
});
|
|
@@ -143,26 +151,30 @@ const watcher = chokidar.watch([], {
|
|
|
143
151
|
ignoreInitial: false,
|
|
144
152
|
});
|
|
145
153
|
let isWatcherActive = false;
|
|
146
|
-
const debouncedStartApp = _.debounce(startApp, 1000);
|
|
147
|
-
export const watchFile = () => {
|
|
154
|
+
const debouncedStartApp = _.debounce((useBun) => startApp(useBun), 1000);
|
|
155
|
+
export const watchFile = (useBun = false) => {
|
|
148
156
|
if (!isWatcherActive) {
|
|
149
|
-
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("
|
|
157
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("Watching files for changes...")}`);
|
|
150
158
|
isWatcherActive = true;
|
|
151
159
|
fileExtension = readConfig().language;
|
|
152
160
|
const srcDirectory = join(getRootDirectory(), "src");
|
|
153
161
|
watcher.add(srcDirectory);
|
|
154
162
|
watcher.on("all", (_event, path) => {
|
|
155
|
-
`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright(
|
|
163
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright(`File changed: [${path}]`)}`);
|
|
156
164
|
if (path.endsWith(".ts") || path.endsWith(".js")) {
|
|
157
|
-
debouncedStartApp();
|
|
165
|
+
debouncedStartApp(useBun);
|
|
158
166
|
}
|
|
159
167
|
});
|
|
160
168
|
process.on("SIGINT", () => {
|
|
169
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("Shutting down watcher...")}`);
|
|
170
|
+
if (child) {
|
|
171
|
+
killProcess(child);
|
|
172
|
+
}
|
|
161
173
|
watcher.close();
|
|
162
174
|
process.exit(0);
|
|
163
175
|
});
|
|
164
176
|
}
|
|
165
177
|
else {
|
|
166
|
-
console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("
|
|
178
|
+
console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("Watcher is already active.")}`);
|
|
167
179
|
}
|
|
168
180
|
};
|
|
@@ -4,11 +4,17 @@ export const watcherConfig = () => {
|
|
|
4
4
|
program
|
|
5
5
|
.command("start")
|
|
6
6
|
.description("starts the dolph application")
|
|
7
|
-
.
|
|
7
|
+
.option("--bun", "uses bun instead of node to run the command")
|
|
8
|
+
.action((options) => {
|
|
9
|
+
startProdApp(options.bun);
|
|
10
|
+
});
|
|
8
11
|
program
|
|
9
12
|
.command("watch")
|
|
10
13
|
.description("starts the dolph application in watch mode")
|
|
11
|
-
.
|
|
14
|
+
.option("--bun", "uses bun instead of node to run the command")
|
|
15
|
+
.action((options) => {
|
|
16
|
+
watchFile(options.bun);
|
|
17
|
+
});
|
|
12
18
|
program
|
|
13
19
|
.command("build")
|
|
14
20
|
.description("compile a typescript project to javascript")
|
|
@@ -43,6 +43,7 @@ export const initDolphCli = (appname) => {
|
|
|
43
43
|
database: "mongo",
|
|
44
44
|
generateFolder: true,
|
|
45
45
|
routing: "express",
|
|
46
|
+
api: "rest",
|
|
46
47
|
};
|
|
47
48
|
if (!existsSync(userConfigFilePath)) {
|
|
48
49
|
inquirer
|
|
@@ -75,6 +76,13 @@ export const initDolphCli = (appname) => {
|
|
|
75
76
|
choices: ["express", "spring"],
|
|
76
77
|
default: "express",
|
|
77
78
|
},
|
|
79
|
+
{
|
|
80
|
+
type: "list",
|
|
81
|
+
name: "api",
|
|
82
|
+
message: "Will you be using REST or GraphQL to build?",
|
|
83
|
+
choices: ["graphql", "rest"],
|
|
84
|
+
default: "rest",
|
|
85
|
+
},
|
|
78
86
|
])
|
|
79
87
|
.then((replies) => {
|
|
80
88
|
// TODO: add this to the config file:
|
|
@@ -2,6 +2,6 @@ import chalk from "chalk";
|
|
|
2
2
|
import { program } from "commander";
|
|
3
3
|
export const packageDescription = () => {
|
|
4
4
|
program
|
|
5
|
-
.version("1.
|
|
5
|
+
.version("1.4.0")
|
|
6
6
|
.description(chalk.cyan("The dolph-cli is a tool for efficient initialization and management of a dolphjs project"));
|
|
7
7
|
};
|
|
@@ -23,7 +23,9 @@ export const packageGenerator = () => {
|
|
|
23
23
|
.option("-m, --model" + chalk.bold(chalk.blue(" <name>")), "Generates a dolphjs models file.")
|
|
24
24
|
.option("-com, --component" + chalk.bold(chalk.blue(" <name>")), "Generates a dolphjs spring component file.")
|
|
25
25
|
.option("-soc, --socket" + chalk.bold(chalk.blue(" <name> ")), "Generate a dolphjs socket service and component.")
|
|
26
|
-
.option("-
|
|
26
|
+
.option("-res, --resolver" + chalk.bold(chalk.blue(" <name> ")), "Generate a dolphjs resolver.")
|
|
27
|
+
.option("-res, --resolver" + chalk.bold(chalk.blue(" <name> ")), "Generate a dolphjs resolver.")
|
|
28
|
+
.option("-a, --all" + chalk.bold(chalk.blue(" <name> ")), "Generates dolphjs controllers, routes, models and services files for the name parameter.")
|
|
27
29
|
.action(async (name, _options) => {
|
|
28
30
|
const promises = Object.entries(name).map(async ([key, value]) => {
|
|
29
31
|
if (key && key.toLowerCase().includes("controller") && value) {
|
|
@@ -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.3
|
|
25
|
+
"@dolphjs/dolph": "^1.4.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/cli": "^0.1.62",
|
|
@@ -53,7 +53,7 @@ export function writePackageJsonFile(name, extension) {
|
|
|
53
53
|
"start": "dolph start"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@dolphjs/dolph": "^1.3
|
|
56
|
+
"@dolphjs/dolph": "^1.4.3"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "The dolphjs-cli is a tool for efficient initialization and management of a dolphjs project",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"repository": "https://github.com/dolphjs/dolph-cli.git",
|