Skip to content

Commit d093664

Browse files
committed
feat(build): add publish-all script to automate library publishing
Add a new script that automatically builds and publishes all libraries in the project. This simplifies the publishing process by handling all libraries in one command rather than requiring manual publishing of each library individually.
1 parent a64a490 commit d093664

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"build": "node tools/scripts/build-libs.js",
1515
"build:all": "bunx nx run-many --target=build --all",
1616
"build:libs": "bunx nx run-many --target=build --projects=libs/*",
17+
"publish:all": "node tools/scripts/publish-all.js",
1718
"lint": "bunx nx run-many --target=lint --all"
1819
},
1920
"private": true,

tools/scripts/publish-all.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports
2+
const { execSync } = require('child_process');
3+
// eslint-disable-next-line @typescript-eslint/no-require-imports
4+
const fs = require('fs');
5+
// eslint-disable-next-line @typescript-eslint/no-require-imports
6+
const path = require('path');
7+
8+
const libsDir = path.join(__dirname, '../..', 'libs');
9+
10+
const getLibDirs = () => {
11+
return fs.readdirSync(libsDir).filter((dir) => {
12+
const stat = fs.statSync(path.join(libsDir, dir));
13+
return (
14+
stat.isDirectory() &&
15+
fs.existsSync(path.join(libsDir, dir, 'package.json'))
16+
);
17+
});
18+
};
19+
20+
const publishLib = (lib) => {
21+
const distPath = path.join(__dirname, '../..', 'libs', lib);
22+
23+
console.log(`📦 Building ${lib}...`);
24+
execSync(`npx nx build ${lib}`, { stdio: 'inherit' });
25+
26+
console.log(`🚀 Publishing ${lib}...`);
27+
try {
28+
execSync(`npm publish ${distPath} --access public`, { stdio: 'inherit' });
29+
console.log(`✅ Published ${lib}`);
30+
} catch (err) {
31+
console.warn(`⚠️ Skipped ${lib}: ${err.message}`);
32+
}
33+
};
34+
35+
const libs = getLibDirs();
36+
37+
for (const lib of libs) {
38+
publishLib(lib);
39+
}

0 commit comments

Comments
 (0)