scripting-cli 1.1.9 → 1.1.10
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.md +4 -0
- package/README_zh.md +4 -0
- package/dist/controller.js +24 -18
- package/dist/index.js +18 -2
- package/dist/start_server.js +3 -2
- package/package.json +1 -1
- package/src/controller.ts +25 -19
- package/src/index.ts +25 -9
- package/src/start_server.ts +7 -2
package/README.md
CHANGED
|
@@ -76,6 +76,10 @@ As you write and save scripts in your desktop editor (e.g., VSCode), the updated
|
|
|
76
76
|
## Additional Information
|
|
77
77
|
|
|
78
78
|
- The default port for the service is `3000`. If that port is already in use, specify a different one using the `--port` option.
|
|
79
|
+
- Use the `--no-auto-open` option to start the development server without automatically opening the `index.tsx` or `widget.tsx` file in your default code editor. Example:
|
|
80
|
+
```bash
|
|
81
|
+
npx scripting-cli start --no-auto-open
|
|
82
|
+
```
|
|
79
83
|
- The tool is intended for users who prefer using desktop editors like VSCode and want seamless integration with the Scripting app for code synchronization and debugging.
|
|
80
84
|
|
|
81
85
|
## Troubleshooting
|
package/README_zh.md
CHANGED
|
@@ -76,6 +76,10 @@ npx scripting-cli start --port=4000
|
|
|
76
76
|
## 其他信息
|
|
77
77
|
|
|
78
78
|
- 服务的默认端口是 `3000`,如果该端口已被占用,您可以使用 `--port` 参数指定其他端口。
|
|
79
|
+
- 使用 --no-auto-open 选项可以在启动开发服务器时,避免自动打开 index.tsx 或 widget.tsx 文件。示例:
|
|
80
|
+
```bash
|
|
81
|
+
npx scripting-cli start --no-auto-open
|
|
82
|
+
```
|
|
79
83
|
- 该工具适用于喜欢使用桌面编辑器(如 VSCode)并希望与 Scripting 应用进行无缝集成的用户,以便进行代码同步和调试。
|
|
80
84
|
|
|
81
85
|
## 故障排除
|
package/dist/controller.js
CHANGED
|
@@ -11,8 +11,8 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
class Controller {
|
|
13
13
|
static instances = new Map();
|
|
14
|
-
static create(socket) {
|
|
15
|
-
const ctrl = new Controller(socket);
|
|
14
|
+
static create(socket, noAutoOpen) {
|
|
15
|
+
const ctrl = new Controller(socket, noAutoOpen);
|
|
16
16
|
Controller.instances.set(socket.id, ctrl);
|
|
17
17
|
return ctrl;
|
|
18
18
|
}
|
|
@@ -22,7 +22,9 @@ class Controller {
|
|
|
22
22
|
watcher = null;
|
|
23
23
|
scriptName = null;
|
|
24
24
|
socket = null;
|
|
25
|
-
|
|
25
|
+
noAutoOpen;
|
|
26
|
+
constructor(socket, noAutoOpen) {
|
|
27
|
+
this.noAutoOpen = noAutoOpen;
|
|
26
28
|
this.socket = socket;
|
|
27
29
|
socket.emit("socketId", socket.id);
|
|
28
30
|
socket.on('syncScriptFromClient', this.handleSyncScriptFromClient);
|
|
@@ -127,13 +129,15 @@ class Controller {
|
|
|
127
129
|
ack({
|
|
128
130
|
success: true,
|
|
129
131
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
if (!this.noAutoOpen) {
|
|
133
|
+
// Open the entry file in VSCode after a delay
|
|
134
|
+
// to ensure the response is sent. Because the open file command
|
|
135
|
+
// may suspend the response and cause the client to not receive the ack.
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
const entryFilePath = path_1.default.join(scriptDir, "index.tsx");
|
|
138
|
+
(0, util_1.tryOpenFileInVSCode)(entryFilePath);
|
|
139
|
+
}, 1000);
|
|
140
|
+
}
|
|
137
141
|
}
|
|
138
142
|
catch (e) {
|
|
139
143
|
console.log(chalk_1.default.red(`Error: ${e}`));
|
|
@@ -194,13 +198,15 @@ class Controller {
|
|
|
194
198
|
scriptFiles,
|
|
195
199
|
});
|
|
196
200
|
this.createWatcher(data.scriptName);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
if (!this.noAutoOpen) {
|
|
202
|
+
// Open the entry file in VSCode after a delay
|
|
203
|
+
// to ensure the response is sent. Because the open file command
|
|
204
|
+
// may suspend the response and cause the client to not receive the ack.
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
const entryFilePath = path_1.default.join(scriptDir, "index.tsx");
|
|
207
|
+
(0, util_1.tryOpenFileInVSCode)(entryFilePath);
|
|
208
|
+
}, 1000);
|
|
209
|
+
}
|
|
204
210
|
}
|
|
205
211
|
catch (e) {
|
|
206
212
|
ack({
|
|
@@ -219,7 +225,7 @@ class Controller {
|
|
|
219
225
|
return;
|
|
220
226
|
}
|
|
221
227
|
const filePath = path_1.default.join((0, util_1.getPath)(this.scriptName), data.relativePath);
|
|
222
|
-
if (fs_1.default.existsSync(filePath)) {
|
|
228
|
+
if (!this.noAutoOpen && fs_1.default.existsSync(filePath)) {
|
|
223
229
|
(0, util_1.tryOpenFileInVSCode)(filePath);
|
|
224
230
|
}
|
|
225
231
|
};
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,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
11
|
.command('start', 'Start the scripting-cli server', (yargs) => {
|
|
12
|
-
return yargs
|
|
12
|
+
return yargs
|
|
13
|
+
.options({
|
|
13
14
|
port: {
|
|
14
15
|
alias: ["p"],
|
|
15
16
|
describe: "The port the server listens on",
|
|
@@ -20,9 +21,24 @@ const start_server_1 = require("./start_server");
|
|
|
20
21
|
.usage("$0 start [--port=<port>]")
|
|
21
22
|
.example([
|
|
22
23
|
["$0 start -p=8000", "Start server and listen on 8000"]
|
|
24
|
+
])
|
|
25
|
+
.options({
|
|
26
|
+
"no-auto-open": {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
default: true,
|
|
29
|
+
describe: "Do not open the index.tsx/widget.tsx file automatically",
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
.usage("$0 start [--no-auto-open]")
|
|
33
|
+
.example([
|
|
34
|
+
["$0 start --no-auto-open", "Start server without opening the index.tsx/widget.tsx file"],
|
|
35
|
+
["$0 start --no-auto-open -p=8000", "Start server without opening the index.tsx/widget.tsx file and listen on 8000"],
|
|
23
36
|
]);
|
|
24
37
|
}, (argv) => {
|
|
25
|
-
(0, start_server_1.startServer)(
|
|
38
|
+
(0, start_server_1.startServer)({
|
|
39
|
+
port: argv.port,
|
|
40
|
+
noAutoOpen: argv['no-auto-open'],
|
|
41
|
+
});
|
|
26
42
|
})
|
|
27
43
|
.option('help', {
|
|
28
44
|
alias: 'h',
|
package/dist/start_server.js
CHANGED
|
@@ -18,11 +18,12 @@ 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) {
|
|
21
|
+
function startServer({ port, noAutoOpen }) {
|
|
22
|
+
console.log("port", port, "noAutoOpen", noAutoOpen);
|
|
22
23
|
const PORT = port ?? 3000;
|
|
23
24
|
(0, http_router_1.initHttpRouter)(app);
|
|
24
25
|
io.on('connection', (socket) => {
|
|
25
|
-
controller_1.Controller.create(socket);
|
|
26
|
+
controller_1.Controller.create(socket, noAutoOpen);
|
|
26
27
|
console.log(chalk_1.default.blue(`Client [${socket.id}] connected`));
|
|
27
28
|
});
|
|
28
29
|
server.listen(PORT, () => {
|
package/package.json
CHANGED
package/src/controller.ts
CHANGED
|
@@ -10,8 +10,8 @@ export class Controller {
|
|
|
10
10
|
|
|
11
11
|
private static instances: Map<string, Controller> = new Map();
|
|
12
12
|
|
|
13
|
-
static create(socket: Socket) {
|
|
14
|
-
const ctrl = new Controller(socket);
|
|
13
|
+
static create(socket: Socket, noAutoOpen: boolean | undefined) {
|
|
14
|
+
const ctrl = new Controller(socket, noAutoOpen);
|
|
15
15
|
Controller.instances.set(socket.id, ctrl);
|
|
16
16
|
return ctrl;
|
|
17
17
|
}
|
|
@@ -23,8 +23,10 @@ export class Controller {
|
|
|
23
23
|
watcher: FSWatcher | null = null;
|
|
24
24
|
scriptName: string | null = null;
|
|
25
25
|
socket: Socket | null = null;
|
|
26
|
+
noAutoOpen: boolean | undefined;
|
|
26
27
|
|
|
27
|
-
constructor(socket: Socket) {
|
|
28
|
+
constructor(socket: Socket, noAutoOpen: boolean | undefined) {
|
|
29
|
+
this.noAutoOpen = noAutoOpen;
|
|
28
30
|
this.socket = socket;
|
|
29
31
|
|
|
30
32
|
socket.emit("socketId", socket.id);
|
|
@@ -169,13 +171,16 @@ export class Controller {
|
|
|
169
171
|
success: true,
|
|
170
172
|
});
|
|
171
173
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
if (!this.noAutoOpen) {
|
|
175
|
+
|
|
176
|
+
// Open the entry file in VSCode after a delay
|
|
177
|
+
// to ensure the response is sent. Because the open file command
|
|
178
|
+
// may suspend the response and cause the client to not receive the ack.
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
const entryFilePath = path.join(scriptDir, "index.tsx")
|
|
181
|
+
tryOpenFileInVSCode(entryFilePath);
|
|
182
|
+
}, 1000);
|
|
183
|
+
}
|
|
179
184
|
|
|
180
185
|
} catch (e) {
|
|
181
186
|
console.log(chalk.red(`Error: ${e}`));
|
|
@@ -262,14 +267,15 @@ export class Controller {
|
|
|
262
267
|
|
|
263
268
|
this.createWatcher(data.scriptName);
|
|
264
269
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
270
|
+
if (!this.noAutoOpen) {
|
|
271
|
+
// Open the entry file in VSCode after a delay
|
|
272
|
+
// to ensure the response is sent. Because the open file command
|
|
273
|
+
// may suspend the response and cause the client to not receive the ack.
|
|
274
|
+
setTimeout(() => {
|
|
275
|
+
const entryFilePath = path.join(scriptDir, "index.tsx")
|
|
276
|
+
tryOpenFileInVSCode(entryFilePath);
|
|
277
|
+
}, 1000);
|
|
278
|
+
}
|
|
273
279
|
} catch (e) {
|
|
274
280
|
ack({
|
|
275
281
|
error: `Failed to init and pull script files.\n${e}`,
|
|
@@ -299,7 +305,7 @@ export class Controller {
|
|
|
299
305
|
|
|
300
306
|
const filePath = path.join(getPath(this.scriptName), data.relativePath)
|
|
301
307
|
|
|
302
|
-
if (fs.existsSync(filePath)) {
|
|
308
|
+
if (!this.noAutoOpen && fs.existsSync(filePath)) {
|
|
303
309
|
tryOpenFileInVSCode(filePath)
|
|
304
310
|
}
|
|
305
311
|
|
package/src/index.ts
CHANGED
|
@@ -6,20 +6,36 @@ import { startServer } from './start_server';
|
|
|
6
6
|
|
|
7
7
|
yargs(hideBin(process.argv))
|
|
8
8
|
.command('start', 'Start the scripting-cli server', (yargs) => {
|
|
9
|
-
return yargs
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
return yargs
|
|
10
|
+
.options({
|
|
11
|
+
port: {
|
|
12
|
+
alias: ["p"],
|
|
13
|
+
describe: "The port the server listens on",
|
|
14
|
+
type: "number",
|
|
15
|
+
default: 3000,
|
|
16
|
+
}
|
|
17
|
+
})
|
|
17
18
|
.usage("$0 start [--port=<port>]")
|
|
18
19
|
.example([
|
|
19
20
|
["$0 start -p=8000", "Start server and listen on 8000"]
|
|
21
|
+
])
|
|
22
|
+
.options({
|
|
23
|
+
"no-auto-open": {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
default: true,
|
|
26
|
+
describe: "Do not open the index.tsx/widget.tsx file automatically",
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
.usage("$0 start [--no-auto-open]")
|
|
30
|
+
.example([
|
|
31
|
+
["$0 start --no-auto-open", "Start server without opening the index.tsx/widget.tsx file"],
|
|
32
|
+
["$0 start --no-auto-open -p=8000", "Start server without opening the index.tsx/widget.tsx file and listen on 8000"],
|
|
20
33
|
]);
|
|
21
34
|
}, (argv) => {
|
|
22
|
-
startServer(
|
|
35
|
+
startServer({
|
|
36
|
+
port: argv.port,
|
|
37
|
+
noAutoOpen: argv['no-auto-open'],
|
|
38
|
+
});
|
|
23
39
|
})
|
|
24
40
|
.option('help', {
|
|
25
41
|
alias: 'h',
|
package/src/start_server.ts
CHANGED
|
@@ -15,14 +15,19 @@ const server = http.createServer(app);
|
|
|
15
15
|
const io = new SocketIOServer(server);
|
|
16
16
|
const bonjour = Bonjour();
|
|
17
17
|
|
|
18
|
-
export function startServer(port
|
|
18
|
+
export function startServer({ port, noAutoOpen }: {
|
|
19
|
+
port: number | undefined
|
|
20
|
+
noAutoOpen: boolean | undefined
|
|
21
|
+
}) {
|
|
22
|
+
|
|
23
|
+
console.log("port", port, "noAutoOpen", noAutoOpen);
|
|
19
24
|
|
|
20
25
|
const PORT = port ?? 3000;
|
|
21
26
|
|
|
22
27
|
initHttpRouter(app);
|
|
23
28
|
|
|
24
29
|
io.on('connection', (socket) => {
|
|
25
|
-
Controller.create(socket);
|
|
30
|
+
Controller.create(socket, noAutoOpen);
|
|
26
31
|
console.log(chalk.blue(`Client [${socket.id}] connected`));
|
|
27
32
|
});
|
|
28
33
|
|