Skip to content

Commit 39fcd53

Browse files
committed
npm: render a README into each platform package
The platform sub-packages had no README, so npmjs.com showed an empty page. Add a template with {{SCOPE}}/{{PKG}}/{{OS}}/{{CPU}} placeholders and render it in build-platform-packages.mjs so every generated package ships a README pointing users at the main @zerops/zcli package.
1 parent 6488ba3 commit 39fcd53

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

tools/npm/scripts/build-platform-packages.mjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@
1111
// Each generated package carries os/cpu fields so the package manager (npm, and Bun,
1212
// which honors them) installs only the one matching the host.
1313

14-
import { mkdirSync, copyFileSync, writeFileSync, chmodSync, existsSync, rmSync } from "node:fs";
15-
import { join } from "node:path";
14+
import { mkdirSync, copyFileSync, writeFileSync, readFileSync, chmodSync, existsSync, rmSync } from "node:fs";
15+
import { dirname, join } from "node:path";
16+
import { fileURLToPath } from "node:url";
1617
import { createRequire } from "node:module";
1718

1819
const require = createRequire(import.meta.url);
1920
const { SCOPE, PLATFORMS } = require("../lib/platforms.js");
2021

22+
const __dirname = dirname(fileURLToPath(import.meta.url));
23+
const README_TEMPLATE = readFileSync(join(__dirname, "platform-package.README.md.tmpl"), "utf8");
24+
25+
function renderReadme({ pkg, os, cpu }) {
26+
return README_TEMPLATE
27+
.replaceAll("{{SCOPE}}", SCOPE)
28+
.replaceAll("{{PKG}}", pkg)
29+
.replaceAll("{{OS}}", os)
30+
.replaceAll("{{CPU}}", cpu);
31+
}
32+
2133
function parseArgs(argv) {
2234
const args = {};
2335
for (let i = 0; i < argv.length; i += 2) {
@@ -63,6 +75,7 @@ for (const p of PLATFORMS) {
6375
files: ["bin/"],
6476
};
6577
writeFileSync(join(pkgDir, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n");
78+
writeFileSync(join(pkgDir, "README.md"), renderReadme(p));
6679

6780
console.log(`built ${SCOPE}/${p.pkg}@${version} (${p.os}/${p.cpu}) -> ${dest}`);
6881
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# {{SCOPE}}/{{PKG}}
2+
3+
Prebuilt `zcli` binary for **{{OS}}/{{CPU}}**.
4+
5+
This package is an internal platform-specific dependency of [`{{SCOPE}}/zcli`](https://www.npmjs.com/package/{{SCOPE}}/zcli). You should not install it directly — install the main package instead, and npm will pull in the right platform binary via `optionalDependencies`:
6+
7+
```sh
8+
npm i -g {{SCOPE}}/zcli
9+
```
10+
11+
For docs, source, and issues see the [zeropsio/zcli](https://github.com/zeropsio/zcli) repository.

0 commit comments

Comments
 (0)