diff --git a/check-content-version.ts b/check-content-version.ts new file mode 100644 index 000000000..f2d0a3f23 --- /dev/null +++ b/check-content-version.ts @@ -0,0 +1,50 @@ +import { exec } from 'child_process'; + +// This is a script that checks if the fundraising-frontend-content package has a never version +// than the one currently installed. This is useful to check if the content has been updated +// in the remote repository and the package-lock.json file needs to be updated. +// Run this before builing the banners + +const CONTENT_REPO_URL = 'github.com/wmde/fundraising-frontend-content.git'; +const CONTENT_REPO_BRANCH = 'production'; + +async function execShellCommand( cmd: string ): Promise { + return new Promise( ( resolve, reject ) => { + // eslint-disable-next-line security/detect-child-process + exec( cmd, ( error, stdout, stderr ) => { + if ( error ) { + console.error( stderr ); + reject( error ); + } + resolve( stdout ); + } ); + } ); +} + +async function getCommitIdFromPackageLock(): Promise { + const output = await execShellCommand( 'npm list --package-lock-only' ); + const commitId = output.match( new RegExp( `${CONTENT_REPO_URL}#([0-9a-f]+)` ) ); + if ( !commitId || !commitId[ 1 ] ) { + throw new Error( 'Could not determine commit id for content from package-lock.json' ); + } + return commitId[ 1 ]; +} + +async function getCommitIdFromRemoteRepo(): Promise { + const output = await execShellCommand( `git ls-remote --heads https://${CONTENT_REPO_URL}` ); + const commitId = output.match( new RegExp( `([0-9a-f]+)\\s+refs/heads/${CONTENT_REPO_BRANCH}` ) ); + if ( !commitId || !commitId[ 1 ] ) { + throw new Error( 'Could not determine commit it for content from remote repository' ); + } + return commitId[ 1 ]; +} + +Promise.all( [ getCommitIdFromPackageLock(), getCommitIdFromRemoteRepo() ] ).then( ( [ localCommitId, remoteCommitId ] ) => { + if ( localCommitId !== remoteCommitId ) { + console.log( + `Content version mismatch, local version is ${localCommitId}, remote is ${remoteCommitId}. + Please run "npm run update-content" to update the package-lock.json file.`.replace( /\n\s+/g, '\n' ) + ); + process.exit( 1 ); + } +} ); diff --git a/package-lock.json b/package-lock.json index 2ff3b4a7a..c636ff16e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,6 +46,7 @@ "stylelint-webpack-plugin": "^4.1.1", "toml": "^3.0.0", "ts-loader": "^9.5.0", + "ts-node": "^10.9.1", "typescript": "^5.2.2", "vitest": "^0.34.6", "vue-loader": "^17.3.0", @@ -218,6 +219,28 @@ "node": ">=0.1.90" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@csstools/css-parser-algorithms": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.3.1.tgz", @@ -1254,6 +1277,30 @@ "node": ">= 10" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, "node_modules/@tufjs/canonical-json": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-1.0.0.tgz", @@ -2583,6 +2630,12 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -3768,6 +3821,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -4174,6 +4233,15 @@ "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==", "dev": true }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -6035,8 +6103,7 @@ }, "node_modules/fundraising-frontend-content": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/wmde/fundraising-frontend-content.git#3bfba7ed35f1374cce95113681ee380e6f866aa8", - "integrity": "sha512-YkO5rRIwQ0M7LyG8uJ23MetUXU7XE1FcXAZLS4ATfE8fJFjZUTOxg3zFQE5Qcz6Oc2Pq/D6hewvv//tbD449QA==", + "resolved": "git+ssh://git@github.com/wmde/fundraising-frontend-content.git#a354fdbd5f2d53c117536cfeda244efc6c26e38c", "license": "CC0-1.0" }, "node_modules/gauge": { @@ -7954,6 +8021,12 @@ "semver": "bin/semver.js" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "node_modules/make-fetch-happen": { "version": "11.1.1", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-11.1.1.tgz", @@ -12859,6 +12932,49 @@ "node": ">= 8" } }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, "node_modules/tuf-js": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/tuf-js/-/tuf-js-1.1.7.tgz", @@ -13184,6 +13300,12 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, "node_modules/v8-to-istanbul": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.0.tgz", @@ -14282,6 +14404,15 @@ "node": ">=10" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 38cafae08..a6bab5085 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test": "npm-run-all test:*", "test:unit": "vitest --run", "watch": "webpack --watch", - "build": "webpack --config webpack.production.js", + "build": "npm-run-all -s check-content-version build:banners", + "build:banners": "webpack --config webpack.production.js", "start": "npm run dev", "dev": "nodemon", "clean": "rimraf dist/*.js dist/*.wikitext dist/*.map", @@ -17,6 +18,7 @@ "lint:ts": "vue-tsc --noEmit", "lint:css": "stylelint '**/*.{scss,vue}'", "ci": "npm-run-all lint test", + "check-content-version": "ts-node check-content-version.ts", "coverage": "vitest run --coverage", "update-content": "npm update fundraising-frontend-content" }, @@ -62,6 +64,7 @@ "stylelint-webpack-plugin": "^4.1.1", "toml": "^3.0.0", "ts-loader": "^9.5.0", + "ts-node": "^10.9.1", "typescript": "^5.2.2", "vitest": "^0.34.6", "vue-loader": "^17.3.0",