Creating a new local package
This page provides instructions on how to create a new local package to share code between applications in a Caplin Trader workspace.
Requirements
Packages for Caplin Trader 5 applications are created within the context of a Caplin Trader development workspace. For more information on creating a development workspace, see Creating a new workspace.
Creating a new local package
You create a local package by using Caplin CLI’s create-package
command:
$ caplin-cli create-package <package-name>
To create a new local package called my-package, for example, follow the steps below:
-
From the root directory of your CT5 development workspace, run the command below to create a local package called my-package:
$ caplin-cli create-package my-package
Your new local package has the following structure:
-
Change directory to
<workspace>/packages/my-package
, and run the command below to download the new package’s dependencies:$ yarn install
Installing a local package in an application
You install local packages to an application by passing a local path to the yarn add
command.
To install the package my-package
created in the previous section, follow the steps below, run the command below from the root directory of your Caplin Trader application:
$ yarn add file:../../packages/my-package
Updating a local package in an application
Each time you update the source code for your local package under your workspace’s packages
directory, you will need to update your application’s copy of the local package.
Run the command below from your application’s root directory to update its copy of the local package:
$ yarn upgrade <package-name>
If your local package is in active development, running yarn upgrade
each time you change your package’s code can quickly become tedious. To save time, you can use the yarn link
command to symlink your application’s copy of the package to the local package.
Follow the steps below:
-
In the local package’s directory, run
yarn link
:$ cd ~/dev/ct5-workspace/package/my-package $ yarn link yarn link v1.10.1 success Registered "my-package". info You can now run `yarn link "my-package"` in the projects where you want to use this package and it will be used instead. Done in 0.04s.
-
Run the command below from the root directory of your application:
$ cd ~/dev/ct5-workspace/apps/my-app $ yarn link my-package yarn link v1.10.1 warning package.json: No license field success Using linked package for "my-package". Done in 0.04s.
For more information, including how to unlink a package, follow the links below: