JSPM

bsc-plugin-update-main-args

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q26014F
  • License ISC

A BrighterScript plugin that injects properties into the argument of the main function - useful for adding deeplinks for debugging

Package Exports

  • bsc-plugin-update-main-args
  • bsc-plugin-update-main-args/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bsc-plugin-update-main-args) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Update Main Args (Brighterscript Plugin)

build status

A Brighterscript plugin that injects properties into the argument of the main function - useful for adding deep links for debugging, for example.

It works by injecting a single line of code as the first line the main() function, like this:

sub main(args as dynamic)
    args.append(parseJson("{""extra"":""args here""}"))
    ...
end sub

Usage

In a Brighterscript project, install the plugin:

npm install -D bsc-plugin-update-main-args

Add it to the plugins list in bsconfig.json, and set up the arguments to load:

{
    "plugins": ["bsc-plugin-update-main-args"],
    "updateMainArgs": {
        "args": {
            "mediaType": "movie",
            "contentId": "test-1234"
        }
    }
}

Read Args from .env

This plugin can also read arguments from an .env file (or from your system's environment variables).

Create a .env file with the variable MAIN_ARGS. It should be in JSON format:

MAIN_ARGS={"mediaType":"movie","contentId":"test-1234"}

Change the bsconfig options to load the environment variable:

{
    "plugins": ["bsc-plugin-update-main-args"],
    "updateMainArgs": {
        "useEnv": true,
        "envFilePath": ".env"
    }
}

Full Configuration Options

{
    "updateMainArgs": {
        "useEnv": true, // read environment variable
        "envFilePath": ".env", // path to specific .env file to read
        "envVar": "MAIN_ARGS", // The environment variable to read
        "args": {} // Just add args directly
    }
}

Example App

There is an test app showing how the plugin works in ./testapp (with the caveat that it is loading the plugin directly from source instead of through npm).

You can run the test app through VSCode:

  1. npm install to install all dependencies
  2. Open VSCode, run debug configuration Debug Test App

It will display all the arguments that werethe following screen:

Test App Screenshot

Test App configuration (./testapp/bsconfig.json):

{
    "updateMainArgs": {
        "useEnv": true,
        "envFilePath": "./testenv",
        "args": {
            "extra": "args here",
            "extra_params": {
                "can": "include",
                "objects": "too"
            }
        }
    }
}

Environment variables file (./testapp/testenv):

MAIN_ARGS={"mediaType":"movie","contentId":"abc1234"}