0.65.27 • Published 1 month ago

brighterscript v0.65.27

Weekly downloads
590
License
MIT
Repository
github
Last release
1 month ago

BrighterScript v1 branch

A superset of Roku's BrightScript language. Compiles to standard BrightScript.

build Coverage Status NPM Version

This is the v1 branch. Unless you're specifically looking for v1, you probably want to view the master branch.

Overview

The BrighterScript language provides new features and syntax enhancements to Roku's BrightScript language. Because the language is a superset of BrightScript, the parser and associated tools (VSCode integration, cli, etc...) work with standard BrightScript (.brs) files. This means you will get benefits (as described in the following section) from using the BrighterScript compiler, whether your project contains BrighterScript (.bs) files or not. The BrighterScript language transpiles to standard BrightScript, so your code is fully compatible with all roku devices.

Features

BrighterScript adds several new features to the BrightScript language such as Namespaces, classes, import statements, and more. Take a look at the language specification docs for more information.

BrighterScript Language Specification

Why use the BrighterScript compiler/CLI?

  • Check the entire project for syntax and program errors without needing to run on an actual Roku device.
  • Catch syntax and program errors at compile time which would not otherwise appear until runtime.
  • The compiler can be used as part of your tool-chains, such as continuous integration or a custom build pipeline.
  • Get real-time syntax validation by using the cli in --watch mode.

Why use the BrighterScript language?

  • Brighterscript is in good hands:
    • The project is open source.
    • Brighterscript is designed by Roku developers, for Roku developers.
    • The project is owned by RokuCommunity and the syntax and features are thoroughly thought out, discussed, and planned.
    • Actively developed.
  • Reduce boilerplate code and time debugging with language features like these:
    • Import statements
      • Declare import statements in scripts instead of xml script tags.
      • Automatically add script tags to XML components for all script import statements and their cascading dependencies
      • Missing imports are flagged at compile time.
    • Classes
      • Support for class inheritance and method overrides
      • Class fields and can be marked as public, protected, and private and incorrect access will be enforced by compile-time checks.
      • Class methods are automatically scoped to the class
    • Namespaces:
      • Automatically add a name prefix to all methods inside a namespace block.
      • Prevents method naming collisions and improves code readability and maintainability.
      • Missing method invocations, and other namespace related syntax errors are reported at compile time.
    • Ternary operator
      • username = m.user <> invalid ? m.user.name : "not logged in"
    • Template strings
      • print `Hello ${firstNameVar}`.
    • null-coalescing operator
      • user = m.user ?? getDefaultUser()
    • Additional Language features coming soon
      • null-conditional operator: userSettings = m.user?.account?.profile?.settings
    • and more...
  • Full BrighterScript support for syntax checking, validation, and intellisense is available within the Brightscript Language VSCode extension.

  • And if it's not enough, the plugin API allows extending the compiler to provide extra diagnostics or transformations.

Who uses Brighterscript?

Brighterscript is used by applicaster, The miracle channel, and in open source projects such as rooibos, and the maestro framework. The language has been in use for almost a year, and there are at least 2,000+ BrighterScript transpiled files on published channels.

The BrighterScript project is used to power the popular Brightscript Language VSCode extension, and other tools.

More projects are adopting BrighterScript all the time, from using the new BrighterScript language features to simply using the compiler as part of their build pipeline. Be sure to watch this space!

What's with the name?

The name BrighterScript is a compliment to everything that is great about Roku's awesome BrightScript language. Naming things is hard, and discoverability and recognizability are both very important. Here are the reasons we chose this name:

  • the er in BrighterScript represents the additional features we have added on top of BrightScript
  • It looks so similar to BrightScript, which is fitting because this language is 95% BrightScript, 5% extra stuff (the er bits).
  • The config file and extension look very similar between BrightScript and BrighterScript. Take bsconfig.json for example. While brsconfig.json might be more fitting for a pure BrightScript project, bsconfig.json is so very close that you probably wouldn't think twice about it. Same with the fact that .bs (BrighterScript) and .brs are very similar.

We want to honor BrightScript, the language that BrighterScript is based off of, and could think of no better way than to use most of its name in our name.

Installation

npm

npm install brighterscript -g

Usage

Basic Usage

If your project structure exactly matches Roku's, and you run the command from the root of your project, then you can do the following:

bsc

That's it! It will find all files in your BrightScript project, check for syntax and static analysis errors, and if there were no errors, it will produce a zip at ./out/project.zip

Advanced Usage

If you need to configure bsc, you can do so in two ways:

  1. Using command line arguments. This tool can be fully configured using command line arguments. To see a full list, run bsc --help in your terminal.
  2. Using a bsconfig.json file. See the available options below. By default, bsc looks for a bsconfig.json file at the same directory that bsc is executed. If you want to store your bsconfig.json file somewhere else, then you should provide the --project argument and specify the path to your bsconfig.json file.

Examples

  1. Your project resides in a subdirectory of your workspace folder.

    bsc --root-dir ./rokuSourceFiles
  2. Run the compiler in watch mode

    bsc --watch
  3. Run the compiler in watch mode, and redeploy to the roku on every change

    bsc --watch --deploy --host 192.168.1.10 --password secret_password
  4. Use a bsconfig.json file not located at cwd

    bsc --project ./some_folder/bsconfig.json
  5. Run the compiler as a linter only (watch mode supported)

    bsc --create-package false --copy-to-staging false

bsconfig.json

Overview

The presence of a bsconfig.json file in a directory indicates that the directory is the root of a BrightScript project. The bsconfig.json file specifies the root files and the compiler options required to compile the project.

Configuration inheritance with extends

A bsconfig.json file can inherit configurations from another file using the extends property.

The extends is a top-level property in bsconfig.json. extends’ value is a string containing a path to another configuration file to inherit from.

The configuration from the base file are loaded first, then overridden by those in the inheriting config file. If a circularity is encountered, we report an error.

The files property from the inheriting config file overwrite those from the base config file.

All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.

Optional extends and project

There are situations where you want to store some compiler settings in a config file, but not fail if that config file doesn't exist. To do this, you can denote that your extends or project path is optional by prefixing it with a question mark (?). For example:

  • bsconfig.json extends
    {
      "extends": "?path/to/optional/bsconfig.json"
    }
  • CLI "extends"

    bsc --extends "?path/to/optional/bsconfig.json"
  • CLI project argument

    bsc --project "?path/to/optional/bsconfig.json"
  • Node.js API extends
    var programBuilder = new ProgramBuilder({
        "extends": "?path/to/optional/bsconfig.json"
    });
  • Node.js API project
    var programBuilder = new ProgramBuilder({
        "project": "?path/to/optional/bsconfig.json"
    });

bsconfig.json options

These are the options available in the bsconfig.json file.

  • project: string - A path to a project file. This is really only passed in from the command line or the NodeJS API, and should not be present in bsconfig.json files. Prefix with a question mark (?) to prevent throwing an exception when the file does not exist.

  • extends: string - Relative or absolute path to another bsconfig.json file that this bsconfig.json file should import and then override. Prefix with a question mark (?) to prevent throwing an exception when the file does not exist.

  • cwd: string - Override the current working directory

  • rootDir: string - The root directory of your roku project. Defaults to current directory

  • files: (string | string[] | { src: string | string[]; dest?: string })[] - The list file globs used to find all files for the project. If using the {src;dest;} format, you can specify a different destination directory for the matched files in src.

  • outFile: string - The path (including filename) where the output file should be placed (defaults to "./out/[WORKSPACE_FOLDER_NAME].zip").

  • createPackage: boolean - Creates a zip package. Defaults to true. This setting is ignored when deploy is enabled.

  • watch: boolean - If true, the server will keep running and will watch and recompile on every file change.

  • deploy: boolean - If true, after a successful build, the project will be deployed to the Roku specified in host.

  • host: string - The host of the Roku that this project will deploy to.

  • username: string - the username to use when deploying to a Roku device.

  • password: string - The password to use when deploying to a roku device.

  • emitFullPaths: boolean - Emit full paths to files when printing diagnostics to the console. Defaults to false

  • diagnosticFilters: Array<string | number | {src: string; codes: number[]} - A list of filters used to hide diagnostics.

    • A string value should be a relative-to-root-dir or absolute file path or glob pattern of the files that should be excluded. Any file matching this pattern will have all diagnostics supressed.
    • A number value should be a diagnostic code. This will supress all diagnostics with that code for the whole project.
    • An object can also be provided to filter specific diagnostic codes for a file pattern. For example,
      "diagnosticFilters": [{
          "src": "vendor/**/*",
          "codes": [1000, 1011] //ignore these specific codes from vendor libraries
      }]
  • diagnosticLevel: 'hint' | 'info' | 'warn' | 'error' - Specify what diagnostic levels are printed to the console. This has no effect on what diagnostics are reported in the LanguageServer. Defaults to 'warn'

  • autoImportComponentScript: bool - BrighterScript only: will automatically import a script at transpile-time for a component with the same name if it exists.

  • sourceRoot: string - Override the root directory path where debugger should locate the source files. The location will be embedded in the source map to help debuggers locate the original source files. This only applies to files found within rootDir. This is useful when you want to preprocess files before passing them to BrighterScript, and want a debugger to open the original files. This option also affects the SOURCE_FILE_PATH and SOURCE_LOCATION source literals.

  • plugins: Array<string> - List of node scripts or npm modules to load as plugins to the BrighterScript compiler.

Ignore errors and warnings on a per-line basis

In addition to disabling an entire class of errors in bsconfig.json by using ignoreErrorCodes, you may also disable errors for a subset of the complier rules within a file with the following comment flags:

  • bs:disable-next-line
  • bs:disable-next-line: code1 code2 code3
  • bs:disable-line
  • bs:disable-line: code1 code2 code3

Here are some examples:

sub Main()
    'disable errors about invalid syntax here
    'bs:disable-next-line
    DoSomething(

    DoSomething( 'bs:disable-line

    'disable errors about wrong parameter count
    DoSomething(1,2,3) 'bs:disable-next-line

    DoSomething(1,2,3) 'bs:disable-next-line:1002
end sub

sub DoSomething()
end sub

The primary motivation for this feature was to provide a stopgap measure to hide incorrectly-thrown errors on legitimate BrightScript code due to parser bugs. This is still a new project and it is likely to be missing support for certain BrightScript syntaxes. It is recommended that you only use these comments when absolutely necessary.

ropm support

In order for BrighterScript-transpiled projects to work as ropm modules, they need a reference to bslib (the BrightScript runtime library for BrighterScript features) in their package. As ropm and brighterscript become more popular, this could result in many duplicate copies of bslib.brs.

To encourage reducing code duplication, BrighterScript has built-in support for loading bslib from ropm. Here's how it works: 1. if your program does not use ropm, or does use ropm but does not directly reference bslib, then the BrighterScript compiler will copy bslib to "pkg:/source/bslib.brs" at transpile-time. 2. if your program uses ropm and has installed bslib as a dependency, then the BrighterScript compiler will not emit a copy of bslib at pkg:/source/bslib.brs, and will instead use the path to the version from ropm pkg:/source/roku_modules/bslib/bslib.brs.

Installing bslib in your ropm-enabled project

bslib is published to npm under the name @rokucommunity/bslib. If you use NodeJS version 12 or above, we recommend installing @rokucommunity/bslib with the bslib alias, as it produces smaller transpiled code (i.e. emits bslib_ prefix instead of rokucommunity_bslib_). Here's the command to install bslib under the bslib alias using the ropm CLI.

ropm install bslib@npm:@rokucommunity/bslib

bslib support on NodeJS versions less than 12

npm aliases only work in NodeJS version 12 and above. If you're using a NodeJS version less than 12, you will need to install @rokucommunity/bslib directly without the alias. BrighterScript recognizes this pattern as well, it's just not preferred (for the reasons mentioned previously). Here's the command for that:

ropm install @rokucommunity/bslib

Language Server Protocol

This project also contributes a class that aligns with Microsoft's Language Server Protocol, which makes it easy to integrate BrightScript and BrighterScript with any IDE that supports the protocol. We won't go into more detail here, but you can use the LanguageServer class from this project to integrate into your IDE. The vscode-BrightScript-language extension uses this LanguageServer class to bring BrightScript and BrighterScript language support to Visual Studio Code.

Changelog

Click here to view the changelog.

Special Thanks

Special thanks to the brs project for its fantastic work on its blazing fast BrightScript parser which was used as the foundation for the BrighterScript parser.

1.0.0-alpha.29

1 month ago

0.65.27

1 month ago

1.0.0-alpha.28

2 months ago

0.65.26

2 months ago

0.65.25

2 months ago

0.65.24

2 months ago

0.65.23

2 months ago

1.0.0-alpha.27

2 months ago

0.65.22

3 months ago

1.0.0-alpha.26

3 months ago

0.65.21

3 months ago

0.65.19

3 months ago

0.65.20

3 months ago

1.0.0-alpha.25

3 months ago

0.65.18

3 months ago

0.65.17

3 months ago

0.65.16

4 months ago

0.65.15

4 months ago

0.66.0-alpha.11

4 months ago

0.65.14

4 months ago

0.65.13

5 months ago

0.66.0-alpha.10

5 months ago

0.65.12

5 months ago

0.65.6

7 months ago

0.65.5

8 months ago

0.65.8

7 months ago

0.65.7

7 months ago

0.65.2

10 months ago

0.65.4

9 months ago

0.65.3

9 months ago

0.65.9

6 months ago

0.66.0-alpha.6

7 months ago

0.66.0-alpha.5

8 months ago

0.66.0-alpha.8

5 months ago

0.66.0-alpha.7

6 months ago

0.66.0-alpha.9

5 months ago

0.66.0-alpha.4

9 months ago

0.66.0-alpha.3

9 months ago

0.65.10

6 months ago

0.65.11

5 months ago

0.66.0-alpha.2

11 months ago

0.66.0-alpha.1

11 months ago

0.65.1

11 months ago

0.65.0

12 months ago

0.66.0-alpha.0

11 months ago

0.64.3

1 year ago

0.64.2

1 year ago

0.64.4

12 months ago

0.64.1

1 year ago

0.64.0

1 year ago

0.63.0

1 year ago

0.62.0

1 year ago

0.61.2

1 year ago

0.61.1

1 year ago

0.61.3

1 year ago

0.61.0

1 year ago

0.60.6

1 year ago

0.59.0

2 years ago

0.60.3

2 years ago

0.60.2

2 years ago

0.60.5

1 year ago

0.60.4

2 years ago

0.60.1

2 years ago

0.60.0

2 years ago

1.0.0-alpha.24

2 years ago

0.57.2

2 years ago

0.57.1

2 years ago

0.58.0

2 years ago

0.55.2

2 years ago

0.55.0

2 years ago

0.55.1

2 years ago

0.56.0

2 years ago

0.53.0

2 years ago

0.53.1

2 years ago

0.54.1

2 years ago

0.54.0

2 years ago

0.57.0

2 years ago

1.0.0-alpha.23

2 years ago

1.0.0-alpha.22

2 years ago

0.51.4

2 years ago

0.51.2

2 years ago

0.51.3

2 years ago

0.51.0

2 years ago

0.51.1

2 years ago

0.52.3

2 years ago

0.52.1

2 years ago

0.52.2

2 years ago

0.52.0

2 years ago

0.50.1

2 years ago

0.50.2

2 years ago

0.50.0

2 years ago

0.48.0

2 years ago

0.48.1

2 years ago

0.49.0

2 years ago

1.0.0-alpha.21

2 years ago

1.0.0-alpha.20

2 years ago

0.45.5

2 years ago

0.45.6

2 years ago

0.45.4

2 years ago

1.0.0-alpha.19

2 years ago

1.0.0-alpha.18

2 years ago

1.0.0-alpha.17

2 years ago

0.46.0

2 years ago

0.47.3

2 years ago

0.47.1

2 years ago

0.47.2

2 years ago

0.47.0

2 years ago

0.45.3

2 years ago

0.45.2

2 years ago

1.0.0-alpha.16

2 years ago

0.43.0

2 years ago

0.44.0

2 years ago

0.45.1

2 years ago

0.41.6

2 years ago

0.45.0

2 years ago

1.0.0-alpha.15

2 years ago

1.0.0-alpha.14

2 years ago

1.0.0-alpha.13

2 years ago

0.42.0

2 years ago

0.43.1

2 years ago

0.41.5

2 years ago

0.41.3

3 years ago

0.41.4

3 years ago

0.41.2

3 years ago

1.0.0-alpha.12

3 years ago

1.0.0-alpha.11

3 years ago

0.41.1

3 years ago

0.41.0

3 years ago

1.0.0-alpha.10

3 years ago

0.40.1

3 years ago

1.0.0-alpha.9

3 years ago

1.0.0-alpha.8

3 years ago

0.40.0

3 years ago

0.39.4

3 years ago

0.39.3

3 years ago

1.0.0-alpha.7

3 years ago

0.39.2

3 years ago

1.0.0-alpha.6

3 years ago

0.39.1

3 years ago

1.0.0-alpha.5

3 years ago

0.39.0

3 years ago

1.0.0-alpha.4

3 years ago

0.38.2

3 years ago

1.0.0-alpha.3

3 years ago

0.38.1

3 years ago

1.0.0-alpha.2

3 years ago

0.38.0

3 years ago

1.0.0-alpha.1

3 years ago

0.37.4

3 years ago

0.37.3

3 years ago

0.37.2

3 years ago

0.37.1

3 years ago

0.37.0

3 years ago

0.36.0

3 years ago

0.35.0

3 years ago

0.34.3

3 years ago

0.34.2

3 years ago

0.34.1

3 years ago

0.34.0

3 years ago

0.33.0

3 years ago

0.32.3

3 years ago

0.32.2

3 years ago

0.31.2

3 years ago

0.31.1

3 years ago

0.31.0

3 years ago

0.30.9

3 years ago

0.30.8

3 years ago

0.30.7

3 years ago

0.30.6

3 years ago

0.30.5

3 years ago

0.30.4

3 years ago

0.30.3

3 years ago

0.30.2

3 years ago

0.30.1

3 years ago

0.30.0

3 years ago

0.29.0

3 years ago

0.28.2

3 years ago

0.28.1

3 years ago

0.28.0

3 years ago

0.27.0

3 years ago

0.26.0

3 years ago

0.25.0

3 years ago

0.24.1

3 years ago

0.24.0

3 years ago

0.23.2

3 years ago

0.23.1

3 years ago

0.23.0

3 years ago

0.22.1

3 years ago

0.22.0

3 years ago

0.21.0

3 years ago

0.20.1

3 years ago

0.20.0

3 years ago

0.19.0

3 years ago

0.18.2

3 years ago

0.18.1

3 years ago

0.18.0

3 years ago

0.17.0

4 years ago

0.16.12

4 years ago

0.16.10

4 years ago

0.16.11

4 years ago

0.16.9

4 years ago

0.16.8

4 years ago

0.16.4

4 years ago

0.16.5

4 years ago

0.16.6

4 years ago

0.16.7

4 years ago

0.16.3

4 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.2

4 years ago

0.15.1

4 years ago

0.15.0

4 years ago

0.14.0

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.13.0

4 years ago

0.12.4

4 years ago

0.12.3

4 years ago

0.12.2

4 years ago

0.12.1

4 years ago

0.12.0

4 years ago

0.11.2

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.11

4 years ago

0.10.9

4 years ago

0.10.10

4 years ago

0.10.8

4 years ago

0.10.7

4 years ago

0.10.6

4 years ago

0.10.5

4 years ago

0.10.4

4 years ago

0.10.3

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.0

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago