@appweaver/cli 1.0.13 → 1.0.15
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/package.json +2 -2
- package/start/start-project.js +10 -8
- package/utils/process-util.d.ts +1 -1
- package/utils/process-util.js +15 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appweaver/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "Appweaver - the backend framework for AI-first development (@cli)",
|
|
5
5
|
"author": "Luka Matosevic",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@sinclair/typebox": "0.34.49",
|
|
35
35
|
"@sinclair/typebox-codegen": "0.11.1",
|
|
36
36
|
"commander": "15.0.0",
|
|
37
|
+
"fkill": "10.0.3",
|
|
37
38
|
"glob": "13.0.6",
|
|
38
39
|
"prettier": "3.8.4",
|
|
39
40
|
"rimraf": "6.1.3",
|
|
40
|
-
"tree-kill": "1.2.2",
|
|
41
41
|
"ts-node": "10.9.2",
|
|
42
42
|
"tsc-alias": "1.8.17",
|
|
43
43
|
"tsc-watch": "7.2.0"
|
package/start/start-project.js
CHANGED
|
@@ -69,18 +69,19 @@ async function startBunProject(mainFilePath, watch) {
|
|
|
69
69
|
*/
|
|
70
70
|
async function watchNodeProject(mainFilePath, projectFile) {
|
|
71
71
|
let abortController;
|
|
72
|
+
let runningProcess;
|
|
72
73
|
const watch = new client_1.TscWatchClient();
|
|
73
74
|
// Handler for every successful compilation of watched code, aborts previous
|
|
74
75
|
// process and starts a new one
|
|
75
76
|
watch.on('success', async () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
abortController?.abort();
|
|
78
|
+
// Wait for the previous process to fully terminate before starting a new one
|
|
79
|
+
await runningProcess;
|
|
79
80
|
abortController = new AbortController();
|
|
80
81
|
// Replace import alias paths in compiled code
|
|
81
82
|
await (0, tsc_alias_1.replaceTscAliasPaths)({ configFile: projectFile });
|
|
82
83
|
// Start the main application process
|
|
83
|
-
|
|
84
|
+
runningProcess = (0, utils_1.runProcess)('node', [mainFilePath], {
|
|
84
85
|
signal: abortController.signal
|
|
85
86
|
});
|
|
86
87
|
});
|
|
@@ -113,14 +114,15 @@ async function watchNodeProject(mainFilePath, projectFile) {
|
|
|
113
114
|
*/
|
|
114
115
|
async function watchBunProcess() {
|
|
115
116
|
let abortController;
|
|
117
|
+
let runningProcess;
|
|
116
118
|
let debounceTimer;
|
|
117
119
|
// Starts a new process and aborts the previous one
|
|
118
120
|
async function start() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
abortController?.abort();
|
|
122
|
+
// Wait for the previous process to fully terminate before starting a new one
|
|
123
|
+
await runningProcess;
|
|
122
124
|
abortController = new AbortController();
|
|
123
|
-
|
|
125
|
+
runningProcess = (0, utils_1.runProcess)('bun', [common_1.config.APP_MAIN_FILE_PATH], {
|
|
124
126
|
signal: abortController.signal
|
|
125
127
|
});
|
|
126
128
|
}
|
package/utils/process-util.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @param {Object} [params={ quiet: false }] - Configurations for how the process should run.
|
|
7
7
|
* @param {boolean} [params.quiet=false] - If true, suppresses the process output.
|
|
8
8
|
* @param {AbortSignal} [params.signal] - Optional AbortSignal to terminate the running process.
|
|
9
|
-
* @return {Promise<number>} A promise that resolves with the exit code of the process
|
|
9
|
+
* @return {Promise<number>} A promise that resolves with the exit code of the process.
|
|
10
10
|
*/
|
|
11
11
|
export declare function runProcess(cmd: string, args?: string[], params?: {
|
|
12
12
|
quiet?: boolean;
|
package/utils/process-util.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.assertEnv = assertEnv;
|
|
|
8
8
|
exports.assertEnvs = assertEnvs;
|
|
9
9
|
exports.isBunProcess = isBunProcess;
|
|
10
10
|
const node_child_process_1 = require("node:child_process");
|
|
11
|
-
const
|
|
11
|
+
const fkill_1 = __importDefault(require("fkill"));
|
|
12
12
|
const common_1 = require("@appweaver/common");
|
|
13
13
|
/**
|
|
14
14
|
* Executes a shell command with optional arguments and configuration parameters.
|
|
@@ -18,7 +18,7 @@ const common_1 = require("@appweaver/common");
|
|
|
18
18
|
* @param {Object} [params={ quiet: false }] - Configurations for how the process should run.
|
|
19
19
|
* @param {boolean} [params.quiet=false] - If true, suppresses the process output.
|
|
20
20
|
* @param {AbortSignal} [params.signal] - Optional AbortSignal to terminate the running process.
|
|
21
|
-
* @return {Promise<number>} A promise that resolves with the exit code of the process
|
|
21
|
+
* @return {Promise<number>} A promise that resolves with the exit code of the process.
|
|
22
22
|
*/
|
|
23
23
|
function runProcess(cmd, args = [], params = {}) {
|
|
24
24
|
const { quiet = false, signal } = params;
|
|
@@ -32,19 +32,27 @@ function runProcess(cmd, args = [], params = {}) {
|
|
|
32
32
|
shell: true,
|
|
33
33
|
env: { ...process.env, WEAVER_CLI: undefined }
|
|
34
34
|
});
|
|
35
|
+
let aborted = false;
|
|
35
36
|
if (signal) {
|
|
36
|
-
const abortHandler = () => {
|
|
37
|
+
const abortHandler = async () => {
|
|
37
38
|
if (child.pid) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
aborted = true;
|
|
40
|
+
try {
|
|
41
|
+
await (0, fkill_1.default)(child.pid, { force: true, tree: true });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error('Failed to kill process:', e);
|
|
45
|
+
}
|
|
46
|
+
resolve(0);
|
|
41
47
|
}
|
|
42
48
|
};
|
|
43
49
|
signal.addEventListener('abort', abortHandler, { once: true });
|
|
44
50
|
}
|
|
45
51
|
child.on('error', reject);
|
|
46
52
|
child.on('close', (code) => {
|
|
47
|
-
|
|
53
|
+
if (!aborted) {
|
|
54
|
+
resolve(code ?? 99);
|
|
55
|
+
}
|
|
48
56
|
});
|
|
49
57
|
});
|
|
50
58
|
}
|