Repository: digital-development
Kalmar Energi frontend Monorepo
Section titled “Kalmar Energi frontend Monorepo”This repository contains frontend applications for Kalmar Energi.
It uses NX to handle the monorepo setup.
Read more in the getting started documentation
Or the NX blog
Use the NX Playbook
Or follow the NX youtube channel
Development
Section titled “Development”Install dependencies
Section titled “Install dependencies”To install development dependencies run:
npm installEnable “short/named imports” in VS code
Section titled “Enable “short/named imports” in VS code”Add this to user settings.json:
"typescript.preferences.importModuleSpecifier": "shortest","javascript.preferences.importModuleSpecifier": "shortest",Local development server
Section titled “Local development server”To start a development server for any given angular application run:
npx nx serve [app-name]Ex:
npx nx serve outageor
npx nx run outage:serve:developmentTo start a development server for multiple applications at once, run:
npx nx run-many --target=serve --projects=[app-name],[app-name]Ex:
npx nx run-many --target=serve --projects=device,outageVS Code
Section titled “VS Code”Its recommended to install the official nx plugin “NX Console”. This plugin provides generators and commands to make it easier to work with NX.
The Angular Language Service plugin helps with code completion while writing angular code.
ESLint provides feedback for when ESLint rules are not followed.
Other commands
Section titled “Other commands”To run build command against a given app run:
npx nx run outage:build:productionTo run lint command against a given app run:
npx nx run outage:lintor
npx nx run outage:lint --fixGenerate libs/components
Section titled “Generate libs/components”Use the --dry-run flag to see what will be generated without actually running the command.
To generate a new library run
npx nx g @nx/angular:library shared-ui --tags=shared-uinpx nx g @nx/angular:library features --tags=featuresnpx nx g @nx/angular:library operators --tags=operatorsnpx nx g @nx/angular:library models --tags=modelsGenerate component inside shared-ui
npx nx g @nx/angular:component header --project=shared-ui --exportnpx nx g @nx/angular:component footer --project=shared-ui --export --standalonenpx nx g @nx/angular:component alert --project=shared-ui --export --standalonenpx nx g @nx/angular:component table --project=shared-ui --export --standalone --inline-style --inline-templatenpx nx g @nx/angular:component dialog --project=shared-ui --export --standalone --inline-style --inline-templateTo generate a standalone component inside the features library
npx nx g @nx/angular:component not-found --project=features --standalone --exportThis component can later be imported like:
import { NotFoundComponent } from "@portal/features";or
loadComponent: () => import("@portal/features").then((m) => m.NotFoundComponent),Generate a new feature
npx nx g @nx/angular:module not-found --project=featuresnpx nx g @nx/angular:component not-found --project=features --module=not-found --exportnpx nx g @nx/angular:component not-found --project=features --standaloneInteractive Dependency graph
Section titled “Interactive Dependency graph”View interactive project graph
npx nx graphsee what’s been affected by changes
npx nx affected:graph --base=master --head=HEADrun tests for current changes
npx nx affected:testrun e2e tests for current changes
npx nx affected:e2eGenerate locale/translations
Section titled “Generate locale/translations”To run i18n command against a given app run:
npx nx run outage:extract-i18n --format=xlf2 --output-path apps/outage/src/localeor
npm run outage:extract-localeBuild in CI/CD
Section titled “Build in CI/CD”To enable post build command the nx command needs to bee triggered through npm run. So to make sure localization index.html is copied to the dist folder, in CI/CD run the following:
npm run outage:build:productionClear cache
Section titled “Clear cache”npx nx clear-cacheUpdate related dependencies
Section titled “Update related dependencies”To upgrade all dependencies to latest minor version run:
npx npm-check-updates --upgrade --target "minor"To update all angular related dependencies to latest available minor/patch version run:
npx npm-check-updates --upgrade --target "minor" --filter "/@angular.*/"To update all typescript/eslint related dependencies to latest available minor/patch version run:
npx npm-check-updates --upgrade --target "minor" --filter "@typescript-eslint/*"Sort dependencies
Section titled “Sort dependencies”Sort all dependencies by running:
npx sort-package-jsonVendors
Section titled “Vendors”The following dependencies are installed from static files in the vendor folder:
xlsx
SheetJS are currently (or permanently) uploading new versions via their own CDN. See https://git.sheetjs.com/sheetjs/sheetjs/issues/2667
Because of this, the package can not be installed via npm anymore. To not depend on SheetJS CDN being online during npm installs, the static file is saved as a vendor module.
A regular check in the changelog is prefferable to determine if any new version should be downloaded to upgrade the package.