Skip to content

Commit

Permalink
switched to esm modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ma4nn committed Jun 25, 2024
1 parent 08e7709 commit 47cca81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions build.js → build.mjs
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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) })()))
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 47cca81

Please sign in to comment.