@dolphjs/cli 1.3.0 → 1.4.1
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,35 +5,50 @@ 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
|
+
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
|
+
};
|
|
11
32
|
export const startApp = (useBun = false) => {
|
|
12
|
-
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("
|
|
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 (child) {
|
|
25
|
-
child.on("exit", () => {
|
|
26
|
-
child = null;
|
|
27
|
-
});
|
|
28
|
-
// If child process is already running, gracefully close it before restarting
|
|
29
|
-
// child.kill("SIGTERM");
|
|
30
|
-
child.kill("SIGKILL");
|
|
31
|
-
}
|
|
32
49
|
if (useBun) {
|
|
33
|
-
console.log(`${chalk.bold(chalk.green("[DOLPH INFO:] "))} ${chalk.greenBright("
|
|
34
|
-
child = spawn("bun", [indexFilePath], {
|
|
35
|
-
stdio: "inherit",
|
|
36
|
-
});
|
|
50
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO:] "))} ${chalk.greenBright("Using Bun to start the server...")}`);
|
|
51
|
+
child = spawn("bun", [indexFilePath], { stdio: "inherit" });
|
|
37
52
|
}
|
|
38
53
|
else {
|
|
39
54
|
child = spawn(fileExtension === "ts" ? "ts-node" : "node", spawnArgs, {
|
|
@@ -46,7 +61,7 @@ export const startApp = (useBun = false) => {
|
|
|
46
61
|
});
|
|
47
62
|
child.on("close", (code) => {
|
|
48
63
|
if (code === 1) {
|
|
49
|
-
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("
|
|
64
|
+
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("Exiting watch mode...")}`);
|
|
50
65
|
child = null;
|
|
51
66
|
process.exit(1);
|
|
52
67
|
}
|
|
@@ -87,29 +102,14 @@ export const buildApp = () => {
|
|
|
87
102
|
export const startProdApp = async (useBun = false) => {
|
|
88
103
|
try {
|
|
89
104
|
fileExtension = readConfig().language;
|
|
105
|
+
if (child) {
|
|
106
|
+
killProcess(child);
|
|
107
|
+
}
|
|
90
108
|
if (fileExtension === "ts") {
|
|
91
|
-
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("
|
|
109
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("Compiling to JavaScript...")}`);
|
|
92
110
|
indexFilePath = join(getRootDirectory(), "src", `server.ts`);
|
|
93
111
|
const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
|
|
94
|
-
|
|
95
|
-
child.on("exit", () => {
|
|
96
|
-
child = null;
|
|
97
|
-
});
|
|
98
|
-
child.kill("SIGTERM");
|
|
99
|
-
}
|
|
100
|
-
child = spawn("swc", spawnArgs, {
|
|
101
|
-
stdio: "inherit",
|
|
102
|
-
});
|
|
103
|
-
child.on("error", (err) => {
|
|
104
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
|
|
105
|
-
process.exit(1);
|
|
106
|
-
});
|
|
107
|
-
child.on("close", (code) => {
|
|
108
|
-
if (code === 1) {
|
|
109
|
-
console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting compilation ...")}`);
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
112
|
+
child = spawn("swc", spawnArgs, { stdio: "inherit" });
|
|
113
113
|
await new Promise((resolve, reject) => {
|
|
114
114
|
child.on("close", (code) => {
|
|
115
115
|
if (code === 0) {
|
|
@@ -125,38 +125,20 @@ export const startProdApp = async (useBun = false) => {
|
|
|
125
125
|
fileExtension === "ts"
|
|
126
126
|
? join(getRootDirectory(), "app", "src", "server.js")
|
|
127
127
|
: join(getRootDirectory(), "src", "server.js");
|
|
128
|
-
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (code === 1) {
|
|
140
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
const child2 = spawn("node", [indexFilePath], {
|
|
147
|
-
stdio: "inherit",
|
|
148
|
-
});
|
|
149
|
-
child2.on("error", (err) => {
|
|
150
|
-
`${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}`)}`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
});
|
|
136
|
+
child.on("close", (code) => {
|
|
137
|
+
if (code === 1) {
|
|
138
|
+
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("Exiting production mode...")}`);
|
|
151
139
|
process.exit(1);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (code === 1) {
|
|
155
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
160
142
|
}
|
|
161
143
|
catch (e) {
|
|
162
144
|
console.error(e);
|
|
@@ -172,26 +154,27 @@ let isWatcherActive = false;
|
|
|
172
154
|
const debouncedStartApp = _.debounce((useBun) => startApp(useBun), 1000);
|
|
173
155
|
export const watchFile = (useBun = false) => {
|
|
174
156
|
if (!isWatcherActive) {
|
|
175
|
-
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...")}`);
|
|
176
158
|
isWatcherActive = true;
|
|
177
159
|
fileExtension = readConfig().language;
|
|
178
160
|
const srcDirectory = join(getRootDirectory(), "src");
|
|
179
161
|
watcher.add(srcDirectory);
|
|
180
162
|
watcher.on("all", (_event, path) => {
|
|
181
|
-
`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright(
|
|
182
|
-
if (path.endsWith(".ts") ||
|
|
183
|
-
path.endsWith(".js")
|
|
184
|
-
// path.startsWith("dolph_config")
|
|
185
|
-
) {
|
|
163
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright(`File changed: [${path}]`)}`);
|
|
164
|
+
if (path.endsWith(".ts") || path.endsWith(".js")) {
|
|
186
165
|
debouncedStartApp(useBun);
|
|
187
166
|
}
|
|
188
167
|
});
|
|
189
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
|
+
}
|
|
190
173
|
watcher.close();
|
|
191
174
|
process.exit(0);
|
|
192
175
|
});
|
|
193
176
|
}
|
|
194
177
|
else {
|
|
195
|
-
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.")}`);
|
|
196
179
|
}
|
|
197
180
|
};
|
|
@@ -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
|
`;
|
|
@@ -11,6 +11,7 @@ export function writeTsConfigFile(isSpring) {
|
|
|
11
11
|
"allowJs": false,
|
|
12
12
|
"declaration": false,
|
|
13
13
|
"experimentalDecorators": true,
|
|
14
|
+
"emitDecoratorMetadata": true,
|
|
14
15
|
"sourceMap": false,
|
|
15
16
|
"useUnknownInCatchVariables": false,
|
|
16
17
|
"strictFunctionTypes": false,
|
|
@@ -53,6 +54,7 @@ export function writeTsConfigFile(isSpring) {
|
|
|
53
54
|
"allowJs": false,
|
|
54
55
|
"declaration": false,
|
|
55
56
|
"experimentalDecorators": true,
|
|
57
|
+
"emitDecoratorMetadata": true,
|
|
56
58
|
"sourceMap": false,
|
|
57
59
|
"useUnknownInCatchVariables": false,
|
|
58
60
|
"strictFunctionTypes": false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
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",
|