Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EAK-552] CI: automatic npm version update based on current maven version #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions docs/website/.lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Versions of pom and package.json should be in sync
"../../pom.xml":
- "npm run sync-version"
17 changes: 17 additions & 0 deletions docs/website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion docs/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions docs/website/sync-version.js
Original file line number Diff line number Diff line change
@@ -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>(.*?)<\/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');
})();
3 changes: 3 additions & 0 deletions ui.apps/.lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Versions of pom and package.json should be in sync
"../pom.xml":
- "npm run sync-version"
23 changes: 23 additions & 0 deletions ui.apps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ui.apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions ui.apps/sync-version.js
Original file line number Diff line number Diff line change
@@ -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>(.*?)<\/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');
})();