Creating next-generation Order Hub applications using a monorepo
Using an Angular monorepo strategy uses Lerna to host several applications in a single repository. This setup provides you with the means to reuse the code, share between applications without having to duplicate code or create library repositories and smaller builds per route, which saves you time. The monorepo strategy is used by all IBM® provided Order Hub repositories. This strategy provides you with a clean customization approach where you can customize routes in an existing IBM repository without taking over all unchanged routes.
About this task
This schematic creates a new monorepo to hold multiple projects for your new applications by using Lerna and Single-Spa.
Procedure
npm uninstall -g @buc/schematics
npm install -g ./lib/buc/schematics/schematics-v4latest.tgzFor Angular v20, run the
following command.npm uninstall -g @buc/schematics
npm install -g ./lib/buc/schematics/schematics-v5latest.tgz
{
"name": "custom-monorepo",
"devServerConfig": {
"port": 9300,
"contextRoot": "/custom-monorepo"
},
"prodServerConfig": {
"hostName": "static.omsbusinessusercontrols.ibm.com"
},
"routes": {
"custom-page1": {
"devServerConfig": {
"port": 9301,
"contextRoot": "/custom-page1"
}
},
"custom-page2": {
"devServerConfig": {
"port": 9302,
"contextRoot": "/custom-page2"
}
}
}
}
ng new --collection=@buc/schematics \
--app-config-json=<app-config.json-file-name> \
--module-short-name=<short-name-for-the-module> \
--prefix=<selector-prefix> \
--mode=on-prem
Note: The ng new command requires the --mode=on-prem
parameter.
The schematic supports the following options.- --skip-git
- This option does not initialize a GitHub repository. The default is false.
- --commit
- This option includes the initial GitHub repository commit information. The default is true.
- --app-config-json
- This option is required. Use the app-config.json file that you created in step 5.
- --module-short-name
- The short name for the module. If the module name has dashes, then the short name must be the text after the last dash. For example, if the module name is buc-app-settings, the module short name must be settings.
- --prefix
- The HTML selector to use for generated components. The default is buc.
- --shared-library-name
- The name of the shared library. The default name is <module-short-name>-shared. The package name is @<prefix>/<module-short-name>-shared.
- --generate-root-config
- Indicates whether to generate a root-config router project. The default is true.
- --skip-install
- Indicates whether to install packages. The default is false.
- --mode
- Set this option to on-prem to generate code that is applicable for next-generation Order Hub.
See the following example.
ng new --collection=@buc/schematics --app-config-json=app-config.json
--module-short-name=monorepo --prefix=monorepo --mode=on-premAfter the command
completes, a Packages installed successfully. message is displayed.
Note: If you
encounter an error similar to the following message, you can safely ignore the error. These errors
do not affect the icons that are used by next-generation Order Hub.
Error: Failed to compile entry-point @carbon/icons-angular/
./om-compose.sh start orderhub
docker exec om-orderhub-base bash -c 'mkdir -p /opt/app-root/src/shell-ui/assets/custom'
docker cp <orderhub-code>/shell-ui/assets/dev/. om-orderhub-base:/opt/app-root/src/shell-ui/assets/custom/
yarn start-app
Note: You see the following
message.
"** Angular Live Development Server is listening on localhost:<port>, open your browser on https://localhost:<port>/<module>/<route> **"You can ignore this message.
Note: If you encounter an error similar to the following message, increase the heap size before you
start the new application.
Error command failed with exist code 134. lerna ERR! yarn run start .... exited 134Run the following command and then start the new application.
- Windows CMD prompt:
SET NODE_OPTIONS=--max_old_space_size=8048 - Bash/Git Bash:
export NODE_OPTIONS=--max_old_space_size=8048 - Powershell:
$Env:NODE_OPTIONS=--max_old_space_size=8048
Note: If you need to stop the server, stop the server job and run the yarn
stop-app command to verify that everything is stopped properly.
Note: To accept the certificate, it is now
https://localhost:9300 instead of
https://bucgenerichost:9300.