scripting-cli 1.1.12 → 1.2.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/README_zh.md CHANGED
@@ -1,29 +1,35 @@
1
- # Scripting app 命令行工具
1
+ # Scripting 应用命令行工具
2
2
 
3
- 欢迎使用 `scripting-cli` 命令行工具,它用于与 Scripting 应用程序进行集成。通过该工具,您可以在开发脚本时,实现代码的实时同步和预览,方便您使用喜欢的桌面编辑器(例如 VSCode)进行开发。
3
+ 欢迎使用 `scripting-cli` 命令行工具,它旨在与 Scripting 应用集成。该工具允许您在使用喜爱的桌面编辑器(如 VSCode)开发脚本时,实现实时同步和预览。
4
4
 
5
- [English Version](./README.md)。
5
+ [English](./README.md) | [日本語](./README_ja.md) | [Deutsch](./README_de.md) | [Français](./README_fr.md) | [Italiano](./README_it.md)
6
6
 
7
- ## 前置条件
7
+ ## 先决条件
8
8
 
9
- 在使用 `scripting-cli` 之前,请确保满足以下条件:
9
+ 在使用 `scripting-cli` 之前,请确保满足以下要求:
10
+
11
+ 1. **Node.js**:确保已安装最新版本的 Node.js。您可以通过运行以下命令检查当前版本:
10
12
 
11
- 1. **Node.js**:请确保您已安装v20+版本的 Node.js。可以通过以下命令检查您的 Node.js 版本:
12
13
  ```bash
13
14
  node -v
14
15
  ```
15
16
 
16
- 2. **Scripting 应用程序**:必须安装 Scripting 应用程序,以便与 `scripting-cli` 运行的本地服务进行连接。
17
+ 2. **Scripting 应用**:必须安装 Scripting 应用,以便连接由 `scripting-cli` 启动的本地服务。
17
18
 
18
19
  ## 安装
19
20
 
20
- 使用 `npx` 命令即可直接使用 `scripting-cli`,无需全局安装。
21
+ 无需全局安装 `scripting-cli`,只需使用 `npx` 运行即可:
22
+
23
+ ```bash
24
+ npx scripting-cli <command>
25
+ ```
21
26
 
22
27
  ## 使用方法
23
28
 
24
29
  ### 1. 创建工作目录
25
30
 
26
- 在您的机器上创建一个存放 Scripting 脚本的目录。例如:
31
+ 首先创建一个目录,用于存放您的 Scripting 应用脚本。例如:
32
+
27
33
  ```bash
28
34
  mkdir my-scripting-project
29
35
  cd my-scripting-project
@@ -31,65 +37,70 @@ cd my-scripting-project
31
37
 
32
38
  ### 2. 启动本地服务
33
39
 
34
- 在工作目录中,运行以下命令启动本地服务:
40
+ 在工作目录中,运行以下命令启动本地开发服务:
35
41
 
36
42
  ```bash
37
43
  npx scripting-cli start
38
44
  ```
39
45
 
40
- 默认情况下,本地服务将启动在端口 `3000`。如果需要指定其他端口,可以使用 `--port` 参数:
46
+ 默认情况下,服务将在端口 `3000` 上启动。如需指定其他端口,请使用 `--port` 选项:
41
47
 
42
48
  ```bash
43
- npx scripting-cli start --port=<port>
49
+ npx scripting-cli start --port=4000
44
50
  ```
45
51
 
46
- 请将 `<port>` 替换为您需要的端口号。例如:
52
+ 要启用 Bonjour 支持,使 Scripting 应用自动检测本地服务,请添加 `--bonjour` 标志:
53
+
47
54
  ```bash
48
- npx scripting-cli start --port=4000
55
+ npx scripting-cli start --bonjour
49
56
  ```
50
57
 
51
58
  ### 3. 连接 Scripting 应用
52
59
 
53
- 本地服务启动后,打开 **Scripting 应用程序** 并选择您刚才启动的本地服务。这将建立 Scripting 应用与本地目录之间的连接。
60
+ 服务运行后,打开 **Scripting 应用** 并连接您刚刚启动的本地服务。这将建立应用与工作目录之间的连接。
54
61
 
55
62
  ### 4. 调试和同步代码
56
63
 
57
- 连接成功后,选择您要调试的脚本项目。Scripting 应用将自动将该项目的代码同步到您的工作目录。
64
+ 连接后,选择要调试的脚本项目。Scripting 应用将自动将该项目的代码同步到您的工作目录。
58
65
 
59
- ### 5. 实时同步代码
66
+ ### 5. 实时代码同步
60
67
 
61
- 当您在桌面编辑器(例如 VSCode)中编写并保存脚本时,更新后的代码将自动同步到 Scripting 应用并立即执行。这样,脚本开发和调试变得更加高效和便捷。
68
+ 在桌面编辑器(如 VSCode)中编写并保存脚本时,更新的代码将自动同步到 Scripting 应用并实时执行,使开发和调试更加顺畅。
62
69
 
63
70
  ## 示例工作流程
64
71
 
65
72
  1. 启动本地服务:
73
+
66
74
  ```bash
67
75
  npx scripting-cli start
68
76
  ```
69
77
 
70
- 2. 打开桌面编辑器并编写脚本。
78
+ 2. 打开编辑器并编写脚本。
71
79
 
72
80
  3. 保存脚本文件。
73
81
 
74
- 4. 代码会自动同步到 Scripting 应用并执行。
82
+ 4. 更新的代码将自动同步到 Scripting 应用并执行。
75
83
 
76
- ## 其他信息
84
+ ## 附加信息
77
85
 
78
- - 服务的默认端口是 `3000`,如果该端口已被占用,您可以使用 `--port` 参数指定其他端口。
79
- - 使用 --no-auto-open 选项可以在启动开发服务器时,避免自动打开 index.tsx 或 widget.tsx 文件。示例:
80
- ```bash
81
- npx scripting-cli start --no-auto-open
82
- ```
83
- - 该工具适用于喜欢使用桌面编辑器(如 VSCode)并希望与 Scripting 应用进行无缝集成的用户,以便进行代码同步和调试。
86
+ * 默认端口为 `3000`。如果该端口已被占用,可使用 `--port` 选项指定其他端口。
87
+ * 使用 `--no-auto-open` 标志可防止工具自动打开 `index.tsx` 或 `widget.tsx` 文件:
88
+
89
+ ```bash
90
+ npx scripting-cli start --no-auto-open
91
+ ```
92
+ * 要使用 Bonjour 服务,请确保系统支持该功能。在 Windows 上,可能需要手动安装 Bonjour。然后,使用 `--bonjour` 选项启用该服务。
93
+ * 该工具适用于喜欢使用 VSCode 等桌面编辑器,并希望与 Scripting 应用实现无缝代码同步和调试的用户。
84
94
 
85
95
  ## 故障排除
86
96
 
87
97
  如果遇到问题,请确保:
88
98
 
89
- - 您安装了 v20+版本的Node.js。
90
- - 您的 Scripting 应用已正确连接到本地服务。
91
- - 您选择的端口没有被其他进程占用。
99
+ * 使用的是 Node.js 版本 20 或更高。
100
+ * Scripting 应用已正确连接到本地服务。
101
+ * 所选端口未被其他进程占用。
102
+ * 始终使用 `npx scripting-cli <command>` 运行工具,并确保软件包是最新的。
92
103
 
93
104
  ---
94
105
 
95
- 感谢使用 `scripting-cli`,希望它能为您的 Scripting 应用开发流程带来便利!祝编程愉快!
106
+ 祝您在 Scripting 应用的开发工作中使用 `scripting-cli` 顺利!编码愉快!
package/dist/const.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scriptingDtsFileName = exports.globalDtsFileName = void 0;
4
+ exports.globalDtsFileName = 'global.d.ts';
5
+ exports.scriptingDtsFileName = 'scripting.d.ts';
@@ -9,6 +9,7 @@ const util_1 = require("./util");
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  const path_1 = __importDefault(require("path"));
12
+ const const_1 = require("./const");
12
13
  class Controller {
13
14
  static instances = new Map();
14
15
  static create(socket, noAutoOpen) {
@@ -41,15 +42,15 @@ class Controller {
41
42
  Controller.instances.delete(socket.id);
42
43
  socket.removeAllListeners();
43
44
  });
44
- fs_1.default.promises.readdir(process.cwd()).then((files) => {
45
- const serverScriptNames = files.filter((filename) => fs_1.default.statSync(filename).isDirectory()
46
- && filename !== '.vscode'
45
+ fs_1.default.promises.readdir((0, util_1.getScriptPath)()).then((files) => {
46
+ const serverScriptNames = files.filter((filename) => fs_1.default.statSync((0, util_1.getScriptPath)(filename)).isDirectory()
47
+ && !filename.startsWith('.')
47
48
  && filename !== 'dts');
48
49
  socket.emit("serverScripts", serverScriptNames);
49
50
  });
50
51
  }
51
52
  createWatcher(scriptName) {
52
- const scriptDir = (0, util_1.getPath)(scriptName);
53
+ const scriptDir = (0, util_1.getScriptPath)(scriptName);
53
54
  this.watcher = chokidar_1.default.watch(scriptDir, {
54
55
  ignored: /(^|[\/\\])\../,
55
56
  persistent: true,
@@ -107,24 +108,18 @@ class Controller {
107
108
  this.watcher = null;
108
109
  }
109
110
  await (0, util_1.writeDtsFiles)({
110
- "global.d.ts": data["global.d.ts"],
111
- "scripting.d.ts": data["scripting.d.ts"],
111
+ [const_1.globalDtsFileName]: data[const_1.globalDtsFileName],
112
+ [const_1.scriptingDtsFileName]: data[const_1.scriptingDtsFileName],
112
113
  });
113
114
  this.scriptName = data.scriptName;
114
- const scriptName = data.scriptName;
115
- const scriptDir = (0, util_1.getPath)(data.scriptName);
116
- const tsconfig = require((0, util_1.getPath)('tsconfig.json'));
117
- if (!tsconfig.include.includes(scriptName)) {
118
- tsconfig.include.push(scriptName);
119
- await fs_1.default.promises.writeFile((0, util_1.getPath)('tsconfig.json'), JSON.stringify(tsconfig, null, 2));
120
- }
115
+ const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
121
116
  (0, util_1.ensureDirectoryExistence)(scriptDir);
122
117
  await Promise.all(Object.entries(data.scriptFiles).map(async ([filename, content]) => {
123
118
  const filePath = path_1.default.join(scriptDir, filename);
124
119
  (0, util_1.ensureDirectoryExistence)(filePath);
125
120
  await fs_1.default.promises.writeFile(filePath, content);
126
121
  }));
127
- console.log(chalk_1.default.green('global.d.ts and scripting.d.ts and other script files saved.'));
122
+ console.log(chalk_1.default.green(`${const_1.globalDtsFileName} and ${const_1.scriptingDtsFileName} and other script files saved.`));
128
123
  this.createWatcher(data.scriptName);
129
124
  ack({
130
125
  success: true,
@@ -160,10 +155,10 @@ class Controller {
160
155
  this.watcher = null;
161
156
  }
162
157
  await (0, util_1.writeDtsFiles)({
163
- "global.d.ts": data["global.d.ts"],
164
- "scripting.d.ts": data["scripting.d.ts"],
158
+ globalDtsFileName: data[const_1.globalDtsFileName],
159
+ scriptingDtsFileName: data[const_1.scriptingDtsFileName],
165
160
  });
166
- const scriptDir = (0, util_1.getPath)(data.scriptName);
161
+ const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
167
162
  if (!fs_1.default.existsSync(scriptDir)) {
168
163
  ack({
169
164
  error: `Script directory ${scriptDir} does not exist`,
@@ -174,6 +169,10 @@ class Controller {
174
169
  const readDir = async (dir) => {
175
170
  const files = await fs_1.default.promises.readdir(dir, { withFileTypes: true });
176
171
  await Promise.all(files.map(async (file) => {
172
+ // ignore .git and .vscode directories
173
+ if (file.name.startsWith('.git') || file.name.startsWith('.vscode')) {
174
+ return;
175
+ }
177
176
  if (file.isFile()) {
178
177
  const filePath = path_1.default.join(dir, file.name);
179
178
  const relativePath = (0, util_1.getRelativePath)(scriptDir, filePath);
@@ -224,7 +223,7 @@ class Controller {
224
223
  if (data.scriptName !== this.scriptName) {
225
224
  return;
226
225
  }
227
- const filePath = path_1.default.join((0, util_1.getPath)(this.scriptName), data.relativePath);
226
+ const filePath = path_1.default.join((0, util_1.getScriptPath)(this.scriptName), data.relativePath);
228
227
  if (!this.noAutoOpen && fs_1.default.existsSync(filePath)) {
229
228
  (0, util_1.tryOpenFileInVSCode)(filePath);
230
229
  }
@@ -248,7 +247,7 @@ class Controller {
248
247
  });
249
248
  return;
250
249
  }
251
- const filePath = path_1.default.join((0, util_1.getPath)(data.scriptName), data.relativePath);
250
+ const filePath = path_1.default.join((0, util_1.getScriptPath)(data.scriptName), data.relativePath);
252
251
  try {
253
252
  const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
254
253
  ack({
package/dist/index.js CHANGED
@@ -1,5 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
38
  };
@@ -35,12 +68,37 @@ const start_server_1 = require("./start_server");
35
68
  .example([
36
69
  ["$0 start --no-auto-open", "Start server without opening the index.tsx/widget.tsx file"],
37
70
  ["$0 start --no-auto-open -p=8000", "Start server without opening the index.tsx/widget.tsx file and listen on 8000"],
71
+ ])
72
+ .options({
73
+ "bonjour": {
74
+ type: "boolean",
75
+ describe: "Enable bonjour service",
76
+ },
77
+ })
78
+ .usage("$0 start [--bonjour]")
79
+ .example([
80
+ ["$0 start --bonjour", "Start server with bonjour service"],
81
+ ["$0 start --bonjour -p=8000", "Start server with bonjour service and listen on 8000"],
82
+ ["$0 start --bonjour --no-auto-open", "Start server with bonjour service without opening the index.tsx/widget.tsx file"],
83
+ ["$0 start --bonjour --no-auto-open -p=8000", "Start server with bonjour service without opening the index.tsx/widget.tsx file and listen on 8000"],
38
84
  ]);
39
85
  }, (argv) => {
40
86
  (0, start_server_1.startServer)({
41
87
  port: argv.port,
42
88
  noAutoOpen: argv['no-auto-open'],
89
+ startBonjourService: argv.bonjour,
43
90
  });
91
+ })
92
+ .command('migrate', 'Migrate the scripts in the workspace root directory to the scripts directory.', (yargs) => {
93
+ return yargs
94
+ .usage("$0 migrate")
95
+ .example([
96
+ ["$0 migrate", "Migrate the scripts in the workspace root directory to the scripts directory."]
97
+ ]);
98
+ }, async () => {
99
+ const { migrateOldFiles } = await Promise.resolve().then(() => __importStar(require('./util')));
100
+ await migrateOldFiles();
101
+ process.exit(0);
44
102
  })
45
103
  .showHelpOnFail(true)
46
104
  .option('help', {
@@ -18,7 +18,7 @@ const app = (0, express_1.default)();
18
18
  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
- function startServer({ port, noAutoOpen }) {
21
+ function startServer({ port, noAutoOpen, startBonjourService }) {
22
22
  // console.log("port", port, "noAutoOpen", noAutoOpen);
23
23
  const PORT = port ?? 3000;
24
24
  (0, http_router_1.initHttpRouter)(app);
@@ -26,41 +26,51 @@ function startServer({ port, noAutoOpen }) {
26
26
  controller_1.Controller.create(socket, noAutoOpen);
27
27
  console.log(chalk_1.default.blue(`Client [${socket.id}] connected`));
28
28
  });
29
- server.listen(PORT, () => {
29
+ server.listen(PORT, async () => {
30
30
  (0, util_1.createTsConfig)(); // Create tsconfig.json when the server starts
31
31
  (0, util_1.createVSCodeSettings)(); // Create vscode settings.json when the server starts
32
+ (0, util_1.ensureScriptsDirectory)(); // Ensure the scripts directory exists
33
+ // await migrateOldFiles(); // Migrate old files to the scripts directory
32
34
  const ipAddress = ip_1.default.address();
33
35
  const address = `http://${ipAddress}:${PORT}`;
34
- console.log(`Server listening on ${chalk_1.default.bold.blue(address)}\nYou can select this server in the Scripting app to connect.\n`);
35
- console.log(`Alternatively, you can ${chalk_1.default.green.bold("use the Scripting app to scan")} the QR code and connect: `);
36
+ if (startBonjourService) {
37
+ console.log(`Server listening on ${chalk_1.default.bold.blue(address)}\n\n${chalk_1.default.yellow('You can select this server in the Scripting app to connect')}.\n`);
38
+ console.log(`Alternatively, you can ${chalk_1.default.green.bold("use the Scripting app to scan")} the QR code and connect: `);
39
+ }
40
+ else {
41
+ console.log(chalk_1.default.yellow.italic(`The bonjour service is not started, you can use \`--bonjour\` option to start it.`));
42
+ console.log(`Server listening on ${chalk_1.default.bold.blue(address)}\nYou can ${chalk_1.default.green.bold("use the Scripting app to scan")} the QR code and connect: `);
43
+ }
36
44
  qrcode_terminal_1.default.generate(address, { small: true });
37
- const service = bonjour.publish({
38
- name: 'Scripting-service',
39
- type: 'http',
40
- port: PORT,
41
- host: 'scripting-service.local',
42
- });
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…');
55
- service.stop(() => {
56
- bonjour.unpublishAll(() => {
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);
45
+ if (startBonjourService) {
46
+ function gracefulShutdown() {
47
+ console.log('Shutting down Bonjour...');
48
+ service.stop(() => {
49
+ bonjour.unpublishAll(() => {
50
+ // wait for 500ms,let goodbye message be sent completely
51
+ setTimeout(() => {
52
+ bonjour.destroy();
53
+ console.log('Bonjour services have been shut down properly.');
54
+ process.exit(0);
55
+ }, 500);
56
+ });
63
57
  });
58
+ }
59
+ const service = bonjour.publish({
60
+ name: 'Scripting-service',
61
+ type: 'http',
62
+ port: PORT,
63
+ host: 'scripting-service.local',
64
+ });
65
+ // Register bonjour service error handler
66
+ service.on('error', err => {
67
+ console.error('Bonjour service error:', err);
68
+ });
69
+ ['SIGINT', 'SIGTERM'].forEach(sig => process.once(sig, gracefulShutdown));
70
+ // Handle uncaught exceptions
71
+ process.on('uncaughtException', err => {
72
+ console.error('Uncaught exception:', err);
73
+ gracefulShutdown();
64
74
  });
65
75
  }
66
76
  });
package/dist/util.js CHANGED
@@ -5,18 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.md5 = md5;
7
7
  exports.getPath = getPath;
8
+ exports.getScriptPath = getScriptPath;
8
9
  exports.tryOpenFileInVSCode = tryOpenFileInVSCode;
9
10
  exports.createTsConfig = createTsConfig;
10
11
  exports.createVSCodeSettings = createVSCodeSettings;
12
+ exports.ensureScriptsDirectory = ensureScriptsDirectory;
11
13
  exports.ensureDirectoryExistence = ensureDirectoryExistence;
12
14
  exports.writeDtsFiles = writeDtsFiles;
13
15
  exports.getRelativePath = getRelativePath;
16
+ exports.migrateOldFiles = migrateOldFiles;
14
17
  const path_1 = __importDefault(require("path"));
15
18
  const crypto_1 = __importDefault(require("crypto"));
16
19
  const os_1 = __importDefault(require("os"));
17
20
  const child_process_1 = __importDefault(require("child_process"));
18
21
  const fs_1 = __importDefault(require("fs"));
19
22
  const chalk_1 = __importDefault(require("chalk"));
23
+ const const_1 = require("./const");
20
24
  function md5(content) {
21
25
  return crypto_1.default
22
26
  .createHash('md5')
@@ -26,6 +30,12 @@ function md5(content) {
26
30
  function getPath(filename) {
27
31
  return path_1.default.join(process.cwd(), filename);
28
32
  }
33
+ function getScriptPath(filename) {
34
+ if (filename != null) {
35
+ return path_1.default.join(process.cwd(), 'scripts', filename);
36
+ }
37
+ return path_1.default.join(process.cwd(), 'scripts');
38
+ }
29
39
  function tryOpenFileInVSCode(filePath) {
30
40
  let cmd = `code "${filePath}"`;
31
41
  if (os_1.default.platform() === "win32") {
@@ -62,12 +72,13 @@ function createTsConfig() {
62
72
  "jsxFragmentFactory": "Fragment",
63
73
  "paths": {
64
74
  "scripting": [
65
- "./dts/scripting.d.ts"
75
+ "./dts/${const_1.scriptingDtsFileName}"
66
76
  ]
67
77
  }
68
78
  },
69
79
  "include": [
70
- "./dts/global.d.ts"
80
+ "./dts/${const_1.globalDtsFileName}",
81
+ "scripts"
71
82
  ]
72
83
  }`;
73
84
  const filePath = getPath('tsconfig.json');
@@ -77,7 +88,18 @@ function createTsConfig() {
77
88
  console.log(chalk_1.default.green('tsconfig.json created.'));
78
89
  }
79
90
  else {
80
- console.log(chalk_1.default.gray('tsconfig.json already exists.'));
91
+ const tsconfig = JSON.parse(fs_1.default.readFileSync(filePath, 'utf-8'));
92
+ if (tsconfig.include && !tsconfig.include.includes('scripts')) {
93
+ tsconfig.include = [
94
+ `./dts/${const_1.globalDtsFileName}`,
95
+ "scripts"
96
+ ];
97
+ fs_1.default.writeFileSync(filePath, JSON.stringify(tsconfig, null, 2));
98
+ console.log(chalk_1.default.yellow('tsconfig.json updated to include scripts directory.'));
99
+ }
100
+ else {
101
+ console.log(chalk_1.default.gray('tsconfig.json already exists.'));
102
+ }
81
103
  }
82
104
  }
83
105
  function createVSCodeSettings() {
@@ -95,6 +117,16 @@ function createVSCodeSettings() {
95
117
  console.log(chalk_1.default.gray('.vscode/settings.json already exists.'));
96
118
  }
97
119
  }
120
+ function ensureScriptsDirectory() {
121
+ const scriptsDir = getScriptPath();
122
+ if (!fs_1.default.existsSync(scriptsDir)) {
123
+ fs_1.default.mkdirSync(scriptsDir, { recursive: true });
124
+ console.log(chalk_1.default.green('Scripts directory created.'));
125
+ }
126
+ else {
127
+ console.log(chalk_1.default.gray('Scripts directory already exists.'));
128
+ }
129
+ }
98
130
  function ensureDirectoryExistence(filePath) {
99
131
  const dirname = path_1.default.dirname(filePath);
100
132
  if (!fs_1.default.existsSync(dirname)) {
@@ -117,3 +149,36 @@ function getRelativePath(from, to) {
117
149
  const relativePath = path_1.default.relative(from, to);
118
150
  return relativePath.replaceAll("\\", "/");
119
151
  }
152
+ async function migrateOldFiles() {
153
+ try {
154
+ const list = await fs_1.default.promises.readdir(process.cwd());
155
+ let hasMigrated = false;
156
+ for (const file of list) {
157
+ if (file === 'dts' || file == "scripts" || file === 'tsconfig.json' || file === 'package.json' || file === 'node_modules' || file.startsWith('.')) {
158
+ continue;
159
+ }
160
+ const filePath = path_1.default.join(process.cwd(), file);
161
+ const stat = await fs_1.default.promises.stat(filePath);
162
+ if (!stat.isDirectory()) {
163
+ continue;
164
+ }
165
+ const newFilePath = path_1.default.join(process.cwd(), 'scripts', file);
166
+ if (fs_1.default.existsSync(newFilePath)) {
167
+ console.log(chalk_1.default.yellow(`File ${newFilePath} already exists, skipping...`));
168
+ continue;
169
+ }
170
+ hasMigrated = true;
171
+ console.log(chalk_1.default.blue(`Moving ${filePath} to ${newFilePath}`));
172
+ await fs_1.default.promises.rename(filePath, newFilePath);
173
+ }
174
+ if (hasMigrated) {
175
+ console.log(chalk_1.default.green('Old files migrated to the scripts directory.'));
176
+ }
177
+ else {
178
+ console.log(chalk_1.default.gray('No old files to migrate.'));
179
+ }
180
+ }
181
+ catch (err) {
182
+ console.log(`Failed to migrate old files: ${chalk_1.default.red(`${err}`)}`);
183
+ }
184
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "scripting-cli",
3
- "version": "1.1.12",
3
+ "version": "1.2.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": {
7
7
  "scripting-cli": "dist/index.js"
8
8
  },
9
9
  "scripts": {
10
- "build": "tsc",
10
+ "build": "npx tsc",
11
11
  "start": "node dist/index.js",
12
12
  "dev": "ts-node src/index.ts",
13
13
  "help": "node dist/index.js --help",
package/src/const.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const globalDtsFileName = 'global.d.ts';
2
+ export const scriptingDtsFileName = 'scripting.d.ts';