diff --git a/build.js b/build.mjs similarity index 82% rename from build.js rename to build.mjs index 2e414b3..0001223 100644 --- a/build.js +++ b/build.mjs @@ -1,10 +1,12 @@ -const replace = require('replace-in-file'); -const crypto = require('crypto'); -const pkg = require('./package.json'); -const pkgLock = require('./package-lock.json'); +import {replaceInFile} from 'replace-in-file' +import crypto from 'crypto'; +import { readFile } from 'fs/promises'; -simplifyVersion = version => version.replace(/^[=<>~^]/g, ''); -majorMinorVersion = version => version.split('.').slice(0, -1).join('.'); +const pkg = JSON.parse(await readFile(new URL('./package.json', import.meta.url))); +const pkgLock = JSON.parse(await readFile(new URL('./package-lock.json', import.meta.url))); + +const simplifyVersion = version => version.replace(/^[=<>~^]/g, ''); +const majorMinorVersion = version => version.split('.').slice(0, -1).join('.'); const urls = { 'bootstrap_js': 'https://cdn.jsdelivr.net/npm/bootstrap@' + simplifyVersion(pkgLock.packages["node_modules/bootstrap"].version) + '/dist/js/bootstrap.bundle.min.js', @@ -41,6 +43,6 @@ async function calculateSris(urls) { to: [majorMinorVersion(process.env.npm_package_version), process.env.INLINE_CSS, process.env.INLINE_JS, ...Object.values(urls), ...sris], countMatches: true, }; -})().then(options => replace(options) +})().then(options => replaceInFile(options) .then(results => results.every(result => (! result.hasChanged || result.numReplacements !== options.from.length) && (() => { throw new Error('error during build: no replacements done in file ' + result.file) })())) ); \ No newline at end of file diff --git a/package.json b/package.json index 9b1af06..7e32ffa 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "moneymoney-sankey", "description": "An extension for the great MoneyMoney app to export an interactive HTML Sankey Chart based on the transaction categories", "version": "1.2.0", + "private": true, "dependencies": { "bootstrap": "^5.3.2", "highcharts": "^11.4.3" @@ -19,7 +20,7 @@ "scripts": { "build:css": "cleancss src/*.css", "build:js": "tsc && terser --compress --mangle -- $npm_package_config_outputDir/*.js", - "build": "mkdir -p $npm_package_config_outputDir && cp src/SankeyChart.lua $npm_package_config_outputDir && INLINE_CSS=`npm run build:css --silent` INLINE_JS=`npm run build:js --silent` node ./build.js", + "build": "mkdir -p $npm_package_config_outputDir && cp src/SankeyChart.lua $npm_package_config_outputDir && INLINE_CSS=`npm run build:css --silent` INLINE_JS=`npm run build:js --silent` node ./build.mjs", "test": "npm-run-all test:*", "test:compile-validate": "lua ./src/SankeyChartTest.lua | html-validate --stdin", "test:placeholder": "grep -qE '{{ ([a-zA-Z_]+) }}' $npm_package_config_outputDir/*.lua && (echo 'error: placeholders have not been replaced in dist!' && exit 1) || exit 0"