diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml index 53e4a42a5..67973c782 100644 --- a/.github/workflows/release-package.yml +++ b/.github/workflows/release-package.yml @@ -24,11 +24,15 @@ jobs: cache: pnpm - name: Install dependencies - run: pnpm install --frozen-lockfile + run: | + pnpm install --frozen-lockfile + result=$(npx tsx scripts/filterPackages.mts) + echo filters=$result >> $GITHUB_ENV + # run: pnpm run --filter \"./packages/**\" build - name: Publish 🚀 shell: bash - run: pnpm publish packages/* --access public --no-git-checks + run: pnpm publish packages/{${{ env.filters }}} --access public --no-git-checks env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index ae212fde5..b409ed709 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "gen:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", "reinstall": "rimraf pnpm-lock.yaml && rimraf package.lock.json && rimraf node_modules && npm run bootstrap", "test:gzip": "npx http-server dist --cors --gzip -c-1", - "test:br": "npx http-server dist --cors --brotli -c-1" + "test:br": "npx http-server dist --cors --brotli -c-1", + "p": "pnpm publish --filter \"./packages/{test,vite-plugin-msw}\" --access public --no-git-checks" }, "dependencies": { "@admin-pkg/vite-plugin-msw": "workspace:*", diff --git a/packages/test/index.js b/packages/test/index.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/test/package.json b/packages/test/package.json new file mode 100644 index 000000000..87525260a --- /dev/null +++ b/packages/test/package.json @@ -0,0 +1,11 @@ +{ + "name": "@admin-pkg/test", + "version": "1.0.2", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/scripts/filterPackages.mts b/scripts/filterPackages.mts new file mode 100644 index 000000000..6a2a89fbe --- /dev/null +++ b/scripts/filterPackages.mts @@ -0,0 +1,39 @@ +import fs from 'node:fs'; +import { exec } from 'child_process'; + +const folderPath = 'packages'; + +const items = fs.readdirSync(folderPath); + +async function filterPackages() { + const promises = items.map(async (name) => { + const localPkgInfo = await runCommand(`npm view ./packages/${name} name version --json`); + const remoteVersion = await runCommand(`npm view ${localPkgInfo.name} version`); + + if (localPkgInfo.version !== remoteVersion) { + return name; + } + return null; + }); + + const packages = await Promise.all(promises); + return packages.filter(Boolean).join(','); +} + +function runCommand(command) { + return new Promise((resolve, reject) => { + exec(command, (error, stdout) => { + if (error) { + reject(error); + } else { + try { + resolve(JSON.parse(stdout.trim())); + } catch (error) { + resolve(stdout.trim()); + } + } + }); + }); +} + +console.log(await filterPackages());