Skip to content

Commit f534f4c

Browse files
authored
feat!: update deps, refactor, remove selfContained and more (#84)
- clean and update dependencies - Replace deps with node alternatives: request, lodash - make package ESM only - upgrade node to 22 - Add more config examples and improve README with examples - remove selfContained option. This option was adding a lot of code and complexity. Building a site which actually does not do any outside requests is difficult to guarantee in this context and the existing implementation had a lot of problems and cases not covered. - enable server side inclusions in dev apache configuration. - allow the config CLI argument to be passed multiple times - split code into separate files, which required a lot of refactoring - improve lock reliability, and use it only when using the CLI to build - fix build config when passed an absolute layout path - adapt dev docker compose to allow to switch between builds easily via environment variable - update release action BREAKING CHANGES: Package is now ESM only. Upgrade node to 22. Support for `selfContained` was removed. Only use lock when run with CLI. Remove `pidFile` config and use temporary file instead.
1 parent 8d4f494 commit f534f4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4913
-4462
lines changed

.eslintrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ on:
66
- main
77
pull_request:
88

9-
env:
10-
NODE_VERSION: 20.x
11-
129
jobs:
1310
lint:
1411
runs-on: ubuntu-latest
1512
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1815
with:
19-
node-version: ${{ env.NODE_VERSION }}
16+
node-version-file: package.json
2017
- name: Install dependencies
2118
run: npm install
19+
- name: Run prettier
20+
run: npm run prettier
2221
- name: Run ESLint
2322
run: npm run eslint

.github/workflows/release.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@ on:
55
branches:
66
- main
77

8-
env:
9-
NODE_VERSION: 20.x
10-
118
jobs:
12-
release-please:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Get package name
16-
run: echo "PACKAGE_NAME=$(jq .name package.json | tr -d '"')" >> $GITHUB_ENV
17-
- uses: GoogleCloudPlatform/release-please-action@v2
18-
id: release
19-
with:
20-
token: ${{ secrets.BOT_TOKEN }}
21-
release-type: node
22-
package-name: ${{ env.PACKAGE_NAME }}
9+
release:
10+
# Documentation: https://github.com/zakodium/workflows#release
11+
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
12+
with:
13+
npm: true
14+
secrets:
15+
github-token: ${{ secrets.BOT_TOKEN }}
16+
npm-token: ${{ secrets.NPM_BOT_TOKEN }}

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
build
22
config.json
33
layouts.json
4-
node_modules
4+
node_modules
5+
coverage
6+
7+
test-coverage.js
8+
9+

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
*.html
1+
*.html
2+
themes
3+
lib
4+
CHANGELOG.md

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:20-slim
1+
FROM node:22-slim
22

33
RUN apt-get update && apt-get install -y cron git
44

@@ -14,7 +14,7 @@ RUN touch /var/log/cron.log
1414
COPY start.sh /start.sh
1515
RUN chmod 744 /start.sh
1616

17-
COPY on-tabs-config.json /on-tabs-config.json
17+
COPY ./configs/on-tabs.json /on-tabs-config.json
1818

1919
COPY ./ ./
2020

README.md

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
# flavor-builder
2+
23
Visualizer website generator
34

45
## Test the build
56

67
To test the build, run:
78

89
```bash
9-
DEBUG=flavor-builder:info node bin/build.js --config=./cheminfo-config.json
10+
DEBUG=flavor-builder:info node bin/build.js --config=./configs/cheminfo.json
1011
```
1112

12-
As configured by `cheminfo-config.json`, this will write to the `build` directory:
13+
There are other build configurations available in the `configs` directory to test.
14+
15+
As configured by `configs/cheminfo.json`, this will write to the `build` directory:
16+
1317
- `cheminfo-revisions.json` and `cheminfo-md5.json` which keep track of what has been updated.
14-
- `cheminfo-flavor-builder.pid` which is used as a lock to know if a build is already in progress.
1518
- `out` directory which contains the result of the build
1619

1720
Build the admin page by running:
21+
1822
```bash
1923
mkdir build/out/on-tabs
20-
node node_modules/visualizer-on-tabs/bin/build.js --outDir=$(realpath ./build/out/on-tabs/) --config=$(realpath ./on-tabs-config.json)
24+
node node_modules/visualizer-on-tabs/bin/build.js --outDir=$(realpath ./build/cheminfo/out/on-tabs/) --config=$(realpath ./configs/on-tabs.json)
2125
```
2226

2327
To test the built website using apache, run:
@@ -26,9 +30,41 @@ To test the built website using apache, run:
2630
docker compose up -d
2731
```
2832

29-
And visit `http://localhost:6060`, and `http://localhost:6060` for the visualizer admin page.
33+
Home page: `http://localhost:6060`
34+
Example of on-tabs page: `http://localhost:6060/flavor/eln/reaction/index.html`
35+
36+
If you built the admin page, you can access it at: `http://localhost:6060/on-tabs/`
37+
38+
## Build with couchdb authentication
39+
40+
If access to the CouchDB database is protected, use the `COUCHDB_USER` and `COUCHDB_PASSWORD` environment variables to provide the credentials.
41+
42+
For example, assuming you have a working couchdb instance on `localhost:5984`, you could run:
43+
44+
```bash
45+
DEBUG=flavor-builder:info COUCHDB_USER=admin COUCHDB_PASSWORD=<FILL_PASSWORD_HERE> node bin/build.js --config=./configs/scipeaks.json
46+
```
47+
48+
````bash
49+
50+
## Test an alternative build
51+
52+
Use your own configuration or build from one of the existing ones in the `configs` directory.
53+
54+
```bash
55+
DEBUG=flavor-builder:info node bin/build.js --config=./configs/flavor-1024.json
56+
# Will serve build/flavor-1024/out/ on port 6060
57+
SERVE_DIR=flavor-1024 docker compose up -d
58+
open http://localhost:6060/
59+
````
60+
61+
> **Warning**
62+
> The `on-tabs` page is not fully functional in this setup.
63+
64+
> [!WARNING]
65+
> Critical content demanding immediate user attention due to potential risks.
3066
31-
The admin page or the `on-tabs` pages build by the flavor-builder are not expected to work with this setup.
67+
TODO: example with couch authentication.
3268
3369
## CLI usage
3470
@@ -43,5 +79,3 @@ It is responsible for building static assets but not for running a web server li
4379
- The outputs of the builds are written to `/var/www/html/` base directory on the container.
4480
- Runs a command when the container starts that builds the visualizer admin page to the `on-tabs` directory, based on the `/on-tabs-config.json` configuration file.
4581
- Runs a command every minute which builds pages to the base directory based on the `/flavor-config.json` configuration file.
46-
47-

apache.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM httpd:2-alpine
2+
3+
# my-httpd.conf was created by first getting the default httpd.conf:
4+
# $ docker run --rm httpd:2-alpine cat /usr/local/apache2/conf/httpd.conf > configs/httpd.conf
5+
# Then, it was modified to allow for SSI
6+
# `LoadModule include_module`: Loads the SSI module.
7+
# `Options ... Includes`: Enables SSI in the specified directory.
8+
# `AddType` and `AddOutputFilter`: Ensures .html files are parsed for SSI.
9+
10+
COPY ./httpd.conf /usr/local/apache2/conf/httpd.conf

bin/build.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
#!/usr/bin/env node
22

3-
'use strict';
3+
import { tmpdir } from 'node:os';
4+
import path from 'node:path';
5+
import process from 'node:process';
46

5-
let args = require('minimist')(process.argv.slice(2));
7+
import minimist from 'minimist';
68

7-
let flavorBuilder = require('../src/index');
8-
const log = require('../src/log');
9+
import { build } from '../src/index.js';
10+
import { acquireLock, releaseLock } from '../src/lock.js';
11+
import log from '../src/log.js';
912

10-
let configs = args.config.split(',');
11-
let prom = [];
12-
for (let i = 0; i < configs.length; i++) {
13-
prom.push(flavorBuilder.build(configs[i]));
13+
let args = minimist(process.argv.slice(2));
14+
const configFiles =
15+
typeof args.config === 'string' ? args.config.split(',') : args.config;
16+
17+
const pidFile = path.join(tmpdir(), 'flavor-builder.pid');
18+
let isProcessLocked = acquireLock(pidFile);
19+
if (isProcessLocked) {
20+
throw new Error('flavor-builder already running');
21+
}
22+
23+
for (let i = 0; i < configFiles.length; i++) {
24+
await build(configFiles[i]);
1425
}
1526

16-
Promise.all(prom)
17-
.then(() => {
18-
log.info('done build');
19-
})
20-
.catch((e) => {
21-
console.error('Error building with flavor-builder', e, e.stack);
22-
process.exit(1);
23-
});
27+
await releaseLock(pidFile);
28+
29+
log.info('done build');

compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
httpd:
3+
build:
4+
dockerfile: ./apache.Dockerfile
5+
volumes:
6+
- ./build/${SERVE_DIR-cheminfo}/out:/usr/local/apache2/htdocs
7+
ports:
8+
- 6060:80

0 commit comments

Comments
 (0)