Build
This document explains how to build and run the application from the source code, but also how to package and distribute it.
Prerequisites
- Node.js v22.7.1+ with npm (tested) or pnpm or yarn for building the application's components and the extensions.
- Python v3.11+ for building the Python extensions.
- The back-end module requires Java v17+, which should be accessible as a first Java runtime through the
PATH, when generating the OpenAPI client code. - When building the container image, a Docker-like application should be up and running.
Compiling and building
The following commands will install dependencies and build the components. They should be run from the root package.json file.
- Run the traditional
npm run installscript for resolving the hereby package dependencies. - Run the
npm run prerequisitesscript for resolving all submodules' dependencies: do not run individually thenpm installscript on every module, because it will not properly install the "back-end" and "electron" components since theprerequisitesnpm script resorts to the--install-linkoption, which installed the "shared/back-end" module dependencies. - Run the
npm run buildscript for building all artifacts.
Most of the artifact files are located under the build directory, which is a symbolic link pointing to the electron/build directory.
Cleaning
The following commands enable cleaning up the project. They should be run from the root package.json file.
- Run the
npm run cleanscript for cleaning all artifacts coming from compilation and previous builds. - Run the
npm run resetscript for resetting the state of the project's files to their git initial state — in particular, this deletes thenode_modulesdirectories.
Versions
The versions of the various components are specified through the root package.json file via the config.applicationVersion, config.apiVersion and config.sdkVersion properties:
config.applicationVersion: the version of the Electron application ;config.backEndVersion: the version of the back-end application ;config.frontEndVersion: the version of the front-end application ;config.apiVersion: the version of the API and its OpenAPI web services contract ;config.sdkVersion: the version of the SDK.
Whenever changing any of those versions, think of running the npm run updateVersion script from the root directory to propagate the version changes to the relevant submodules, which updates the src/constants.ts file accordingly and the SDK version and the extensions' dependency version accordingly.
Back-end (server)
Its source-code and scripts are located under the back-end directory.
All the commands specified in that section should be run from the back-end subdirectory and all resource locations are expressed from that directory, unless stated otherwise explicitly.
Build
- To build the back-end from scratch, run the following command from the root folder:
npm run back-end:prerequisites && npm run back-end:build. - To recompile it after having changed its code, run the
npm run buildscript.
Run
To run the back-end, run the npm run start script. The environment variables which have an impact over the execution as well as the commands and parameters are described by running the npm run start:help script.
You may access to the SwaggerUI relative the OpenAPI specifications, captured through the JSON openapi.json file, open the browser to the http://localhost:3001/swaggerui URL, 3001 being the back-end default port.
Development
-
When changing the database Prisma schema:
- run the
npm run prisma:generatescript to regenerate the Prisma client code, - then run the
npm run prisma:updatescript to update the schema of the startup database filedatabase.dband to add the new SQL migration script in theprisma/migrationsdirectory (in case of a synchronization issue with the schema migration, read this article Make Prisma Ignore a Migration Change), - and then run the
npm run prisma:seedscript to update thesettingstable value startup database filedatabase.dbwith its settings set to the latest version of the migration.
- run the
-
When changing the OpenAPI contract, run the
openApi:generateOpenApiscript to regenerate theopenapi.jsonfile.- Think of updating the
config.apiVersionproperty. - The
npm run openApi:typeScript:generateAndPackagescript generates the TypeScript OpenAPI client library into the directory../generated/openapi/typescript-fetch. - The
npm run openApi:python:generateAndPackagescript generates the Python OpenAPI client library into the directory../generated/openapi/python. - The
npm run openApi:generateAndPackagescript generates the 2 previous packages.
- Think of updating the
-
Whenever the database schema changes, a file in the
secretsorassetsdirectory changes, run thenpm run build:copyscript to update the Electron applicationdistdirectory.
API web services client library publication
To publish a new version of the API web services client library, run the npm run wsClient:publish script, after having built the libraries via the previous openApi:generateAndPackage script:
- for publishing the Node.js package on npm, use the
npm login --scope=@koppasoftcommand to log in first ; - for publishing the Python package on PyPi, declare an API token at https://pypi.org/manage/account/token/ beforehand.
Extensions
The SDKs and extensions and scripts are located in the extensions directory and the commands in the rest of this section should be run from that directory:
- the SDKs are in the
sdksubdirectory ; - the extensions are in the
instancessubdirectory.
For building the SDKs and extensions:
- run the
npm run sdk:buildscript to build the SDKs ; - run the
npm run instances:buildscript to build the extensions ; - run the
npm run buildscript to build both.
When a new version should be applied to all extensions, run the npm run incrementVersion script to increment their minor version.
SDKs publication
To publish a new version of the SDKs, run the npm run sdk:publish script, after having built the SDKs via the sdk:public:build script:
- for publishing the Node.js SDK package on npm, use the
npm login --scope=@koppasoftcommand to log in first ; - for publishing the Python SDK package on PyPi, declare an API token at https://pypi.org/manage/account/token/ beforehand.
Front-end (web)
Its source-code and scripts are located under the front-end directory.
All the commands specified in that section should be run from the front-end subdirectory and all resource locations are expressed from that directory, unless stated otherwise explicitly.
Build
- To build the front-end component from scratch, run the following command from the root folder:
npm run front-end:prerequisites && npm run front-end:build. - To recompile it after having changed its code, run the
npm run buildscript.
Run
To run the front-end component, run the npm run start script.
Shared
Its source-code and scripts are located under the shared directory. It only contains a back-end folder, which contains code common between the "back-end" and "electron" modules.
- Run the
npm run buildscript to build it, which will compile the code.
Electron
Its source-code and scripts are located under the electron directory.
- Run the
npm run startscript to start it on the local machine. - Run the
npm run buildscript to build it for the same target OS as the hosting machine, which outputs a runnable artifact inside thedistdirectory. - Run the
npm run packagescript to package it for the same target OS as the hosting machine.
Container image
The container image specifications are classically defined through the Dockerfile file and the ignored files through the .dockerignore file.
Build
To build the container image of the back-end application via Docker, which also embeds the front-end application, run the npm run docker:build script from the root directory, which creates an image with the koppasoft/picteus:latest tag.
Publish
To publish a new version of the container image, run the npm run docker:publish script from the root directory, which pushes it against Docker Hub.
Run
Refer to container.md for running the container.
Packaging and distributing
The Electron application:
- is packaged via the
npm run packagescript: this invokes the previously mentioned Electronpackagenpm script ; - is distributed via the
npm run distributescript — which also invokes the previous one —, which signs, zips and notarize the application distribution package on macOS, which should be executed with the following environment variables set, when run on macOS:
MACOS_APPLICATION_CERTIFICATE_BASE64_CONTENT: the base64 encoded content of the application certificate. This content is obtained via thebase64 -i <certificate.p12>command, where<certificate.p12>is the path of the "Developer ID Application" certificate file in P12 format ;MACOS_APPLICATION_CERTIFICATE_PASSWORD: the password of the previous certificate ;MACOS_NOTARIZE_APPLICATION_PASSWORD: the Apple application-specific password related to thePicteusentry, used to notarize the application package ;PICTEUS_CHROME_EXTENSIONS_TOKEN: the Personal Access Token (PAT) value for access the private GitHub repository containing the Chrome extensions ;
- is deployed via the
npm run deployscript, which uploads the previously generated application distribution package: thegcloud logincommand should have been run beforehand, with GCP credentials having permissions over the destination GCS bucket, or with theCLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDEenvironment variable set with the contents of a GCP account service key with writing permissions over the GCS bucket.