Merge remote-tracking branch 'web-template/template' into develop

This commit is contained in:
SArpnt 2024-08-09 15:07:21 -04:00
commit b0c7956b72
Signed by: SArpnt
SSH key fingerprint: SHA256:iDMeic8KkqqEsN4wODlgsk1d/oW1ojZ/cu/MEWyfLBw
4 changed files with 93 additions and 112 deletions

56
biome.jsonc Normal file
View file

@ -0,0 +1,56 @@
{
"files": {
"ignore": [
"pnpm-lock.yaml",
"package.json5",
"assets/",
// https://github.com/prettier/prettier/issues/5019
"*.md",
],
},
"vcs": {
"enabled": true,
"clientKind": "git",
},
"linter": {
"rules": {
"style": {
"useBlockStatements": "warn",
"noCommaOperator": "off",
"noNonNullAssertion": "off",
"useNumberNamespace": "off",
},
"complexity": {
"noForEach": "off",
"useLiteralKeys": "off",
},
"performance": {
"noDelete": "off",
},
},
},
"formatter": {
"indentWidth": 4,
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
// TODO prevent if/for/while without braces
},
},
"css": {
"formatter": {
"enabled": false,
},
},
"overrides": [
{
"include": ["*.jsonc"],
"json": {
"formatter": {
"trailingCommas": "all",
},
},
},
],
}

View file

@ -1,125 +1,49 @@
const esbuild = require("esbuild");
//const XXHash = require("xxhash");
const htmlmin = require("html-minifier");
//const npath = require("path");
//const afs = require("fs/promises");
//const minimatch = require("minimatch");
const input = "src";
const output = "_site";
const serve = process.env.ELEVENTY_RUN_MODE === "serve";
// TODO minify css and js in html
//function getHash(f) {
// XXHash.hash(f, 0xe0b52cfa, "base64").replaceAll("=", "");
//}
module.exports = eleventyConfig => {
eleventyConfig.on("eleventy.after", async ({ dir, results, runMode, outputMode }) => {
await Promise.all([
esbuild.build({
entryPoints: [`src/style.css`, `src/interface.ts`, `src/embed.ts`],
outdir: output,
format: "esm",
bundle: true,
splitting: true,
minify: !serve,
sourcemap: true,
//write: serve,
}),
esbuild.build({
entryPoints: [`src/audio-worklet/audio-worklet.ts`],
outdir: output,
format: "esm",
bundle: true,
splitting: false,
minify: !serve,
sourcemap: true,
//write: serve,
}),
]);
eleventyConfig.setLayoutResolution(false);
// proper cachebusting is difficult not doing it right now
//if (!serve) {
// async function getHashOfFile(assetPath, content) {
// console.log(`hashing ${assetPath}`);
// assetPaths.push({
// assetPath: assetPath.replace(dir.output, ""),
// assetHash: getHash(content ?? (await afs.readFile(assetPath))),
// });
// }
eleventyConfig.on(
"eleventy.after",
async ({ dir, results, runMode, outputMode }) => {
await Promise.all([
esbuild.build({
entryPoints: [`src/style.css`, `src/interface.ts`, `src/embed.ts`],
outdir: output,
format: "esm",
bundle: true,
splitting: true,
minify: !serve,
sourcemap: true,
//write: serve,
}),
esbuild.build({
entryPoints: [`src/audio-worklet/audio-worklet.ts`],
outdir: output,
format: "esm",
bundle: true,
splitting: false,
minify: !serve,
sourcemap: true,
//write: serve,
}),
]);
},
);
// const globs = [
// `!${dir.output}/library/**`,
// `${dir.output}/**/*.{css,js,png,jpg,jpeg,gif,mp4,ico}`,
// ].map(g => new minimatch.Minimatch(g));
// const assetPaths = [];
// (await Promise.all(await afs.readdir(dir.output, {}))).forEach(relpath => {
// const path = npath.join(dir.output, relpath);
// if (globs.every(mg => mg.match(path))) {
// getHashOfFile(path);
// }
// });
// const esbuildFiles = [];
// esbuildResult.outputFiles.forEach(({ contents, path: apath }) => {
// const path = npath.relative("", apath);
// console.log(path);
// console.log(globs[1].match(path));
// if (globs.every(mg => mg.match(path))) {
// const string = Buffer.from(contents).toString();
// console.log(string.substring(0, 20).replace(/\n/g, "|"));
// assetPaths.push({
// assetPath: path.replace(dir.output, ""),
// assetHash: getHash(contents),
// });
// esbuildFiles.push({ contents, path });
// } else {
// afs.writeFile(path, contents);
// }
// });
// results.forEach(({ inputPath, outputPath, url, content }) => {
// let outputData = ""; // Assigned later
// let outputChanged = false; // Check if any hashes have been added
// // Read the output content
// fs.readFile(outputPath, (encoding = "UTF-8"), (err, data) => {
// if (err) {
// logRed(err);
// throw err;
// }
// // Save the output data
// outputData = data;
// assetPaths.forEach(({ assetPath, assetHash }) => {
// if (data.includes(assetPath)) {
// // TODO very error prone
// outputData = outputData.replace(assetPath, assetPath + "?v=" + assetHash);
// outputChanged = true;
// }
// });
// });
// });
// // TODO replace text in esbuild files
// // TODO write esbuild files
//}
});
eleventyConfig.addTransform("htmlmin", function (content) {
if (this.page.outputPath && this.page.outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
eleventyConfig.addTransform("minify html", function (content) {
if (this.page.outputPath?.endsWith(".html")) {
return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});

View file

@ -4,7 +4,9 @@
build: 'rm -rf _site && eleventy',
serve: 'eleventy --serve',
debug: 'DEBUG=* eleventy --serve',
test: 'tsc; jest --passWithNoTests',
test: 'tsc; biome check; jest --passWithNoTests',
fulltest: 'eleventy --dryrun && pnpm run test',
format: 'biome check --write',
},
dependencies: {
'@11ty/eleventy': '^2.0.1',
@ -20,12 +22,11 @@
'html-minifier': '^4.0.0',
},
devDependencies: {
'@prettier/plugin-pug': '^3.0.0',
'@biomejs/biome': '^1.8.3',
'@types/audioworklet': '^0.0.58',
'@types/jest': '^29.5.12',
jest: '^29.7.0',
'jest-environment-jsdom': '^29.7.0',
prettier: '^3.3.3',
'ts-essentials': '^10.0.1',
'ts-jest': '^29.2.4',
typescript: '^5.5.4',

View file

@ -9,8 +9,8 @@
"strict": true,
"exactOptionalPropertyTypes": true,
"noPropertyAccessFromIndexSignature": true,
// as far as i can tell there is no way to define a type that indicates a
// valid index for some value. this makes this pretty much impossible to use
// currently there is no type for a valid array index.
// this makes this pretty much impossible to use.
//"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,