Skip to content

Commit db52075

Browse files
committed
build: new publish scripts
1 parent 22fb953 commit db52075

File tree

4 files changed

+178
-8
lines changed

4 files changed

+178
-8
lines changed

.github/workflows/publish.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ jobs:
2222
node-version: 14
2323
- run: npm ci
2424
- run: npm run build:tsc
25-
- run: npm run build:lib
26-
- run: npm test
2725
- run: npm run build:package
28-
- uses: JS-DevTools/npm-publish@v1
29-
with:
30-
token: ${{ secrets.NPM_TOKEN }}
31-
package: "./dist-package/package.json"
26+
- run: npm test
27+
- run: node scripts/npm-publish.mjs
28+
env:
29+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
30+
NO_DRY_RUN: "1"

package-lock.json

+135-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "Better TypeScript standard library",
66
"main": "index.js",
77
"devDependencies": {
8+
"@jsdevtools/npm-publish": "^1.4.3",
89
"@types/node": "^16.9.4",
910
"prettier": "^2.4.1",
1011
"tsd": "^0.17.0",
@@ -26,4 +27,4 @@
2627
"types": []
2728
}
2829
}
29-
}
30+
}

scripts/npm-publish.mjs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Script to publish generated npm packages.
2+
// Should be called from GitHub "publish" Action.
3+
import npmPublish from "@jsdevtools/npm-publish";
4+
import { readdir } from "fs/promises";
5+
import path, { dirname } from "path";
6+
import { fileURLToPath } from "url";
7+
8+
const distPackageDir = path.join(
9+
dirname(fileURLToPath(import.meta.url)),
10+
"..",
11+
"dist-package"
12+
);
13+
const packages = await readdir(distPackageDir);
14+
const packageJsonPaths = packages.map((packageName) => path.join(
15+
distPackageDir,
16+
packageName,
17+
"package.json"
18+
));
19+
20+
// To actually publish, you need to pass a NO_DRY_RUN environment variable.
21+
const dryRun = !process.env.NO_DRY_RUN
22+
const token = process.env.NPM_TOKEN
23+
24+
for (const packageJsonPath of packageJsonPaths) {
25+
const { type, package: packageName, version, oldVersion } = await npmPublish({
26+
dryRun,
27+
package: packageJsonPath,
28+
access: "public",
29+
token,
30+
});
31+
if (type === "none") {
32+
console.log(`${packageName} was not publsihed`)
33+
} else {
34+
console.log(`${packageName}: ${type} ${oldVersion} -> ${version}`)
35+
}
36+
}

0 commit comments

Comments
 (0)