-
Install Docker on your machine.
-
Copy the
.env.examplefile and name it.env. In the newly created file, change the value ofNODE_ENVto bedevelopment. -
Run
npm installto install NPM dependencies. -
Run
npm run docker:startto start the Node application in Docker. If you haven't built the Docker image before, this might take several minutes. Once the image is ready, the container outputs logs from the development server in the terminal. The container is set up to add a couple of crucial dependencies to the environment for the service to work properly:- Modelica dependencies.
- Pandoc CLI.
- LaTeX.
-
Run
npm run docker:stopto stop the server when you are done or if you want to switch to debug mode.
Note You may use
npm startto start the Node application outside of Docker but you will need to install expected dependencies on your machine for the service to work properly.
Run npm run docker:shell to access the filesystem of the running Docker image with a terminal prompt.
- Run
npm run docker:debugto start the development server in debug mode. - Go to
chrome://inspectin the Chrome browser. - Open the dedicated tools for Node. These tools provide a console, the ability to inspect source code, etc.
- Run
npm run docker:debugto start the development server in debug mode. - In VSCode, select the
Run and Debugtab in the left hand column. Click the cog icon at the top of the opened column and add the followinglaunch.jsonfile:{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Docker: Attach", "port": 9229, "address": "localhost", "localRoot": "${workspaceFolder}/server", "remoteRoot": "/app", "outFiles": [ "${workspaceFolder}/build/app/**/*.js" ], } ] } - With the
Run and Debugcolumn open, click the play icon at the top to runDocker: Attach. At this point, you should be able to set and hit breakpoints in the source code of the server.
- Install the 'Remote Containers' extension.
- Click on the new icon that will show in the left hand column with a hover tip of 'Remote Explorer.'
- Existing containers on your machine should be shown. If it isn't already started, run
npm run docker:startto make sure that Docker containers are running. - Hover over the
linkage-apicontainer and click theAttach to Containerbutton (a folder with a+). - A new VSCode window will open that is attached and reading from the
linkage-apicontainer. It'll be blank, though, as you'll need to specify which directory you'd like to open in the container. Open the/appdirectory (where theserverfolder is mounted). - The VSCode instance running in the container will have its own unique set of extensions. To run tests, install the
Jestextension. This should create a new entry in the left hand column of VSCode that looks like an Erlenmeyer flask (aka a beaker). If the entry doesn't show, you may need to close and re-open VSCode. - The extension will take a moment to discover tests, but after that process is done, you should be up and running to set breakpoints and debug tests.
This project uses Jest to tests functionalities.
- Run
npm run testto execute all tests. - Run
npm run test:cito execute all tests intended for the continuous integration workflow. - Run
npm run unit-testto execute unit tests. - Run
npm run integration-testto execute integration tests.
This repository leverages GitHub Actions to run continuous integration scripts. You can debug these scripts locally thanks to a tool called act.
For instance, the command below locally executes a dry run of the server-tests GitHub Action as if it received a pull_request event:
sudo act pull_request -W .github/workflows/server-tests.yml -n
Note
actmust be executed at the root level of the repository to avoid errors that are essentially false negative.
The backend features an endpoint at POST /api/sequence that generates and serves a Control Sequence Document in the .docx file format. This document is formed thanks to, among other things, a .tex LaTeX template and the input from the request. The content of the LaTeX template derives from the ASHRAE Guideline 36-2021 document.
Note If an error occurred during the creation of the Control Sequence Document, the endpoint will most likely respond with an empty object or, if the error is catchable, a message providing some information about the issue that occurred. Unfortunately, it seems that the external tool used to create the document, Pandoc, does a poor job returning the errors it encounters.
Beyond the entrypoint for the endpoint at /src/index.ts, all the code and files needed to generate the Control Sequence Document can be found in the /src/sequence folder.
This folder contains the following elements:
index.ts: The code for the backend to process the request input and respond with the Control Sequence Document as a binary file.template.tex: The LaTeX template used by Pandoc to produce a.docxfile.source-styles.docx: The Microsoft Word document used by Pandoc to define the styles found in the resulting Control Sequence Document./latex-assets: The subfolder containing raw external assets used by the LaTeX template. Typically, this subfolder contains images in the PNG, JPEG, and SVG formats that were exported manually from the ASHRAE Guideline 36-2021 document./converted-latex-assets: The subfolder containing converted external assets used by the LaTeX template. Typically, this subfolder contains images that are also stored as SVGs in the/latex-assetssubfolder and were manually converted to the PDF format. This folder is necessary to help LaTeX and Pandoc with certain file formats that they do not support very well./output-documents: The subfolder containing files created by the endpoint as a result of the generation of the Control Sequence Document. Typically, this subfolder contains.docxand.texfiles where the name follows this pattern:sequence-DATE_TIME_UTC.FILE_EXTENSION(e.g.,sequence-2022-07-28T20:07:15.746Z.docx).
Note None of the files created in this process are exposed by the backend. The endpoint directly serves the
.docxControl Sequence Document once after generating it. The file is stored in the filesystem but kept private. If access to Control Sequence Documents is needed after they are generated, some additional code will need to be written in order to handle that (most likely using theexpress.staticmiddleware pointing at the/sequence/output-documentssubfolder or another solution described in this blog post, for example).
TODO
The .docx document returned by the endpoint is created in the following manner: