Skip to content

Commit

Permalink
build: new publish scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo committed Sep 24, 2021
1 parent 22fb953 commit db52075
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 8 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ jobs:
node-version: 14
- run: npm ci
- run: npm run build:tsc
- run: npm run build:lib
- run: npm test
- run: npm run build:package
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: "./dist-package/package.json"
- run: npm test
- run: node scripts/npm-publish.mjs
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NO_DRY_RUN: "1"
136 changes: 135 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Better TypeScript standard library",
"main": "index.js",
"devDependencies": {
"@jsdevtools/npm-publish": "^1.4.3",
"@types/node": "^16.9.4",
"prettier": "^2.4.1",
"tsd": "^0.17.0",
Expand All @@ -26,4 +27,4 @@
"types": []
}
}
}
}
36 changes: 36 additions & 0 deletions scripts/npm-publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Script to publish generated npm packages.
// Should be called from GitHub "publish" Action.
import npmPublish from "@jsdevtools/npm-publish";
import { readdir } from "fs/promises";
import path, { dirname } from "path";
import { fileURLToPath } from "url";

const distPackageDir = path.join(
dirname(fileURLToPath(import.meta.url)),
"..",
"dist-package"
);
const packages = await readdir(distPackageDir);
const packageJsonPaths = packages.map((packageName) => path.join(
distPackageDir,
packageName,
"package.json"
));

// To actually publish, you need to pass a NO_DRY_RUN environment variable.
const dryRun = !process.env.NO_DRY_RUN
const token = process.env.NPM_TOKEN

for (const packageJsonPath of packageJsonPaths) {
const { type, package: packageName, version, oldVersion } = await npmPublish({
dryRun,
package: packageJsonPath,
access: "public",
token,
});
if (type === "none") {
console.log(`${packageName} was not publsihed`)
} else {
console.log(`${packageName}: ${type} ${oldVersion} -> ${version}`)
}
}

0 comments on commit db52075

Please sign in to comment.