Scratchext is a framework for making Scratch 2.0 extensions in node.js.
Clone the scratchext repository into your project directory.
$ cd your/project/directory
$ git clone https://github.com/queryselector/scratchext
Create a manifest file called extension.json
. This file contains information about the extension and its blocks.
{
"extensionName": "HelloWorld",
"extensionPort": 12345,
"blockSpecs": [
[" ", "say hello", "greet"]
]
}
Then create extension.js
, which contains the extension behavior.
require('./scratchext/scratchext').create({
blocks: {
greet: function () {
console.log('Hello, world!');
}
}
});
Run the extension with Node…
$ sudo node extension.js
…and import the extension into Scratch by shift-clicking the File menu, selecting Import Experimental Extension, and choosing extension.json
in the file dialog.
Your block will appear in the More Blocks category. Click it to say hello!
$ sudo node extension.js
Connected to Scratch as "HelloWorld", port 12345
Hello, world!
That's it! Check out the wiki for more tutorials and documentation.