Profiles

Configure your application

The application is configured with the app.config.json file, that may contain different profiles.

Definition

All available profiles for an application are defined in the file `app.config.json.

{
  "default": {
    "resolution": {
      "name": "fullHd",
      "width": 1920,
      "height": 1280
    }
  },

  "my-profile": {
    "mixins": ["default"],
    "base": {
      "name": "html5",
      "vendors": ["html5"]
    },
    "resolution": {
      "name": "hdReady",
      "width": 1280,
      "height": 720
    }
  }
}

In this example, 2 profiles are declared:

  • default: a default profile, which is mandatory
  • my-profile: a profile derived from the default one, which overrides the resolution
grunt serve --profile=my-profile

Default profile

There is always one profile default, which is the one that is used when the --profile option is not specified.

Warning

You should never use grunt tasks without profile.

Resolve profile

The toolchain will resolve the profile and create a profile.json file (see generated/<profileName>/config directory).

You can import the resolved profile in the application by using:

import profile from "profile.json";

Local configuration file

Each developer can create a app.config.env.json that belongs to him (this file must be ignored by git).

The content of this file will be automatically merged with the app.config.json when running the toolchain, meaning that you can overwrite part of the configuration file for your own needs with no impact on the configuration file used by everyone.

{
  "fullHd": {
    "device":{
      "host": "10.1.45.50"
    }
  }
}

Profile file split

When you have multiple devices, number of lines in app.config.json file will increase. To help you organize your profiles, you can split them in multiple files.

Create new file app.config.XXX.json under profiles folder. You can then include this json inside app.config.json.

{
  "includes": [
    "profiles/app.config.XXX.json"
  ]
}

Base

A base is a technical environment that offers implementations based on one or multiple vendors.

Each profile must define the implementations it is based on.

A base declare the vendors it is built on, and optionally will specify which implementation of which vendor for which service it must use.

{
  "my-box": {
    "base": {
      "name": "Html5",
      "vendors": [
        "html5",
        "mock"
      ],
      "implementations": {
        "PvrService": "Html5PvrService"
      }
    }
  }
}
{
  "default": {
    "autoRun": true,
    "firstScreen": {
      "id": "welcomeHomeScreen",
      "options": {
        "childToFocus": "rootContainer"
      }
    }
  }
}

Note

childToFocus can also be defined in the screen itself by using _getChildToFocus method. See Focus

Global configuration

You can configure some aspect of the framework through the profile.

nametypedescriptiondefault
autorunbooleanAutomatically open the browser (or device) to start the application after the build is done.false
firstScreenobjectThe first screen to show (its id and options){id:$Application.screens[0].prototype.id, options: {childToFocus: $Application.screens[0].children[0]}
localesstring[]List of available languages that are going to be bundled inside the application. See documentation[]
isBenchbooleanFlag to be used for profiles used for benchmark to allow metrics calculationfalse
isTestbooleanFlag to be used for profiles used for functional test to limit logsfalse
resolutionobjectObject containing width and height value for resolution
flagsobjectObject containing flag to be activated or not. See flags documentation
deviceobjectObject containing information about the target device. See flags documentation
es5booleanAllow transpile to es5false
es3booleanAllow transpile to es3false
polyfillsstring[]See polyfills documentation

Flags

nametypedescriptiondefault
rtlbooleanEnable right to left support. See right to left documentationfalse

Device

nametypedescriptiondefault
typestringDevice identifier
enableAnimationbooleanOnly used with @dana/renderer-css vendor. Enable animationsfalse

For other variables, see dedicated device documentation:

Singletons and services configuration

You can configure all singletons and services from the profile and more generally all singletons of the framework.

You just need to declare an object with the singleton name as the key and add all the configuration you want:

{
  "my-profile": {
    "I18nManager": {
      "defaultLocale": "en-GB"
    },
    "Logger": {
      "ConsoleAppender": {
        "level": "info"
      }
    }
  }
}

Environment variables

You can use environment variable in a profile. This can be useful for development and test purpose for instance if you need to specify your IP or server address:

{
  "my-profile": {
    "host": "<%= env.IP %>"
  }
}

It will check if value match with pattern <%= KEY %> and search associate value in :

  1. ~/.wtv/env.json
  2. environment variables
  3. if no value is found, the key is used as the value and some warnings are returned

Profile theme configuration

You can declare some configuration in profiles for theme:

{
  "my-profile": {
    "base": {
      "name": "myProfile",
      "vendors": [
        "html5"
      ],
      "theme": {
        "file": "theme.less",
        "testColor": "red",
        "width": "$$resolution.width$$"
      },
      "resolution": {
        "name": "hdReady",
        "width": 1280,
        "height": 720,
        "ratio": 0.6666666666666666
      }
    }
  }
}

You can use some variables to declare a value in another object, as above with “theme.width”. $$resolution.width$$ will be replaced by resolution width’s result (1280) and by another object in final step : { unit: "", value: 1280}.

You can add some operations, a task will calculate that :

{
  "my-profile": {
    "base": {
      "name": "myProfile",
      "vendors": [
        "html5"
      ],
      "theme": {
        "file": "theme.less",
        "testColor": "red",
        "width": "128px * 10"
      }
    }
  }
}

As you can see, “theme.width” is an operation, it will be replaced by {unit: "px", value: 1280}.

Profile composition

You can compose profiles for factorization purpose:

{
  "oneProfile": {
    "host": "<%= env.IP %>"
  },
  "anotherProfile": {
    "host": "<%= oneProfile.host %>"
  }
}
{
  "default": {
    "resolution": {
      "name": "fullHd",
      "width": 1920,
      "height": 1280
    }
  },
  "base-720p": {
    "resolution": {
      "name": "hdReady",
      "width": 1280,
      "height": 720
    }
  },
  "base-key-mapping": {
    "keyMapping": {
      "MENU": 462,
      "BACK": 461,
      "POWER": 409,
      "EXIT": 27
    }
  },
  "my-profile": {
    "mixins": [
      "default",
      "base-key-mapping"
    ]
  },
  "my-profile-720p": {
    "mixins": [
      "my-profile",
      "base-720p"
    ]
  }
}

Allow log appenders

By default, all logs are removed in packaged files. You can enable them, with productFilter option (we recommend to use FileAppender).

{
  "my-profile": {
    "Logger": {
      "productFilter": true,
      "FileAppender": {
        "level": "info"
      }
    }
  }
}

Comments

JSON format specify that comments are not allowed. But comments are very useful when you have a big modular application with several profiles and several components to configure.

So we have some pre-processing tool which will remove comments before evaluating the JSON. It enables comments in your profile file:

{
  "default": { // My default profile !
    ...
  }
}