@dolphjs/cli 1.2.3 → 1.3.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
|
@@ -8,7 +8,7 @@ import _ from "lodash";
|
|
|
8
8
|
let fileExtension = "";
|
|
9
9
|
let indexFilePath = "";
|
|
10
10
|
let child;
|
|
11
|
-
export const startApp = () => {
|
|
11
|
+
export const startApp = (useBun = false) => {
|
|
12
12
|
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("starting dolph server ...")}`);
|
|
13
13
|
fileExtension = readConfig().language;
|
|
14
14
|
indexFilePath = join(getRootDirectory(), "src", `server.${fileExtension}`);
|
|
@@ -29,9 +29,17 @@ export const startApp = () => {
|
|
|
29
29
|
// child.kill("SIGTERM");
|
|
30
30
|
child.kill("SIGKILL");
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (useBun) {
|
|
33
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO:] "))} ${chalk.greenBright("using Bun to start the server ...")}`);
|
|
34
|
+
child = spawn("bun", [indexFilePath], {
|
|
35
|
+
stdio: "inherit",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
child = spawn(fileExtension === "ts" ? "ts-node" : "node", spawnArgs, {
|
|
40
|
+
stdio: "inherit",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
35
43
|
child.on("error", (err) => {
|
|
36
44
|
console.error(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`);
|
|
37
45
|
process.exit(1);
|
|
@@ -45,74 +53,115 @@ export const startApp = () => {
|
|
|
45
53
|
});
|
|
46
54
|
};
|
|
47
55
|
export const buildApp = () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
fileExtension = readConfig().language;
|
|
58
|
+
if (fileExtension === "ts") {
|
|
59
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("compiling to javascript ...")}`);
|
|
60
|
+
indexFilePath = join(getRootDirectory(), "src", "server.ts");
|
|
61
|
+
const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
|
|
62
|
+
const child = spawn("swc", spawnArgs, {
|
|
63
|
+
stdio: "inherit",
|
|
64
|
+
});
|
|
65
|
+
child.on("error", (err) => {
|
|
66
|
+
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
|
|
67
|
+
// process.exit(1);
|
|
68
|
+
reject(err);
|
|
69
|
+
});
|
|
70
|
+
child.on("close", (code) => {
|
|
71
|
+
if (code === 1) {
|
|
72
|
+
console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting compilation ...")}`);
|
|
73
|
+
reject(new Error("Compilation failed ..."));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("compilation successful")}`);
|
|
77
|
+
resolve();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("cannot compile javascript file, exiting compilation ...")}`);
|
|
83
|
+
reject(new Error("Cannot compile JavaScript file"));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
71
86
|
};
|
|
72
|
-
export const startProdApp = () => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
child
|
|
87
|
+
export const startProdApp = async (useBun = false) => {
|
|
88
|
+
try {
|
|
89
|
+
fileExtension = readConfig().language;
|
|
90
|
+
if (fileExtension === "ts") {
|
|
91
|
+
console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("compiling to javascript ...")}`);
|
|
92
|
+
indexFilePath = join(getRootDirectory(), "src", `server.ts`);
|
|
93
|
+
const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
|
|
94
|
+
if (child) {
|
|
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
|
+
});
|
|
113
|
+
await new Promise((resolve, reject) => {
|
|
114
|
+
child.on("close", (code) => {
|
|
115
|
+
if (code === 0) {
|
|
116
|
+
resolve();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
reject(new Error("Compilation failed"));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
81
122
|
});
|
|
82
|
-
child.kill("SIGTERM");
|
|
83
123
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
indexFilePath =
|
|
125
|
+
fileExtension === "ts"
|
|
126
|
+
? join(getRootDirectory(), "app", "src", "server.js")
|
|
127
|
+
: join(getRootDirectory(), "src", "server.js");
|
|
128
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("starting dolph server ...")}`);
|
|
129
|
+
if (useBun) {
|
|
130
|
+
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("using Bun to start the server ...")}`);
|
|
131
|
+
const child2 = spawn("bun", [indexFilePath], {
|
|
132
|
+
stdio: "inherit",
|
|
133
|
+
});
|
|
134
|
+
child2.on("error", (err) => {
|
|
135
|
+
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
|
|
94
136
|
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
137
|
+
});
|
|
138
|
+
child2.on("close", (code) => {
|
|
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}`)}`;
|
|
151
|
+
process.exit(1);
|
|
152
|
+
});
|
|
153
|
+
child2.on("close", (code) => {
|
|
154
|
+
if (code === 1) {
|
|
155
|
+
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
101
160
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
stdio: "inherit",
|
|
105
|
-
});
|
|
106
|
-
child2.on("error", (err) => {
|
|
107
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
|
|
161
|
+
catch (e) {
|
|
162
|
+
console.error(e);
|
|
108
163
|
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
child2.on("close", (code) => {
|
|
111
|
-
if (code === 1) {
|
|
112
|
-
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
|
|
113
|
-
process.exit(1);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
164
|
+
}
|
|
116
165
|
};
|
|
117
166
|
const watcher = chokidar.watch([], {
|
|
118
167
|
ignored: "/node_modules",
|
|
@@ -120,8 +169,8 @@ const watcher = chokidar.watch([], {
|
|
|
120
169
|
ignoreInitial: false,
|
|
121
170
|
});
|
|
122
171
|
let isWatcherActive = false;
|
|
123
|
-
const debouncedStartApp = _.debounce(startApp, 1000);
|
|
124
|
-
export const watchFile = () => {
|
|
172
|
+
const debouncedStartApp = _.debounce((useBun) => startApp(useBun), 1000);
|
|
173
|
+
export const watchFile = (useBun = false) => {
|
|
125
174
|
if (!isWatcherActive) {
|
|
126
175
|
console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("watching files for changes ...")}`);
|
|
127
176
|
isWatcherActive = true;
|
|
@@ -130,8 +179,11 @@ export const watchFile = () => {
|
|
|
130
179
|
watcher.add(srcDirectory);
|
|
131
180
|
watcher.on("all", (_event, path) => {
|
|
132
181
|
`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("file changed" + `[${path}]`)}`;
|
|
133
|
-
if (path.endsWith(".ts") ||
|
|
134
|
-
|
|
182
|
+
if (path.endsWith(".ts") ||
|
|
183
|
+
path.endsWith(".js")
|
|
184
|
+
// path.startsWith("dolph_config")
|
|
185
|
+
) {
|
|
186
|
+
debouncedStartApp(useBun);
|
|
135
187
|
}
|
|
136
188
|
});
|
|
137
189
|
process.on("SIGINT", () => {
|
|
@@ -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")
|
|
@@ -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.3.0")
|
|
6
6
|
.description(chalk.cyan("The dolph-cli is a tool for efficient initialization and management of a dolphjs project"));
|
|
7
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolphjs/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|