-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generator scripts #132
Comments
Concept:Allow any file to be written as a JavaScript/TypeScript file which returns the file's content or a collection of files. Generate a single fileIf the generator script just returns a single file, the output will be written to the file name of the generator script: For some files, we will provide helper methods to make it more convenient to build the JSON. It should also be possible to import and use custom components where applicable. import { defineEntity } from "@bridge/generate"
import { Pathfinder } from "../components/Pathfinder.js"
export default defineEntity(({ description, components, use }) => {
// The exact shape of these helper functions still needs to be discussed.
// Generally supporting this way of writing an entity/item or block is necessary
// to make custom components work flawlessly
description({...})
use(Pathfinder)
components({...})
}) The usage of the helper methods is not required; it's also possible to just return raw JSON. export default {
"minecraft:entity": {...}
} This also works for mcfunction files: export default `
/say Hello World!
/tag @s init
` Generate multiple filesTo get more control over the output of your generator script, export a file collection import { FileCollection, defineEntity } from "@bridge/generate"
const files = new FileCollection()
files.add('dummy/file_1.json', defineEntity(...))
files.add('dummy/file_2.json', defineEntity(...))
export default files Auto-completions & Developer experienceWe can provide auto-completions for the helper functions using #463. Additionally, it's worth considering whether to add a "template" API import { useTemplate } from "@bridge/generate"
// The useTemplate function returns the file contents and omits the template file from the compilation output
// Function signature: useTemplate<T=any>(templatePath: string, omitFromOutput=true): Promise<T>
const template = await useTemplate('./myEntity.json')
return template |
- feat: initial generator scripts (towards bridge-core/editor#132)
- fix: various issues with generator scripts (towards bridge-core/editor#132)
- fix: generator script extension generation (towards bridge-core/editor#132)
- fix: generator script collections (towards bridge-core/editor#132)
Edit: Done
|
- fix: file collection containing file with name of template file not generating file - upd: make useTemplate function accept an options object instead of raw boolean towards bridge-core/editor#132
Also makes JSON file definitions more precise by adding the fileExtensions property. towards #132
Generate sets of items, entities or blocks with JavaScript
The text was updated successfully, but these errors were encountered: