From 323139f04060a6383db2763fa096771b37ff504a Mon Sep 17 00:00:00 2001 From: Simon Hofmann Date: Thu, 15 Feb 2024 20:54:08 +0100 Subject: [PATCH] Aligned package versions, added script to bump versions on snapshot releases --- .build/bump_version.js | 43 +++++++++++++++++++++++++ .build/pre-release.sh | 2 +- .github/workflows/snapshot_release.yaml | 24 ++++++-------- core/configs/package.json | 2 +- core/nut.js/package.json | 4 +-- core/provider-interfaces/package.json | 12 +++---- core/shared/package.json | 4 +-- examples/README.md | 4 +++ examples/jest-test/package.json | 2 +- examples/keyboard-test/package.json | 2 +- examples/mouse-test/package.json | 2 +- examples/screen-test/package.json | 2 +- examples/typescript-test/package.json | 2 +- examples/window-test/package.json | 3 +- package.json | 4 ++- providers/clipboardy/package.json | 4 +-- providers/libnut/package.json | 7 ++-- 17 files changed, 84 insertions(+), 39 deletions(-) create mode 100644 .build/bump_version.js mode change 100644 => 100755 .build/pre-release.sh create mode 100644 examples/README.md diff --git a/.build/bump_version.js b/.build/bump_version.js new file mode 100644 index 00000000..b5b42e53 --- /dev/null +++ b/.build/bump_version.js @@ -0,0 +1,43 @@ +const { exec } = require("child_process"); +const { readFile, writeFile } = require("fs"); +const { join } = require("path"); + +const args = process.argv.slice(2); +const version = args[0]; + +if (version == null || version === "") { + throw new Error("Version is required"); +} + +exec("pnpm m ls --json --depth=-1", (_, stdout) => { + const modules = JSON.parse(stdout).filter( + (module) => module.private !== true, + ); + + for (const module of modules) { + const filePath = join(module.path, "package.json"); + + readFile(filePath, "utf8", (err, data) => { + if (err) { + throw new Error(err); + } + // Parse JSON + const obj = JSON.parse(data); + + // Change a property + obj.version = version; + + // Convert object back to JSON + const json = JSON.stringify(obj, null, 2); + + // Write JSON file + writeFile(filePath, json, "utf8", (err) => { + if (err) { + throw new Error(err); + } else { + console.log("File successfully updated."); + } + }); + }); + } +}); diff --git a/.build/pre-release.sh b/.build/pre-release.sh old mode 100644 new mode 100755 index 1f515ee3..780cd47c --- a/.build/pre-release.sh +++ b/.build/pre-release.sh @@ -5,4 +5,4 @@ patchVersion=$(npm --no-git-tag version patch) nextVersion=${patchVersion}-next."$(date +%Y%m%d%H%M%S)" echo "${nextVersion:1}" -npm version --no-git-tag -f "${nextVersion:1}" \ No newline at end of file +node ./bump_version.js "${nextVersion:1}" diff --git a/.github/workflows/snapshot_release.yaml b/.github/workflows/snapshot_release.yaml index 0890f2c6..867775b8 100644 --- a/.github/workflows/snapshot_release.yaml +++ b/.github/workflows/snapshot_release.yaml @@ -29,23 +29,16 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v3.0.0 - name: Install - run: npm ci + run: pnpm i - name: Install @nut-tree/libnut@next - run: npm i @nut-tree/libnut@next + run: | + pnpm --filter @nut-tree/libnut i @nut-tree/libnut-darwin@next @nut-tree/libnut-linux@next @nut-tree/libnut-win32@next - name: Compile - run: npm run compile - - name: Init window e2e test subpackage - run: npm --prefix e2e/window-test ci + run: pnpm run compile - name: Run tests uses: GabrielBB/xvfb-action@v1 with: - run: | - npx playwright install --with-deps - npm test - - name: Run Electron e2e test subpackage - uses: GabrielBB/xvfb-action@v1 - with: - run: npm --prefix e2e/electron-test cit + run: pnpm run coverage deploy: needs: @@ -63,13 +56,14 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v3.0.0 - name: Install - run: npm ci + run: pnpm i - name: Install @nut-tree/libnut@next - run: npm i @nut-tree/libnut@next + run: | + pnpm --filter @nut-tree/libnut i @nut-tree/libnut-darwin@next @nut-tree/libnut-linux@next @nut-tree/libnut-win32@next - name: Create snapshot release run: bash ./.build/pre-release.sh - name: Publish snapshot release to npm - run: npm run publish-next + run: pnpm run publish:next env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - uses: actions/setup-node@v3 diff --git a/core/configs/package.json b/core/configs/package.json index 5142018d..2a877f91 100644 --- a/core/configs/package.json +++ b/core/configs/package.json @@ -1,7 +1,7 @@ { "name": "@nut-tree/configs", "private": true, - "version": "1.0.0", + "version": "4.0.0", "description": "Shared configs for nut.js", "author": { "name": "dry Software UG (haftungsbeschränkt)", diff --git a/core/nut.js/package.json b/core/nut.js/package.json index e56235aa..2023639b 100644 --- a/core/nut.js/package.json +++ b/core/nut.js/package.json @@ -51,7 +51,7 @@ "test": "jest --runInBand", "coverage": "jest --coverage --runInBand --logHeapUsage", "coverage:clean": "rimraf coverage", - "publish-next": "pnpm publish --tag next", + "publish:next": "pnpm publish --tag next", "prepublishOnly": "pnpm run compile", "versionBump": "bump --tag --push --all", "typedoc": "typedoc --options ./typedoc.js --entryPointStrategy expand ./lib" @@ -73,4 +73,4 @@ "lint-staged": { "**/*": "prettier --write --ignore-unknown" } -} +} \ No newline at end of file diff --git a/core/provider-interfaces/package.json b/core/provider-interfaces/package.json index 09c2e4a2..6916b5af 100644 --- a/core/provider-interfaces/package.json +++ b/core/provider-interfaces/package.json @@ -1,13 +1,13 @@ { "name": "@nut-tree/provider-interfaces", - "version": "1.0.0", + "version": "4.0.0", "description": "Public provider interfaces for @nut-tree/nut-js", "main": "dist/index", "typings": "dist/index", "scripts": { "clean": "rimraf dist", "compile": "pnpm run clean && tsc -p .", - "publish-next": "pnpm publish --tag next", + "publish:next": "pnpm publish --tag next", "prepublishOnly": "pnpm run compile" }, "keywords": [ @@ -23,7 +23,7 @@ "dependencies": { "@nut-tree/shared": "workspace:*" }, - "devDependencies": { - "@nut-tree/configs": "workspace:*" - } -} + "devDependencies": { + "@nut-tree/configs": "workspace:*" + } +} \ No newline at end of file diff --git a/core/shared/package.json b/core/shared/package.json index 2eedcd1b..b9a3e822 100644 --- a/core/shared/package.json +++ b/core/shared/package.json @@ -1,6 +1,6 @@ { "name": "@nut-tree/shared", - "version": "1.0.0", + "version": "4.0.0", "description": "Shared objects, data types and functions for @nut-tree/nut-js", "main": "dist/index", "typings": "dist/index", @@ -10,7 +10,7 @@ "coverage:clean": "rimraf coverage", "clean": "rimraf dist", "compile": "pnpm run clean && tsc -p .", - "publish-next": "pnpm publish --tag next", + "publish:next": "pnpm publish --tag next", "prepublishOnly": "pnpm run compile" }, "dependencies": { diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..3fd118de --- /dev/null +++ b/examples/README.md @@ -0,0 +1,4 @@ +# nut.js examples + +The projects contained in this folder are meant to be used as examples for how to use nut.js. +Especially the image matching samples will probably not run out of the box on you machine, nonetheless they should give you a good starting point for your own projects. \ No newline at end of file diff --git a/examples/jest-test/package.json b/examples/jest-test/package.json index 3b93be75..ce8d63be 100644 --- a/examples/jest-test/package.json +++ b/examples/jest-test/package.json @@ -1,6 +1,6 @@ { "name": "sample-jest", - "version": "2.0.0", + "version": "4.0.0", "private": true, "description": "A simple nut.js test example which demos Jest integration", "main": "index.js", diff --git a/examples/keyboard-test/package.json b/examples/keyboard-test/package.json index fac1939b..edc6100c 100644 --- a/examples/keyboard-test/package.json +++ b/examples/keyboard-test/package.json @@ -1,6 +1,6 @@ { "name": "sample-keyboard", - "version": "2.0.0", + "version": "4.0.0", "private": true, "description": "A simple nut.js test example which tests keyboard control", "main": "index.js", diff --git a/examples/mouse-test/package.json b/examples/mouse-test/package.json index 30ac3b19..8b2ef061 100644 --- a/examples/mouse-test/package.json +++ b/examples/mouse-test/package.json @@ -1,6 +1,6 @@ { "name": "sample-mouse", - "version": "2.0.0", + "version": "4.0.0", "private": true, "description": "A simple nut.js test example which tests mouse control", "author": { diff --git a/examples/screen-test/package.json b/examples/screen-test/package.json index 79114288..dea4ce7c 100644 --- a/examples/screen-test/package.json +++ b/examples/screen-test/package.json @@ -1,6 +1,6 @@ { "name": "sample-screen", - "version": "2.0.0", + "version": "4.0.0", "private": true, "description": "A simple nut.js test example which tests screen control", "main": "index.js", diff --git a/examples/typescript-test/package.json b/examples/typescript-test/package.json index bd23dac4..748e2d3b 100644 --- a/examples/typescript-test/package.json +++ b/examples/typescript-test/package.json @@ -1,6 +1,6 @@ { "name": "sample-typescript", - "version": "2.0.0", + "version": "4.0.0", "private": true, "description": "A simple nut.js test example which demos usage with TypeScript", "main": "index.ts", diff --git a/examples/window-test/package.json b/examples/window-test/package.json index c9bffc37..6e78434c 100644 --- a/examples/window-test/package.json +++ b/examples/window-test/package.json @@ -1,6 +1,7 @@ { "name": "sample-window", - "version": "2.0.0", + "version": "4.0.0", + "private": true, "description": "Integration tests to verify window handling", "main": "main.js", "author": { diff --git a/package.json b/package.json index 11e8a986..eed933d2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "compile": "pnpm -r run compile", "coverage": "pnpm -r run coverage", "coverage:clean": "pnpm -r run coverage:clean", - "prepare": "husky install" + "prepare": "husky install", + "publish:next": "pnpm -r run publish:next", + "publish": "pnpm -r run publish" }, "packageManager": "pnpm@8.15.2", "workspaces": [ diff --git a/providers/clipboardy/package.json b/providers/clipboardy/package.json index ab70f86b..fb451217 100644 --- a/providers/clipboardy/package.json +++ b/providers/clipboardy/package.json @@ -1,6 +1,6 @@ { "name": "@nut-tree/default-clipboard-provider", - "version": "1.0.0", + "version": "4.0.0", "description": "The @nut-tree/nut-js default clipboard provider based on clipboardy", "main": "dist/index", "typings": "dist/index", @@ -10,7 +10,7 @@ "test": "jest --runInBand", "clean": "rimraf dist", "compile": "pnpm run clean && tsc -p .", - "publish-next": "pnpm publish --tag next", + "publish:next": "pnpm publish --tag next", "prepublishOnly": "pnpm run compile" }, "keywords": [ diff --git a/providers/libnut/package.json b/providers/libnut/package.json index baeac448..e987e775 100644 --- a/providers/libnut/package.json +++ b/providers/libnut/package.json @@ -1,6 +1,6 @@ { "name": "@nut-tree/libnut", - "version": "3.0.0", + "version": "4.0.0", "description": "libnut is an N-API module for desktop automation with node", "main": "dist/index", "typings": "dist/index", @@ -34,7 +34,8 @@ "coverage": "jest --coverage --runInBand", "coverage:clean": "rimraf coverage", "publish:next": "pnpm publish --tag next", - "prepublishOnly": "pnpm run compile" + "prepublishOnly": "pnpm run compile", + "version": "npm version --no-git-tag -f" }, "engines": { "node": ">=10.15.3" @@ -52,4 +53,4 @@ "peerDependencies": { "@nut-tree/nut-js": "^3" } -} +} \ No newline at end of file