Skip to content
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

Open
solvedDev opened this issue Oct 10, 2021 · 2 comments
Open

Generator scripts #132

solvedDev opened this issue Oct 10, 2021 · 2 comments
Assignees
Labels
feature Request of a new feature

Comments

@solvedDev
Copy link
Member

solvedDev commented Oct 10, 2021

Generate sets of items, entities or blocks with JavaScript

@solvedDev solvedDev added the idea A new idea that could be worth to explore label Oct 10, 2021
@solvedDev solvedDev added this to the v2.3.0 milestone Jul 13, 2022
@solvedDev
Copy link
Member Author

solvedDev commented Jul 13, 2022

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 file

If the generator script just returns a single file, the output will be written to the file name of the generator script: myGenerator.js-> myGenerator.json

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 files

To 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 experience

We 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

@solvedDev solvedDev added feature Request of a new feature and removed idea A new idea that could be worth to explore labels Jul 13, 2022
@solvedDev solvedDev self-assigned this Jul 23, 2022
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
- feat: initial generator scripts (towards bridge-core/editor#132)
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
- fix: various issues with generator scripts (towards bridge-core/editor#132)
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
- fix: generator script extension generation (towards bridge-core/editor#132)
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
- fix: generator script collections (towards bridge-core/editor#132)
@solvedDev
Copy link
Member Author

solvedDev commented Jul 23, 2022

Edit: Done

Dash cache file should store files generated by script and unlink them when...
- Generator script is unlinked
- Before running script again

solvedDev added a commit that referenced this issue Jul 23, 2022
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
- 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
solvedDev added a commit that referenced this issue Jul 23, 2022
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
solvedDev added a commit to bridge-core/dash-compiler that referenced this issue Jul 23, 2022
solvedDev added a commit that referenced this issue Jul 24, 2022
solvedDev added a commit that referenced this issue Jul 25, 2022
@solvedDev solvedDev modified the milestones: v2.3.0, v2.4.0 Jul 25, 2022
solvedDev added a commit that referenced this issue Jul 25, 2022
Also makes JSON file definitions more precise by adding the fileExtensions property.

towards #132
@solvedDev solvedDev removed this from the v2.4.0 milestone Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request of a new feature
Projects
Status: 📝 Todo
Development

No branches or pull requests

1 participant