scripting-cli 1.1.10 → 1.1.12

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/index.js CHANGED
@@ -8,6 +8,9 @@ const yargs_1 = __importDefault(require("yargs/yargs"));
8
8
  const helpers_1 = require("yargs/helpers");
9
9
  const start_server_1 = require("./start_server");
10
10
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
11
+ .parserConfiguration({
12
+ "boolean-negation": false
13
+ })
11
14
  .command('start', 'Start the scripting-cli server', (yargs) => {
12
15
  return yargs
13
16
  .options({
@@ -25,7 +28,6 @@ const start_server_1 = require("./start_server");
25
28
  .options({
26
29
  "no-auto-open": {
27
30
  type: "boolean",
28
- default: true,
29
31
  describe: "Do not open the index.tsx/widget.tsx file automatically",
30
32
  },
31
33
  })
@@ -40,10 +42,12 @@ const start_server_1 = require("./start_server");
40
42
  noAutoOpen: argv['no-auto-open'],
41
43
  });
42
44
  })
45
+ .showHelpOnFail(true)
43
46
  .option('help', {
44
47
  alias: 'h',
45
48
  describe: 'Show help',
46
49
  })
50
+ .demandCommand()
47
51
  .parse();
48
52
  // if (require.main === module) {
49
53
  // startServer();
@@ -19,7 +19,7 @@ const server = http_1.default.createServer(app);
19
19
  const io = new socket_io_1.Server(server);
20
20
  const bonjour = (0, bonjour_1.default)();
21
21
  function startServer({ port, noAutoOpen }) {
22
- console.log("port", port, "noAutoOpen", noAutoOpen);
22
+ // console.log("port", port, "noAutoOpen", noAutoOpen);
23
23
  const PORT = port ?? 3000;
24
24
  (0, http_router_1.initHttpRouter)(app);
25
25
  io.on('connection', (socket) => {
@@ -37,16 +37,31 @@ function startServer({ port, noAutoOpen }) {
37
37
  const service = bonjour.publish({
38
38
  name: 'Scripting-service',
39
39
  type: 'http',
40
- port: PORT
40
+ port: PORT,
41
+ host: 'scripting-service.local',
41
42
  });
42
- process.on('SIGINT', () => {
43
+ // Register bonjour service error handler
44
+ service.on('error', err => {
45
+ console.error('Bonjour service error:', err);
46
+ });
47
+ ['SIGINT', 'SIGTERM'].forEach(sig => process.once(sig, gracefulShutdown));
48
+ // Handle uncaught exceptions
49
+ process.on('uncaughtException', err => {
50
+ console.error('Uncaught exception:', err);
51
+ gracefulShutdown();
52
+ });
53
+ function gracefulShutdown() {
54
+ console.log('Shutting down Bonjour…');
43
55
  service.stop(() => {
44
56
  bonjour.unpublishAll(() => {
45
- bonjour.destroy();
46
- console.log('Bonjour services have been shut down properly.');
47
- process.exit(0);
57
+ // wait for 500ms,let goodbye message be sent completely
58
+ setTimeout(() => {
59
+ bonjour.destroy();
60
+ console.log('Bonjour services have been shut down properly.');
61
+ process.exit(0);
62
+ }, 500);
48
63
  });
49
64
  });
50
- });
65
+ }
51
66
  });
52
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripting-cli",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "This plugin integrates the desktop editor synchronization feature of the Scripting app.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -5,6 +5,9 @@ import { hideBin } from 'yargs/helpers';
5
5
  import { startServer } from './start_server';
6
6
 
7
7
  yargs(hideBin(process.argv))
8
+ .parserConfiguration({
9
+ "boolean-negation": false
10
+ })
8
11
  .command('start', 'Start the scripting-cli server', (yargs) => {
9
12
  return yargs
10
13
  .options({
@@ -22,7 +25,6 @@ yargs(hideBin(process.argv))
22
25
  .options({
23
26
  "no-auto-open": {
24
27
  type: "boolean",
25
- default: true,
26
28
  describe: "Do not open the index.tsx/widget.tsx file automatically",
27
29
  },
28
30
  })
@@ -34,13 +36,15 @@ yargs(hideBin(process.argv))
34
36
  }, (argv) => {
35
37
  startServer({
36
38
  port: argv.port,
37
- noAutoOpen: argv['no-auto-open'],
39
+ noAutoOpen: argv['no-auto-open'] as any,
38
40
  });
39
41
  })
42
+ .showHelpOnFail(true)
40
43
  .option('help', {
41
44
  alias: 'h',
42
45
  describe: 'Show help',
43
46
  })
47
+ .demandCommand()
44
48
  .parse();
45
49
 
46
50
 
@@ -20,7 +20,7 @@ export function startServer({ port, noAutoOpen }: {
20
20
  noAutoOpen: boolean | undefined
21
21
  }) {
22
22
 
23
- console.log("port", port, "noAutoOpen", noAutoOpen);
23
+ // console.log("port", port, "noAutoOpen", noAutoOpen);
24
24
 
25
25
  const PORT = port ?? 3000;
26
26
 
@@ -46,18 +46,38 @@ export function startServer({ port, noAutoOpen }: {
46
46
  const service = bonjour.publish({
47
47
  name: 'Scripting-service',
48
48
  type: 'http',
49
- port: PORT
49
+ port: PORT,
50
+ host: 'scripting-service.local',
50
51
  });
51
52
 
52
- process.on('SIGINT', () => {
53
+ // Register bonjour service error handler
54
+ service.on('error', err => {
55
+ console.error('Bonjour service error:', err);
56
+ });
57
+
58
+ ['SIGINT', 'SIGTERM'].forEach(sig =>
59
+ process.once(sig, gracefulShutdown)
60
+ );
61
+
62
+ // Handle uncaught exceptions
63
+ process.on('uncaughtException', err => {
64
+ console.error('Uncaught exception:', err);
65
+ gracefulShutdown();
66
+ });
67
+
68
+ function gracefulShutdown() {
69
+ console.log('Shutting down Bonjour…');
53
70
  service.stop(() => {
54
71
  bonjour.unpublishAll(() => {
55
- bonjour.destroy();
56
- console.log('Bonjour services have been shut down properly.');
57
- process.exit(0);
72
+ // wait for 500ms,let goodbye message be sent completely
73
+ setTimeout(() => {
74
+ bonjour.destroy();
75
+ console.log('Bonjour services have been shut down properly.');
76
+ process.exit(0);
77
+ }, 500);
58
78
  });
59
79
  });
60
- });
80
+ }
61
81
 
62
82
  });
63
83
  }