Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
41
scratch-vm/src/cli/index.js
Normal file
41
scratch-vm/src/cli/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const fs = require('fs');
|
||||
const VirtualMachine = require('../index');
|
||||
|
||||
/* eslint-env node */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const file = process.argv[2];
|
||||
if (!file) {
|
||||
throw new Error('Invalid file');
|
||||
}
|
||||
|
||||
const runProject = async buffer => {
|
||||
const vm = new VirtualMachine();
|
||||
vm.runtime.on('SAY', (target, type, text) => {
|
||||
console.log(text);
|
||||
});
|
||||
vm.setCompatibilityMode(true);
|
||||
vm.clear();
|
||||
await vm.loadProject(buffer);
|
||||
vm.start();
|
||||
vm.greenFlag();
|
||||
await new Promise(resolve => {
|
||||
const interval = setInterval(() => {
|
||||
let active = 0;
|
||||
const threads = vm.runtime.threads;
|
||||
for (let i = 0; i < threads.length; i++) {
|
||||
if (!threads[i].updateMonitor) {
|
||||
active += 1;
|
||||
}
|
||||
}
|
||||
if (active === 0) {
|
||||
clearInterval(interval);
|
||||
resolve();
|
||||
}
|
||||
}, 50);
|
||||
});
|
||||
vm.stopAll();
|
||||
vm.quit();
|
||||
};
|
||||
|
||||
runProject(fs.readFileSync(file));
|
||||
Reference in New Issue
Block a user