Skip to content

Commit af8c1ea

Browse files
committed
cli
1 parent 2422cc4 commit af8c1ea

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

docs/website/convert-cli.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
slug: /convert-cli
3+
title: Convert Sb3 files to executable CLI
4+
hide_table_of_contents: false
5+
---
6+
7+
# Convert Sb3 files to executable CLI
8+
1.https://packager.02engine.org/
9+
10+
2.select your project
11+
12+
3.`Environment->Other environments->Node.js CLI`
13+
14+
Node.js CLI runs your Scratch project directly in Node.js environment using scratch-vm. This is intended for server-side execution, automated testing, or batch processing tasks.
15+
16+
Advantages:
17+
18+
- Small file size (~20-30MB vs ~100MB for Electron)
19+
- Fast startup (no browser overhead)
20+
- Direct event monitoring
21+
Command Line Arguments:
22+
23+
You can pass arguments to your application like this:
24+
25+
`app.exe your-project.sb3 --arg1 value1 --arg2 value2 --flag`
26+
27+
CLI API Available:
28+
29+
In CLI mode, you can use the following JavaScript functions in your Scratch project:
30+
31+
- You can use a `say` block to output text to the console
32+
33+
- cli.log(message) - Output text to console
34+
- cli.error(message) - Output error to console
35+
- cli.warn(message) - Output warning to console
36+
- cli.info(message) - Output info to console
37+
- cli.exit(code) - Exit the application (0 = success, non-zero = error)
38+
- cli.getArgs() - Get all command line arguments as an object
39+
- cli.getArg(key) - Get a specific command line argument by key
40+
Example Usage:
41+
```javascript
42+
// Get command line arguments
43+
const args = cli.getArgs();
44+
cli.log('Arguments:', args);
45+
46+
// Get specific argument
47+
const mode = cli.getArg('mode');
48+
if (mode === 'test') {
49+
cli.log('Running in test mode');
50+
}
51+
52+
// Exit with success code
53+
cli.exit(0);
54+
Packaging Instructions:
55+
```
56+
After downloading the package:
57+
58+
Extract the ZIP file to a folder
59+
60+
Install Node.js (version 18 or higher)
61+
62+
Open a terminal/command prompt in the extracted folder
63+
64+
Run `npm install` to install dependencies
65+
66+
Run `npm run build` to create the executable
67+
68+
The executable will be created in the same folder
69+
70+
Simply run the executable - no external SB3 file needed!
71+
72+
Important: Node.js CLI mode:
73+
74+
No graphical output - project runs in headless mode
75+
76+
Mouse and keyboard interactions will not work
77+
78+
Audio playback may be limited
79+
80+
Some extensions may not be compatible
81+
82+
Perfect for automated testing, server-side execution, or background tasks

sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
'website/opf',
1111
'website/custom-default-project',
1212
'website/custom-addon',
13-
'website/new-ui'
13+
'website/new-ui',
14+
'website/convert-cli'
1415
]
1516
},
1617
'website/unshared-projects',

0 commit comments

Comments
 (0)