@objectstack/cli 0.8.0 ā 0.8.2
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/CHANGELOG.md +19 -0
- package/dist/bin.js +42 -7
- package/package.json +7 -4
- package/src/bin.ts +1 -1
- package/src/commands/serve.ts +47 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @objectstack/cli
|
|
2
2
|
|
|
3
|
+
## 0.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [555e6a7]
|
|
8
|
+
- @objectstack/spec@0.8.2
|
|
9
|
+
- @objectstack/core@0.8.2
|
|
10
|
+
- @objectstack/plugin-hono-server@0.8.2
|
|
11
|
+
|
|
12
|
+
## 0.8.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 254f290: fix: serve command now detects available ports to avoid conflicts
|
|
17
|
+
refactor: update to use Core v0.8.0 API (kernel.use/bootstrap)
|
|
18
|
+
- @objectstack/spec@0.8.1
|
|
19
|
+
- @objectstack/core@0.8.1
|
|
20
|
+
- @objectstack/plugin-hono-server@0.8.1
|
|
21
|
+
|
|
3
22
|
## 1.0.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/dist/bin.js
CHANGED
|
@@ -416,14 +416,49 @@ var createCommand = new Command3("create").description("Create a new package, pl
|
|
|
416
416
|
import { Command as Command4 } from "commander";
|
|
417
417
|
import path3 from "path";
|
|
418
418
|
import fs3 from "fs";
|
|
419
|
+
import net from "net";
|
|
419
420
|
import chalk4 from "chalk";
|
|
420
421
|
import { bundleRequire } from "bundle-require";
|
|
422
|
+
var getAvailablePort = async (startPort) => {
|
|
423
|
+
const isPortAvailable = (port2) => {
|
|
424
|
+
return new Promise((resolve) => {
|
|
425
|
+
const server = net.createServer();
|
|
426
|
+
server.once("error", (err) => {
|
|
427
|
+
resolve(false);
|
|
428
|
+
});
|
|
429
|
+
server.once("listening", () => {
|
|
430
|
+
server.close(() => resolve(true));
|
|
431
|
+
});
|
|
432
|
+
server.listen(port2);
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
let port = startPort;
|
|
436
|
+
while (!await isPortAvailable(port)) {
|
|
437
|
+
port++;
|
|
438
|
+
if (port > startPort + 100) {
|
|
439
|
+
throw new Error(`Could not find an available port starting from ${startPort}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return port;
|
|
443
|
+
};
|
|
421
444
|
var serveCommand = new Command4("serve").description("Start ObjectStack server with plugins from configuration").argument("[config]", "Configuration file path", "objectstack.config.ts").option("-p, --port <port>", "Server port", "3000").option("--no-server", "Skip starting HTTP server plugin").action(async (configPath, options) => {
|
|
445
|
+
let port = parseInt(options.port);
|
|
446
|
+
try {
|
|
447
|
+
const availablePort = await getAvailablePort(port);
|
|
448
|
+
if (availablePort !== port) {
|
|
449
|
+
port = availablePort;
|
|
450
|
+
}
|
|
451
|
+
} catch (e) {
|
|
452
|
+
}
|
|
422
453
|
console.log(chalk4.bold(`
|
|
423
454
|
\u{1F680} ObjectStack Server`));
|
|
424
455
|
console.log(chalk4.dim(`------------------------`));
|
|
425
456
|
console.log(`\u{1F4C2} Config: ${chalk4.blue(configPath)}`);
|
|
426
|
-
|
|
457
|
+
if (parseInt(options.port) !== port) {
|
|
458
|
+
console.log(`\u{1F310} Port: ${chalk4.blue(port)} ${chalk4.yellow(`(requested: ${options.port} in use)`)}`);
|
|
459
|
+
} else {
|
|
460
|
+
console.log(`\u{1F310} Port: ${chalk4.blue(port)}`);
|
|
461
|
+
}
|
|
427
462
|
console.log("");
|
|
428
463
|
const absolutePath = path3.resolve(process.cwd(), configPath);
|
|
429
464
|
if (!fs3.existsSync(absolutePath)) {
|
|
@@ -452,7 +487,7 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
|
|
|
452
487
|
console.log(chalk4.yellow(`\u{1F4E6} Loading ${plugins.length} plugin(s)...`));
|
|
453
488
|
for (const plugin of plugins) {
|
|
454
489
|
try {
|
|
455
|
-
kernel.
|
|
490
|
+
kernel.use(plugin);
|
|
456
491
|
const pluginName = plugin.name || plugin.constructor?.name || "unnamed";
|
|
457
492
|
console.log(chalk4.green(` \u2713 Registered plugin: ${pluginName}`));
|
|
458
493
|
} catch (e) {
|
|
@@ -463,16 +498,16 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
|
|
|
463
498
|
if (options.server !== false) {
|
|
464
499
|
try {
|
|
465
500
|
const { HonoServerPlugin } = await import("@objectstack/plugin-hono-server");
|
|
466
|
-
const serverPlugin = new HonoServerPlugin({ port
|
|
467
|
-
kernel.
|
|
468
|
-
console.log(chalk4.green(` \u2713 Registered HTTP server plugin (port: ${
|
|
501
|
+
const serverPlugin = new HonoServerPlugin({ port });
|
|
502
|
+
kernel.use(serverPlugin);
|
|
503
|
+
console.log(chalk4.green(` \u2713 Registered HTTP server plugin (port: ${port})`));
|
|
469
504
|
} catch (e) {
|
|
470
505
|
console.warn(chalk4.yellow(` \u26A0 HTTP server plugin not available: ${e.message}`));
|
|
471
506
|
}
|
|
472
507
|
}
|
|
473
508
|
console.log(chalk4.yellow(`
|
|
474
509
|
\u{1F680} Starting ObjectStack...`));
|
|
475
|
-
await kernel.
|
|
510
|
+
await kernel.bootstrap();
|
|
476
511
|
console.log(chalk4.green(`
|
|
477
512
|
\u2705 ObjectStack server is running!`));
|
|
478
513
|
console.log(chalk4.dim(` Press Ctrl+C to stop
|
|
@@ -496,7 +531,7 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
|
|
|
496
531
|
|
|
497
532
|
// src/bin.ts
|
|
498
533
|
var program = new Command5();
|
|
499
|
-
program.name("objectstack").description("CLI for ObjectStack Protocol - Development Tools for Microkernel Architecture").version("0.
|
|
534
|
+
program.name("objectstack").description("CLI for ObjectStack Protocol - Development Tools for Microkernel Architecture").version("0.8.0");
|
|
500
535
|
program.addCommand(compileCommand);
|
|
501
536
|
program.addCommand(serveCommand);
|
|
502
537
|
program.addCommand(devCommand);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@objectstack/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Command Line Interface for ObjectStack Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,9 +22,12 @@
|
|
|
22
22
|
"commander": "^11.1.0",
|
|
23
23
|
"tsx": "^4.7.1",
|
|
24
24
|
"zod": "^4.3.6",
|
|
25
|
-
"@objectstack/spec": "0.8.
|
|
26
|
-
"@objectstack/core": "0.8.
|
|
27
|
-
"@objectstack/plugin-hono-server": "0.8.
|
|
25
|
+
"@objectstack/spec": "0.8.2",
|
|
26
|
+
"@objectstack/core": "0.8.2",
|
|
27
|
+
"@objectstack/plugin-hono-server": "0.8.2"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@objectstack/core": "^0.8.2"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@types/node": "^25.1.0",
|
package/src/bin.ts
CHANGED
|
@@ -10,7 +10,7 @@ const program = new Command();
|
|
|
10
10
|
program
|
|
11
11
|
.name('objectstack')
|
|
12
12
|
.description('CLI for ObjectStack Protocol - Development Tools for Microkernel Architecture')
|
|
13
|
-
.version('0.
|
|
13
|
+
.version('0.8.0');
|
|
14
14
|
|
|
15
15
|
// Add all commands
|
|
16
16
|
program.addCommand(compileCommand);
|
package/src/commands/serve.ts
CHANGED
|
@@ -1,21 +1,62 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import net from 'net';
|
|
4
5
|
import chalk from 'chalk';
|
|
5
6
|
import { bundleRequire } from 'bundle-require';
|
|
6
7
|
|
|
8
|
+
// Helper to find available port
|
|
9
|
+
const getAvailablePort = async (startPort: number): Promise<number> => {
|
|
10
|
+
const isPortAvailable = (port: number): Promise<boolean> => {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const server = net.createServer();
|
|
13
|
+
server.once('error', (err: any) => {
|
|
14
|
+
resolve(false);
|
|
15
|
+
});
|
|
16
|
+
server.once('listening', () => {
|
|
17
|
+
server.close(() => resolve(true));
|
|
18
|
+
});
|
|
19
|
+
server.listen(port);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let port = startPort;
|
|
24
|
+
while (!(await isPortAvailable(port))) {
|
|
25
|
+
port++;
|
|
26
|
+
if (port > startPort + 100) {
|
|
27
|
+
throw new Error(`Could not find an available port starting from ${startPort}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return port;
|
|
31
|
+
};
|
|
32
|
+
|
|
7
33
|
export const serveCommand = new Command('serve')
|
|
8
34
|
.description('Start ObjectStack server with plugins from configuration')
|
|
9
35
|
.argument('[config]', 'Configuration file path', 'objectstack.config.ts')
|
|
10
36
|
.option('-p, --port <port>', 'Server port', '3000')
|
|
11
37
|
.option('--no-server', 'Skip starting HTTP server plugin')
|
|
12
38
|
.action(async (configPath, options) => {
|
|
39
|
+
let port = parseInt(options.port);
|
|
40
|
+
try {
|
|
41
|
+
const availablePort = await getAvailablePort(port);
|
|
42
|
+
if (availablePort !== port) {
|
|
43
|
+
port = availablePort;
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// Ignore error and try with original port, or let it fail later
|
|
47
|
+
}
|
|
48
|
+
|
|
13
49
|
console.log(chalk.bold(`\nš ObjectStack Server`));
|
|
14
50
|
console.log(chalk.dim(`------------------------`));
|
|
15
51
|
console.log(`š Config: ${chalk.blue(configPath)}`);
|
|
16
|
-
|
|
52
|
+
if (parseInt(options.port) !== port) {
|
|
53
|
+
console.log(`š Port: ${chalk.blue(port)} ${chalk.yellow(`(requested: ${options.port} in use)`)}`);
|
|
54
|
+
} else {
|
|
55
|
+
console.log(`š Port: ${chalk.blue(port)}`);
|
|
56
|
+
}
|
|
17
57
|
console.log('');
|
|
18
58
|
|
|
59
|
+
|
|
19
60
|
const absolutePath = path.resolve(process.cwd(), configPath);
|
|
20
61
|
|
|
21
62
|
if (!fs.existsSync(absolutePath)) {
|
|
@@ -56,7 +97,7 @@ export const serveCommand = new Command('serve')
|
|
|
56
97
|
|
|
57
98
|
for (const plugin of plugins) {
|
|
58
99
|
try {
|
|
59
|
-
kernel.
|
|
100
|
+
kernel.use(plugin);
|
|
60
101
|
const pluginName = plugin.name || plugin.constructor?.name || 'unnamed';
|
|
61
102
|
console.log(chalk.green(` ā Registered plugin: ${pluginName}`));
|
|
62
103
|
} catch (e: any) {
|
|
@@ -69,9 +110,9 @@ export const serveCommand = new Command('serve')
|
|
|
69
110
|
if (options.server !== false) {
|
|
70
111
|
try {
|
|
71
112
|
const { HonoServerPlugin } = await import('@objectstack/plugin-hono-server');
|
|
72
|
-
const serverPlugin = new HonoServerPlugin({ port
|
|
73
|
-
kernel.
|
|
74
|
-
console.log(chalk.green(` ā Registered HTTP server plugin (port: ${
|
|
113
|
+
const serverPlugin = new HonoServerPlugin({ port });
|
|
114
|
+
kernel.use(serverPlugin);
|
|
115
|
+
console.log(chalk.green(` ā Registered HTTP server plugin (port: ${port})`));
|
|
75
116
|
} catch (e: any) {
|
|
76
117
|
console.warn(chalk.yellow(` ā HTTP server plugin not available: ${e.message}`));
|
|
77
118
|
}
|
|
@@ -79,7 +120,7 @@ export const serveCommand = new Command('serve')
|
|
|
79
120
|
|
|
80
121
|
// Boot the kernel
|
|
81
122
|
console.log(chalk.yellow(`\nš Starting ObjectStack...`));
|
|
82
|
-
await kernel.
|
|
123
|
+
await kernel.bootstrap();
|
|
83
124
|
|
|
84
125
|
console.log(chalk.green(`\nā
ObjectStack server is running!`));
|
|
85
126
|
console.log(chalk.dim(` Press Ctrl+C to stop\n`));
|