diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 000000000..7c2be23aa --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,13 @@ + +# Check if node & npm are installed +if ! command -v node &> /dev/null; then + echo "Node is not installed. Lint Staged checks will be skipped." + exit 0 +fi + +# Run Lint Staged Checks +cd ui.apps +npx lint-staged --verbose + +cd ../docs/website +npx lint-staged --verbose diff --git a/docs/website/.lintstagedrc.yml b/docs/website/.lintstagedrc.yml new file mode 100644 index 000000000..35a3395ef --- /dev/null +++ b/docs/website/.lintstagedrc.yml @@ -0,0 +1,3 @@ +# Versions of pom and package.json should be in sync +"../../pom.xml": + - "npm run sync-version" diff --git a/docs/website/package-lock.json b/docs/website/package-lock.json index 575cc02d3..13059d7aa 100644 --- a/docs/website/package-lock.json +++ b/docs/website/package-lock.json @@ -32,6 +32,7 @@ "foreach-cli": "^1.8.1", "glob": "^11.0.1", "html-minifier-terser": "^7.2.0", + "husky": "^9.1.7", "js-yaml": "^4.1.0", "jsdom": "^26.0.0", "kleur": "^4.1.5", @@ -5684,6 +5685,22 @@ "node": ">= 14" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", diff --git a/docs/website/package.json b/docs/website/package.json index a57e83369..f427babd5 100644 --- a/docs/website/package.json +++ b/docs/website/package.json @@ -17,7 +17,9 @@ "watch:ts": "webpack --watch", "lint": "concurrently \"npm:lint:js\" \"npm:lint:css\"", "lint:js": "eslint \"src/**/*.{ts,js}\" --max-warnings 3", - "lint:css": "stylelint \"src/**/*.less\"" + "lint:css": "stylelint \"src/**/*.less\"", + "sync-version": "node sync-version.js", + "prepare": "cd ../.. && husky" }, "keywords": [], "author": "", @@ -46,6 +48,7 @@ "foreach-cli": "^1.8.1", "glob": "^11.0.1", "html-minifier-terser": "^7.2.0", + "husky": "^9.1.7", "js-yaml": "^4.1.0", "jsdom": "^26.0.0", "kleur": "^4.1.5", diff --git a/docs/website/sync-version.js b/docs/website/sync-version.js new file mode 100644 index 000000000..c51afa72e --- /dev/null +++ b/docs/website/sync-version.js @@ -0,0 +1,31 @@ +/** + * Keep the version of the package.json file in sync with the version of the pom.xml file. + */ +const { promisify } = require('util'); +const fs = require('fs').promises; +const exec = promisify(require('child_process').exec); + +const toSemver = (version) => { + const [major, minor, patch, post] = version.split('.'); + if (post) { + const [pre, build] = post.split('-'); + return `${major}.${minor}.${patch}-${build || 'RELEASE'}.${pre}`; + } + return `${major}.${minor}.${patch}`; +}; + +(async() => { + console.log('Checking pom.xml version...'); + const rootPom = await fs.readFile('../../pom.xml', 'utf-8'); + const rootPomVersion = rootPom.match(/(.*?)<\/version>/)[1]; + const pomVersion = toSemver(rootPomVersion.trim()); + + console.log('Pom version resolved:', pomVersion); + const { version } = require('./package.json'); + + if (version === pomVersion) return; + console.info(`Updating package.json version to ${pomVersion}`); + + await exec(`npm version ${pomVersion} --no-git-tag-version`); + await exec('git add package.json package-lock.json'); +})(); diff --git a/ui.apps/.lintstagedrc.yml b/ui.apps/.lintstagedrc.yml new file mode 100644 index 000000000..b474074e3 --- /dev/null +++ b/ui.apps/.lintstagedrc.yml @@ -0,0 +1,3 @@ +# Versions of pom and package.json should be in sync +"../pom.xml": + - "npm run sync-version" diff --git a/ui.apps/package-lock.json b/ui.apps/package-lock.json index 682fc20be..d87385b55 100644 --- a/ui.apps/package-lock.json +++ b/ui.apps/package-lock.json @@ -10,6 +10,7 @@ "license": "Apache-2.0", "devDependencies": { "eslint": "^9.19.0", + "husky": "^9.1.7", "neostandard": "^0.12.0" } }, @@ -2139,6 +2140,22 @@ "node": ">= 0.4" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -5343,6 +5360,12 @@ "function-bind": "^1.1.2" } }, + "husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true + }, "ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", diff --git a/ui.apps/package.json b/ui.apps/package.json index d4ed77523..bece58be1 100644 --- a/ui.apps/package.json +++ b/ui.apps/package.json @@ -5,13 +5,16 @@ "private": true, "devDependencies": { "eslint": "^9.19.0", + "husky": "^9.1.7", "neostandard": "^0.12.0" }, "directories": { "doc": "src/main/content/jcr_root/apps/etoolbox-authoring-kit/depends-on/docs" }, "scripts": { - "lint": "eslint \"src/main/content/jcr_root/apps/**/*.js\"" + "lint": "eslint \"src/main/content/jcr_root/apps/**/*.js\"", + "sync-version": "node sync-version.js", + "prepare": "cd .. && husky" }, "license": "Apache-2.0", "repository": "https://github.com/exadel-inc/etoolbox-authoring-kit/tree/master/ui.apps/src/main/content/jcr_root/apps/etoolbox-authoring-kit/depends-on" diff --git a/ui.apps/sync-version.js b/ui.apps/sync-version.js new file mode 100644 index 000000000..096451b1a --- /dev/null +++ b/ui.apps/sync-version.js @@ -0,0 +1,31 @@ +/** + * Keep the version of the package.json file in sync with the version of the pom.xml file. + */ +const { promisify } = require('util'); +const fs = require('fs').promises; +const exec = promisify(require('child_process').exec); + +const toSemver = (version) => { + const [major, minor, patch, post] = version.split('.'); + if (post) { + const [pre, build] = post.split('-'); + return `${major}.${minor}.${patch}-${build || 'RELEASE'}.${pre}`; + } + return `${major}.${minor}.${patch}`; +}; + +(async() => { + console.log('Checking pom.xml version...'); + const rootPom = await fs.readFile('../pom.xml', 'utf-8'); + const rootPomVersion = rootPom.match(/(.*?)<\/version>/)[1]; + const pomVersion = toSemver(rootPomVersion.trim()); + + console.log('Pom version resolved:', pomVersion); + const { version } = require('./package.json'); + + if (version === pomVersion) return; + console.info(`Updating package.json version to ${pomVersion}`); + + await exec(`npm version ${pomVersion} --no-git-tag-version`); + await exec('git add package.json package-lock.json'); +})();