-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to esbuild and update npm packages (#1605)
The assets build script instead precompiles the Handlebars templates. https://handlebarsjs.com/installation/precompilation.html The HTML formatter's digest function has been updated to produce 8- character uppercase hashes in order to match those generated by esbuild. The ESLint config was re-initiated and now uses its default parser (Espree), so Babel is no longer required. For the Elixir-based tests to result in up-to-date build dist contents I found I had to empty the _build directory.
- Loading branch information
1 parent
eb463ec
commit 7d400e5
Showing
61 changed files
with
5,717 additions
and
23,058 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ jobs: | |
otp: 24 | ||
lint: lint | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: erlef/setup-beam@v1 | ||
with: | ||
|
@@ -59,17 +59,14 @@ jobs: | |
name: Check JS | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Set up Node.js 10.x | ||
uses: actions/[email protected] | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 10.10.0 | ||
node-version: 16 | ||
- run: npm install --prefix assets | ||
- run: npm run --prefix assets lint | ||
|
||
- run: sudo apt-get install xvfb | ||
- name: npm install, build, and test | ||
run: | | ||
- run: | | ||
xvfb-run --auto-servernum npm run --prefix assets test | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true | ||
}, | ||
extends: 'standard', | ||
overrides: [ | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module' | ||
}, | ||
rules: { | ||
'no-path-concat': 0, | ||
'no-throw-literal': 0, | ||
'no-useless-escape': 0, | ||
'object-curly-spacing': 0 | ||
}, | ||
globals: { | ||
'Handlebars': 'readonly' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
const path = require('node:path') | ||
const esbuild = require('esbuild') | ||
const util = require('./utilities') | ||
|
||
|
||
/** | ||
* Configuration variables | ||
*/ | ||
|
||
// Build options | ||
const commonOptions = { | ||
entryNames: '[name]-[hash]', | ||
bundle: true, | ||
minify: true, | ||
logLevel: 'info', | ||
} | ||
const epubOptions = { | ||
outdir: path.resolve('../formatters/epub/dist'), | ||
} | ||
const htmlOptions = { | ||
outdir: path.resolve('../formatters/html/dist'), | ||
} | ||
|
||
// Handlebars template paths | ||
const templates = { | ||
sourceDir: path.resolve('js/handlebars/templates'), | ||
compiledDir: path.resolve('../tmp/handlebars'), | ||
filename: 'handlebars.templates.js', | ||
} | ||
templates.compiledPath = path.join(templates.compiledDir, templates.filename) | ||
|
||
// Directories to create/clean | ||
const cleanDirs = { | ||
pre: [ | ||
epubOptions.outdir, | ||
htmlOptions.outdir, | ||
templates.compiledDir, | ||
], | ||
postHtml: [ | ||
templates.compiledDir, | ||
], | ||
} | ||
|
||
|
||
/** | ||
* Clean: pre-build | ||
*/ | ||
|
||
util.ensureEmptyDirsExistSync(cleanDirs.pre) | ||
|
||
|
||
/** | ||
* Build: ePub | ||
*/ | ||
|
||
const epubBuild = esbuild.build({ | ||
...commonOptions, | ||
...epubOptions, | ||
entryPoints: [ | ||
'js/entry/epub.js', | ||
'css/entry/epub-elixir.css', | ||
'css/entry/epub-erlang.css', | ||
], | ||
}).catch(() => process.exit(1)) | ||
|
||
|
||
/** | ||
* Build: HTML | ||
*/ | ||
|
||
// Precompile Handlebars templates | ||
util.runShellCmdSync(`npx handlebars ${templates.sourceDir} --output ${templates.compiledPath}`) | ||
|
||
// esbuild | ||
const htmlBuild = esbuild.build({ | ||
...commonOptions, | ||
...htmlOptions, | ||
entryPoints: [ | ||
templates.compiledPath, | ||
'js/entry/html.js', | ||
'css/entry/html-elixir.css', | ||
'css/entry/html-erlang.css', | ||
], | ||
loader: { | ||
'.woff2': 'file', | ||
}, | ||
}).catch(() => process.exit(1)) | ||
|
||
// The Handlebars runtime from the local module dist directory is used to ensure | ||
// the version matches that which was used to compile the templates. | ||
// 'bundle' must be false in order for 'Handlebar' to be available at runtime. | ||
esbuild.build({ | ||
...commonOptions, | ||
...htmlOptions, | ||
entryPoints: ['node_modules/handlebars/dist/handlebars.runtime.js'], | ||
bundle: false, | ||
}).catch(() => process.exit(1)) | ||
|
||
|
||
/** | ||
* Clean: post-build | ||
*/ | ||
Promise.all([epubBuild, htmlBuild]).then(() => { | ||
util.ensureEmptyDirsExistSync(cleanDirs.postHtml) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const child_process = require('node:child_process') | ||
const fs = require('fs-extra') | ||
|
||
module.exports.runShellCmdSync = (command) => { | ||
child_process.execSync(command, (err, stdout, stderr) => { | ||
if (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} else { | ||
if (stdout) { console.log('\n' + stdout) } | ||
if (stderr) { console.log('\n' + stderr) } | ||
return | ||
} | ||
}) | ||
} | ||
|
||
module.exports.ensureEmptyDirsExistSync = (dirs) => { | ||
dirs.forEach(dir => { | ||
fs.emptyDirSync(dir) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.