From 82c07d55ea6b8077d92e0304000cc857e3f02417 Mon Sep 17 00:00:00 2001 From: Vegard Bakke Date: Sat, 17 Jan 2026 17:40:40 +0100 Subject: [PATCH 1/2] Copy README from root to assets when newer --- package.json | 1 + scripts/copy-readme.js | 80 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 scripts/copy-readme.js diff --git a/package.json b/package.json index 990bccdb..284f24a8 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "scripts": { "ng": "ng", "start": "ng serve", + "prebuild": "node scripts/copy-readme.js", "build": "ng build --configuration=production" , "watch": "ng build --watch --configuration development", "test": "ng test", diff --git a/scripts/copy-readme.js b/scripts/copy-readme.js new file mode 100644 index 00000000..958bf84a --- /dev/null +++ b/scripts/copy-readme.js @@ -0,0 +1,80 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); + +// Comment to add at the beginning of the copied readme file +const comment = ` + +`; + + +const sourceFile = path.join(__dirname, '..', 'README.md'); +const targetDir = path.join(__dirname, '..', 'src/assets/Markdown Files'); +const targetFile = path.join(targetDir, 'README.md'); + +try { + // Ensure target directory exists + if (!fs.existsSync(targetDir)) { + fs.mkdirSync(targetDir, { recursive: true }); + } + + // Warn the programmer if readme copy is newer than source + let copyNeeded = true; + const sourceStats = fs.statSync(sourceFile); + if (fs.existsSync(targetFile)) { + const targetStats = fs.statSync(targetFile); + + if (targetStats.mtimeMs == sourceStats.mtimeMs) { + copyNeeded = false; + } + if (targetStats.mtimeMs > sourceStats.mtimeMs) { + console.warn('==============================================================='); + console.warn('⚠️ WARNING: Did you edit the README.md copy under `assets`?'); + console.warn('The assets readme gets overwritten during the build process.'); + console.warn('Edit the main README.md in root folder to avoid losing changes.'); + console.warn('==============================================================='); + fs.copyFileSync(targetFile, targetFile + '.bak'); + console.warn('Made you a backup, though: ' + targetFile + '.bak'); + } + } + + if (copyNeeded) { + // Read the source README + const readmeContent = fs.readFileSync(sourceFile, 'utf8'); + const nl = getLineBreakChar(readmeContent); + + // Write to target with comment prepended + fs.writeFileSync(targetFile, setLineBreak(comment, nl) + readmeContent, 'utf8'); + fs.utimesSync(targetFile, sourceStats.atime, sourceStats.mtime); + + console.log('✔ Copied README.md to src/assets/Markdown Files/'); + } +} catch (error) { + console.error('Error copying README.md to assets:', error); + process.exit(1); +} + + +function setLineBreak(input, nl) { + return input.replace(/\r\n|\r|\n/g, nl); +} + +function getLineBreakChar(string) { + const indexOfLF = string.indexOf('\n', 1) // No need to check first-character + + if (indexOfLF === -1) { + if (string.indexOf('\r') !== -1) return '\r' + + return '\n' + } + + if (string[indexOfLF - 1] === '\r') return '\r\n' + + return '\n' +} From 71a23e658b963e2dfbd8ab16980fad9e13715527 Mon Sep 17 00:00:00 2001 From: Vegard Bakke Date: Sat, 17 Jan 2026 18:41:29 +0100 Subject: [PATCH 2/2] Add suggested improvement to ESLint command --- .github/workflows/ESLint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ESLint.yml b/.github/workflows/ESLint.yml index bd98cae2..756dc10f 100644 --- a/.github/workflows/ESLint.yml +++ b/.github/workflows/ESLint.yml @@ -8,4 +8,4 @@ jobs: - name: Install modules run: yarn - name: Run ESLint - run: yarn run eslint . --ext .js,.jsx,.ts,.tsx + run: yarn run lint