scripting-cli 1.0.9 → 1.1.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/index.js CHANGED
@@ -1,4 +1,14 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
2
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
14
  };
@@ -23,23 +33,6 @@ const io = new socket_io_1.Server(server);
23
33
  const bonjour = (0, bonjour_1.default)();
24
34
  const getPath = (filename) => path_1.default.join(process.cwd(), filename);
25
35
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
26
- // .command({
27
- // command: 'start',
28
- // describe: 'Start the scripting-cli server',
29
- // builder: (yargs) => {
30
- // return yargs.options({
31
- // port: {
32
- // describe: "The port the server listens on",
33
- // number: true,
34
- // default: 3000,
35
- // }
36
- // })
37
- // .usage("$0 start [--port=<port>]");
38
- // },
39
- // handler: (argv) => {
40
- // startServer(argv.port);
41
- // }
42
- // })
43
36
  .command('start', 'Start the scripting-cli server', (yargs) => {
44
37
  return yargs.options({
45
38
  port: {
@@ -54,7 +47,6 @@ const getPath = (filename) => path_1.default.join(process.cwd(), filename);
54
47
  ["$0 start -p=8000", "Start server and listen on 8000"]
55
48
  ]);
56
49
  }, (argv) => {
57
- console.log("argv", argv.port);
58
50
  startServer(argv.port);
59
51
  })
60
52
  .option('help', {
@@ -129,18 +121,18 @@ function startServer(port) {
129
121
  fs_1.default.mkdirSync(dirname, { recursive: true });
130
122
  }
131
123
  };
132
- const writeDtsFiles = async (files) => {
133
- await Promise.all(Object.entries(files).map(async ([filename, content]) => {
124
+ const writeDtsFiles = (files) => __awaiter(this, void 0, void 0, function* () {
125
+ yield Promise.all(Object.entries(files).map((_a) => __awaiter(this, [_a], void 0, function* ([filename, content]) {
134
126
  const filePath = getPath(`dts/${filename}`);
135
127
  ensureDirectoryExistence(filePath);
136
- await fs_1.default
128
+ yield fs_1.default
137
129
  .promises
138
130
  .writeFile(filePath, content)
139
131
  .catch((err) => {
140
132
  console.log(chalk_1.default.red(`Error writing file: ${err}`));
141
133
  });
142
- }));
143
- };
134
+ })));
135
+ });
144
136
  const tryOpenFileInVSCode = (filePath) => {
145
137
  let cmd = `code "${filePath}"`;
146
138
  if (os_1.default.platform() === "win32") {
@@ -155,7 +147,7 @@ function startServer(port) {
155
147
  }
156
148
  child_process_1.default.execSync(cmd);
157
149
  };
158
- const PORT = port ?? 3000;
150
+ const PORT = port !== null && port !== void 0 ? port : 3000;
159
151
  io.on('connection', (socket) => {
160
152
  console.log(chalk_1.default.blue(`Client [${socket.id}] connected`));
161
153
  let watcher = null;
@@ -205,7 +197,7 @@ function startServer(port) {
205
197
  .on('error', error => console.log(chalk_1.default.bgRed(`Watcher error: ${error}`)))
206
198
  .on('ready', () => console.log(`[${chalk_1.default.bold.blue(scriptName)}] Watching files for changes`));
207
199
  };
208
- socket.on('syncScriptFromClient', async (data, ack) => {
200
+ socket.on('syncScriptFromClient', (data, ack) => __awaiter(this, void 0, void 0, function* () {
209
201
  try {
210
202
  if (data.scriptName === scriptName) {
211
203
  ack({
@@ -215,10 +207,10 @@ function startServer(port) {
215
207
  }
216
208
  if (scriptName != null) {
217
209
  console.log(`Received new script, closing previous watcher`);
218
- watcher?.close();
210
+ watcher === null || watcher === void 0 ? void 0 : watcher.close();
219
211
  watcher = null;
220
212
  }
221
- await writeDtsFiles({
213
+ yield writeDtsFiles({
222
214
  "global.d.ts": data["global.d.ts"],
223
215
  "scripting.d.ts": data["scripting.d.ts"],
224
216
  });
@@ -227,14 +219,14 @@ function startServer(port) {
227
219
  const tsconfig = require(getPath('tsconfig.json'));
228
220
  if (!tsconfig.include.includes(scriptName)) {
229
221
  tsconfig.include.push(scriptName);
230
- await fs_1.default.promises.writeFile(getPath('tsconfig.json'), JSON.stringify(tsconfig, null, 2));
222
+ yield fs_1.default.promises.writeFile(getPath('tsconfig.json'), JSON.stringify(tsconfig, null, 2));
231
223
  }
232
224
  ensureDirectoryExistence(scriptDir);
233
- await Promise.all(Object.entries(data.scriptFiles).map(async ([filename, content]) => {
225
+ yield Promise.all(Object.entries(data.scriptFiles).map((_a) => __awaiter(this, [_a], void 0, function* ([filename, content]) {
234
226
  const filePath = path_1.default.join(scriptDir, filename);
235
227
  ensureDirectoryExistence(filePath);
236
- await fs_1.default.promises.writeFile(filePath, content);
237
- }));
228
+ yield fs_1.default.promises.writeFile(filePath, content);
229
+ })));
238
230
  console.log(chalk_1.default.green('global.d.ts and scripting.d.ts and other script files saved.'));
239
231
  createWatcher(data.scriptName);
240
232
  ack({
@@ -249,8 +241,8 @@ function startServer(port) {
249
241
  error: `Failed to init and sync script files.\n${e}`,
250
242
  });
251
243
  }
252
- });
253
- socket.on("syncScriptFromServer", async (data, ack) => {
244
+ }));
245
+ socket.on("syncScriptFromServer", (data, ack) => __awaiter(this, void 0, void 0, function* () {
254
246
  try {
255
247
  if (scriptName === data.scriptName) {
256
248
  ack({
@@ -260,10 +252,10 @@ function startServer(port) {
260
252
  }
261
253
  if (scriptName != null) {
262
254
  console.log(`Received new script [${chalk_1.default.bold.blue(data.scriptName)}], closing previous watcher`);
263
- watcher?.close();
255
+ watcher === null || watcher === void 0 ? void 0 : watcher.close();
264
256
  watcher = null;
265
257
  }
266
- await writeDtsFiles({
258
+ yield writeDtsFiles({
267
259
  "global.d.ts": data["global.d.ts"],
268
260
  "scripting.d.ts": data["scripting.d.ts"],
269
261
  });
@@ -275,13 +267,13 @@ function startServer(port) {
275
267
  return;
276
268
  }
277
269
  const scriptFiles = {};
278
- const readDir = async (dir) => {
279
- const files = await fs_1.default.promises.readdir(dir, { withFileTypes: true });
280
- await Promise.all(files.map(async (file) => {
270
+ const readDir = (dir) => __awaiter(this, void 0, void 0, function* () {
271
+ const files = yield fs_1.default.promises.readdir(dir, { withFileTypes: true });
272
+ yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
281
273
  if (file.isFile()) {
282
274
  const filePath = path_1.default.join(dir, file.name);
283
275
  const relativePath = path_1.default.relative(scriptDir, filePath);
284
- const content = await fs_1.default.promises.readFile(filePath, 'utf-8').catch((err) => {
276
+ const content = yield fs_1.default.promises.readFile(filePath, 'utf-8').catch((err) => {
285
277
  console.log(chalk_1.default.red(`Error reading file: ${err}`));
286
278
  });
287
279
  if (typeof content === "string") {
@@ -292,11 +284,11 @@ function startServer(port) {
292
284
  }
293
285
  }
294
286
  else if (file.isDirectory()) {
295
- await readDir(path_1.default.join(dir, file.name));
287
+ yield readDir(path_1.default.join(dir, file.name));
296
288
  }
297
- }));
298
- };
299
- await readDir(scriptDir);
289
+ })));
290
+ });
291
+ yield readDir(scriptDir);
300
292
  scriptName = data.scriptName;
301
293
  ack({
302
294
  scriptFiles,
@@ -310,11 +302,11 @@ function startServer(port) {
310
302
  error: `Failed to init and pull script files.\n${e}`,
311
303
  });
312
304
  }
313
- });
305
+ }));
314
306
  socket.on('stopDebugScript', (data, ack) => {
315
307
  if (data === scriptName) {
316
308
  console.log(`[${chalk_1.default.bold.blue(scriptName)}] Stop debug script`);
317
- watcher?.close();
309
+ watcher === null || watcher === void 0 ? void 0 : watcher.close();
318
310
  watcher = null;
319
311
  scriptName = "";
320
312
  ack(true);
@@ -323,7 +315,7 @@ function startServer(port) {
323
315
  ack(false);
324
316
  }
325
317
  });
326
- socket.on("getFileContent", async (data, ack) => {
318
+ socket.on("getFileContent", (data, ack) => __awaiter(this, void 0, void 0, function* () {
327
319
  if (scriptName !== data.scriptName) {
328
320
  ack({
329
321
  error: `Script ${data.scriptName} is not initialized`,
@@ -332,7 +324,7 @@ function startServer(port) {
332
324
  }
333
325
  const filePath = path_1.default.join(getPath(data.scriptName), data.relativePath);
334
326
  try {
335
- const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
327
+ const content = yield fs_1.default.promises.readFile(filePath, 'utf-8');
336
328
  ack({
337
329
  content,
338
330
  });
@@ -342,14 +334,14 @@ function startServer(port) {
342
334
  error: `Failed to get file content.\n${e}`,
343
335
  });
344
336
  }
345
- });
337
+ }));
346
338
  socket.on("log", (data) => {
347
339
  if (data.scriptName !== scriptName) {
348
340
  return;
349
341
  }
350
342
  console.log(`[${chalk_1.default.bold.blue(scriptName)}][${data.isError ? chalk_1.default.red("ERROR") : "LOG"}][${new Date().toLocaleTimeString()}] ${data.content}`);
351
343
  });
352
- socket.on("openFile", async (data) => {
344
+ socket.on("openFile", (data) => __awaiter(this, void 0, void 0, function* () {
353
345
  if (data.scriptName !== scriptName) {
354
346
  return;
355
347
  }
@@ -357,10 +349,10 @@ function startServer(port) {
357
349
  if (fs_1.default.existsSync(filePath)) {
358
350
  tryOpenFileInVSCode(filePath);
359
351
  }
360
- });
352
+ }));
361
353
  socket.on('disconnect', () => {
362
354
  console.log(chalk_1.default.gray(`Client [${socket.id}] disconnected`));
363
- watcher?.close();
355
+ watcher === null || watcher === void 0 ? void 0 : watcher.close();
364
356
  watcher = null;
365
357
  });
366
358
  const serverScriptNames = fs_1.default.readdirSync(process.cwd())
@@ -385,7 +377,6 @@ function startServer(port) {
385
377
  });
386
378
  });
387
379
  }
388
- if (require.main === module) {
389
- console.log("start main");
390
- startServer();
391
- }
380
+ // if (require.main === module) {
381
+ // startServer();
382
+ // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripting-cli",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
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
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  import express from 'express';
2
3
  import http from 'http';
3
4
  import { Server as SocketIOServer } from 'socket.io';
@@ -453,6 +454,6 @@ function startServer(port?: number) {
453
454
  });
454
455
  }
455
456
 
456
- if (require.main === module) {
457
- startServer();
458
- }
457
+ // if (require.main === module) {
458
+ // startServer();
459
+ // }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2020",
3
+ "target": "es2015",
4
4
  "module": "commonjs",
5
5
  "declaration": false,
6
6
  "outDir": "./dist",