Skip to content
Open
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build/unpacked/
build/unpacked-tests/
build/ts/
build/ts-native/
Expand Down
74 changes: 55 additions & 19 deletions build/create-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SaxonJS from 'saxon-js';
import AdmZip from 'adm-zip';
import fetch from 'node-fetch';
import * as path from 'path';
import replaceInFiles from 'replace-in-files';
import fs from 'fs-extra';

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement of 'replace-in-files' with 'fs-extra' is a significant dependency change that should be documented in the package.json or migration notes. This change affects how file operations are performed throughout the build process.

Copilot uses AI. Check for mistakes.

// create json XSLT from xml XSLT:
// xslt3 -xsl:build/transform.xsl -export:build/transform.sef.json -t -ns:##html5
Expand All @@ -11,6 +11,16 @@ const testVersion = '2023.1.0';
const download = 'https://repo1.maven.org/maven2/info/kuechler/bmf/taxapi/taxxmls/' + testVersion + '/taxxmls-' + testVersion + '.jar';
const unpackFolder = "build/unpacked";
const tsFolder = "build/ts";
const extraXmlSources = [
{
url: 'https://www.bmf-steuerrechner.de/javax.faces.resource/daten/xmls/Lohnsteuer2026.xml.xhtml',
target: 'Lohnsteuer2026Big.xml'
},
{
url: 'https://www.bmf-steuerrechner.de/javax.faces.resource/daten/xmls/Lohnsteuer2025.xml.xhtml',
target: 'Lohnsteuer2025Big.xml'
}
];

fetch(download).then(res => res.arrayBuffer())
.then(arrayBuffer => Buffer.from(arrayBuffer))
Expand All @@ -28,27 +38,53 @@ fetch(download).then(res => res.arrayBuffer())
resolve(found);
})
}).then(xmlFileNames => {
return new Promise(function (resolve, _reject) {
var found = [];
return new Promise(function (resolve, reject) {
const dirPath = path.join(path.resolve(path.dirname('.')), unpackFolder);
xmlFileNames.forEach(function (xmlFileName) {
//
if (xmlFileName == 'Lohnsteuer2023JanuarBig.xml') {
console.log("replace: " + xmlFileName);
const options = {
files: dirPath + '/' + xmlFileName,
from: /Lohnsteuer2023Big/g,
to: 'Lohnsteuer2023JanuarBig',
};
found.push(replaceInFiles(options));
}else {
found.push(Promise.resolve(xmlFileName));
}
});
Promise.all(found).then(_results => {
const xmlFileName = 'Lohnsteuer2023JanuarBig.xml';
if (!xmlFileNames.includes(xmlFileName)) {
resolve(xmlFileNames);
return;
}
console.log('replace: ' + xmlFileName);
const xmlPath = path.join(dirPath, xmlFileName);
fs.readFile(xmlPath, 'utf8')
.then(content => {
const updated = content.replace(/Lohnsteuer2023Big/g, 'Lohnsteuer2023JanuarBig');
if (updated === content) {
return;
}
return fs.writeFile(xmlPath, updated, 'utf8');
})
Comment on lines +43 to +57

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactored code no longer handles multiple file replacements as the original code did with forEach. If additional files need similar name replacements in the future, this single-file approach will require modification. Consider documenting this limitation or making the replacement logic more generic.

Suggested change
const xmlFileName = 'Lohnsteuer2023JanuarBig.xml';
if (!xmlFileNames.includes(xmlFileName)) {
resolve(xmlFileNames);
return;
}
console.log('replace: ' + xmlFileName);
const xmlPath = path.join(dirPath, xmlFileName);
fs.readFile(xmlPath, 'utf8')
.then(content => {
const updated = content.replace(/Lohnsteuer2023Big/g, 'Lohnsteuer2023JanuarBig');
if (updated === content) {
return;
}
return fs.writeFile(xmlPath, updated, 'utf8');
})
// Define replacement rules: { fileName, searchValue, replaceValue }
const replacementRules = [
{
fileName: 'Lohnsteuer2023JanuarBig.xml',
searchValue: /Lohnsteuer2023Big/g,
replaceValue: 'Lohnsteuer2023JanuarBig'
}
// Add more rules here as needed
];
// Filter rules to only those files that exist in xmlFileNames
const applicableRules = replacementRules.filter(rule => xmlFileNames.includes(rule.fileName));
if (applicableRules.length === 0) {
resolve(xmlFileNames);
return;
}
// Apply all replacements in parallel
Promise.all(applicableRules.map(rule => {
console.log('replace: ' + rule.fileName);
const xmlPath = path.join(dirPath, rule.fileName);
return fs.readFile(xmlPath, 'utf8')
.then(content => {
const updated = content.replace(rule.searchValue, rule.replaceValue);
if (updated === content) {
return;
}
return fs.writeFile(xmlPath, updated, 'utf8');
});
}))

Copilot uses AI. Check for mistakes.
.then(() => resolve(xmlFileNames))
.catch(err => reject(err));
});
}).then(xmlFileNames => {
const dirPath = path.join(path.resolve(path.dirname('.')), unpackFolder);
const downloads = extraXmlSources.map(source => {
const targetPath = path.join(dirPath, source.target);
if (fs.existsSync(targetPath)) {
console.log('skip download (exists) ' + source.target);
if (!xmlFileNames.includes(source.target)) {
xmlFileNames.push(source.target);
}
return Promise.resolve();
}
return fetch(source.url).then(res => {
if (!res.ok) {
throw new Error('Failed to download ' + source.url + ' (' + res.status + ' ' + res.statusText + ')');
}
return res.text();
}).then(content => fs.outputFile(targetPath, content)).then(() => {
console.log('download ' + source.target + ' from ' + source.url);
if (!xmlFileNames.includes(source.target)) {
xmlFileNames.push(source.target);
}
});
})
});
if (downloads.length === 0) {
return xmlFileNames;
}
return Promise.all(downloads).then(() => xmlFileNames);
}).then(xmlFileNames => {
const dirPath = path.join(path.resolve(path.dirname('.')), tsFolder);
console.log("outdir: " + dirPath);
Expand Down
3 changes: 3 additions & 0 deletions build/ts-for-native-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ try {
from: /.*import.*;.*/g,
to: ' ',
}).pipe({ from: /.*export class/, to: 'class' })
// allow access from helper methods / other generated files
.pipe({ from: /private\s+static\s+readonly\s+(_[a-zA-Z]+)/g, to: 'public static readonly $1' })
.pipe({ from: /private\s+static\s+readonly\s+typeDirectory/g, to: 'public static readonly typeDirectory' })
//.pipe({ from: /(Lohnsteuer[a-zA-Z0-9]+Big)/g, to: "$1Js"});

console.log('Count of matches by paths: ', countOfMatchesByPaths);
Expand Down
Loading