Building an application

The page provides instructions for building an application so it can be deployed to production.

Requirements

Your application must be committed to a Git repository before you can build the application. The application’s build script creates version strings based on your HEAD branch’s commit count, hash, and branch descriptor.

Building an application

To build an application, follow the steps below:

  1. Commit any pending changes in your application to Git. The example commands below commit all modified and untracked files:

    $ git add --all
    $ git commit -m "<message>"
  2. From the root directory of your application, run the command below to build the application:

    $ yarn run build

The build task writes a JavaScript bundle and a Java web application archive (WAR) file under your application’s build directory:

builddiststaticbundle-dev.jsindex.htmlexported-wars MyApp.war

The WAR file is an archived version of the contents of the build/dist directory and can be deployed to a Java application server.

Troubleshooting build issues

This section describes common issues you may encounter when running yarn run build or yarn start.

Alias <name> not registered

WARN [aliases-plugin] <time>: Alias "<name>" not registered.

This warning is generated when your application references a Caplin Trader alias but has not declared in the file ~/src/config/aliases.js which package provides the alias.

Aliases

A Caplin Trader alias is a stand-in for a class name that is resolved to a specific class at build time. The mapping of aliases to implementations is configured in your application’s ~/src/config/aliases.js file.

By using aliases to refer to shared data services such as the Permissioning Service, Caplin Trader makes it easy to substitute different implementations of data services when building for development, test, and production environments.

While some Caplin Trader 5 packages continue to use aliases, Caplin Trader 5’s compatibility with Node.js opens up alternative options for providing shared data services in your own application code, such as AngularJS’s dependency injection, and Redux’s store and middleware.

To resolve a missing alias warning, determine which Caplin package defines the alias, and copy the definition of the alias to your application’s ~/src/config/aliases.js file.

For example, consider the code below which requires the Caplin Trader service caplin.event-service:

const eventService = require("service!caplin.event-service");

The identifier caplin.event-service is an alias, and unless a implementation for the alias is declared in the application’s src/config/aliases.js file, yarn run build and yarn start will generate the following warning:

Example warning
WARN [aliases-plugin] 02:46:30: Alias "caplin.event-service" not registered.

To resolve the missing alias registration in the example above, follow the steps below:

  1. Use the grep command to search your application’s node_modules directory for the Caplin package that defines the missing alias:

    $ grep -R --include=aliasProviders.js 'caplin\.event-service' node_modules
    node_modules/ct-services/aliasProviders.js:  "caplin.event-service": function() {

    The output from the command reveals that the ct-services package defines the caplin.event-service alias.

    On Microsoft Windows, the grep command is available in Cygwin and the Bash shell of Git for Windows.
  2. Copy the alias definition for caplin.event-service from node_modules/ct-services/aliasProviders.js to the object exported by your application’s src/config/aliases.js file:

    File: node_modules/ct-services/aliasProviders.js
    module.exports = {
      "caplin.log-store-service": function() {
        return require("ct-core/log/LogStoreService");
      },
      "caplin.event-service": function() {
        return require("ct-core/event/EventHub");
      },
      "caplin.config-service": function() {
        return require("./providers/CaplinConfigService");
      },
      "caplin.user-prompt-service": function() {
        return require("./providers/BrowserUserPromptService");
      }
    };
    File: src/config/aliases.js
    module.exports = {
      "caplin.event-service": function() {
        return require("ct-core/event/EventHub");
      }
    };