Skip to content

Commit

Permalink
feat: create a script to build help (#223)
Browse files Browse the repository at this point in the history
* feat: create a script to build help

* chore: use native base64

* chore: fix eslint

* chore: fix prettier in build_help

* chore: add help.html in prettier ignore
  • Loading branch information
lpatiny authored Aug 21, 2024
1 parent e624e76 commit cc7042f
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 8 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/lib/canvas_editor/cursors_24px.js
/openchemlib
/war
/help.html
14 changes: 13 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default [
},
},
{
files: ['scripts/**'],
files: ['scripts/**/*.js'],
languageOptions: {
globals: {
...globals.node,
Expand All @@ -65,6 +65,18 @@ export default [
'unicorn/no-process-exit': 'off',
},
},
{
files: ['scripts/**/*.mjs'],
languageOptions: {
globals: {
...globals.node,
},
sourceType: 'module',
},
rules: {
'unicorn/no-process-exit': 'off',
},
},
{
files: ['tests/**'],
rules: {
Expand Down
327 changes: 327 additions & 0 deletions help.html

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"build-esm-bundle-export": "npm run build-esm-bundle && node scripts/build_esm_bundle_types.js",
"build-esm-bundle-types": "node scripts/esm_bundle_types.js",
"build-esm-bundle-watch": "npm run build-esm-bundle -- --watch",
"build-help": "node scripts/build_help.mjs",
"build-full-pretty": "npm run build:pretty -- -m full",
"build-minimal": "npm run build:min -- -m minimal",
"eslint": "eslint .",
Expand Down Expand Up @@ -77,6 +78,7 @@
"homepage": "https://github.com/cheminfo/openchemlib-js",
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^22.0.0",
"autoprefixer": "^10.4.19",
"benchmark": "^2.1.4",
"esbuild": "^0.23.0",
Expand Down
37 changes: 37 additions & 0 deletions scripts/build_help.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable no-await-in-loop */
import { readdir, readFile, writeFile } from 'node:fs/promises';

const homedir = new URL(
'../openchemlib/src/main/resources/html/',
import.meta.url,
);

// loading the images
const pngNames = await readdir(new URL('editor', homedir)).then((files) =>
files.filter((file) => file.endsWith('.png')),
);
const images = {};
for (const pngName of pngNames) {
const blob = await readFile(new URL(`editor/${pngName}`, homedir), 'base64');
const encoded = toBase64URL(blob, 'image/png');
images[pngName] = encoded;
}

// loading the html file
let html = await readFile(new URL('editor/editor.html', homedir), 'utf8');
for (const [pngName, encoded] of Object.entries(images)) {
html = html.replaceAll(`src="${pngName}"`, `src="${encoded}"`);
}

// loading css
let css = await readFile(new URL('styles.css', homedir), 'utf8');
html = html.replace(
'<link type="text/css" href="../styles.css" rel="stylesheet">',
`<style>${css}</style>`,
);

await writeFile(new URL('../help.html', import.meta.url), html);

function toBase64URL(base64, type) {
return `data:${type};base64,${base64}`;
}

0 comments on commit cc7042f

Please sign in to comment.