Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create a script to build help #223

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`;
}
Loading