Skip to content

Commit

Permalink
Merge pull request #4 from rokucommunity/prep-for-release
Browse files Browse the repository at this point in the history
Prep for release
  • Loading branch information
TwitchBronBron authored Aug 19, 2024
2 parents cbe67db + 8e1e6a2 commit 1213f0e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"cSpell.words": [
"brighterscript",
"findnode",
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).



## [0.1.0](https://github.com/rokucommunity/bsc-plugin-auto-findnode/compare/315acc957e1f9e26fa8398d1f6f1926c592355a8...v0.1.0) - 2024-08-19
- Initial release, which includes:
- auto-inject m variables for each element with an ID from xml
- warn about all `m.top.findNode` calls in the `init()` function
57 changes: 54 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# bsc-plugin-auto-findnode

A BrighterScript plugin that auto-injects `m.top.findNode()` calls in your component `init()` functions

[![build status](https://img.shields.io/github/actions/workflow/status/rokucommunity/bsc-plugin-auto-findnode/build.yml?branch=master&logo=github)](https://github.com/rokucommunity/bsc-plugin-auto-findnode/actions?query=branch%3Amaster+workflow%3Abuild)
Expand All @@ -20,14 +21,64 @@ npm install bsc-plugin-auto-findnode

```jsonc
{
"plugins": [
"bsc-plugin-auto-findnode"
]
"plugins": ["bsc-plugin-auto-findnode"]
}
```

3. Run brighterscript like normal, and the plugin will work!

```bash
npx bsc
```

## How it works

1. find every xml file in the project
2. find every element with an ID in that xml file
3. find the `init()` function for each scope (or create one in a new file)
4. inject `m.<elementId> = m.top.findNode("<elementId>")` into the init function

For example:

**Before:**

_pkg:/components/ZombieKeyboard.xml_

```xml
<component name="ZombieKeyboard">
<children>
<label id="helloZombieText" />
</children>
<script uri="ZombieKeyboard.brs" />
</component>
```

_pkg:/components/ZombieKeyboard.brs_

```brightscript
sub init()
print "init for the keyboard!"
end sub
```

**After:**

_pkg:/components/ZombieKeyboard.xml_

```xml
<component name="ZombieKeyboard">
<children>
<label id="helloZombieText" />
</children>
<script uri="ZombieKeyboard.brs" />
</component>
```

_pkg:/components/ZombieKeyboard.brs_

```brightscript
sub init()
m.helloZombieText = m.top.findNode("helloZombieText")
print "init for the keyboard!"
end sub
```
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bsc-plugin-auto-findnode",
"version": "1.0.0",
"description": "",
"version": "0.0.1",
"description": "A BrighterScript plugin that auto-injects `m.top.findNode()` calls in your component `init()` functions",
"main": "dist/index.js",
"scripts": {
"preversion": "npm run build && npm run lint && npm run test",
Expand Down

0 comments on commit 1213f0e

Please sign in to comment.