Skip to content

Commit f6eb3a7

Browse files
committed
chore(_tools): add npm build script
1 parent 2545a17 commit f6eb3a7

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

_tools/build_npm.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
2+
import { join } from "https://deno.land/[email protected]/path/mod.ts";
3+
import { makeOptions } from "./meta.ts";
4+
5+
async function buildPkg(version: string): Promise<void> {
6+
await emptyDir("./npm");
7+
const pkg = makeOptions(version);
8+
await Deno.copyFile("LICENSE", join(pkg.outDir, "LICENSE"));
9+
Deno.copyFile(
10+
join(".", "README.md"),
11+
join(pkg.outDir, "README.md"),
12+
);
13+
await build(pkg);
14+
}
15+
16+
if (import.meta.main) {
17+
const version = Deno.args[0];
18+
if (!version) {
19+
console.error("argument is required");
20+
Deno.exit(1);
21+
}
22+
await buildPkg(version);
23+
}

_tools/meta.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { BuildOptions } from "https://deno.land/x/[email protected]/mod.ts";
2+
3+
export const makeOptions = (version: string): BuildOptions => ({
4+
test: false,
5+
shims: {},
6+
compilerOptions: {
7+
lib: ["dom", "esnext", "dom.iterable"],
8+
},
9+
typeCheck: false,
10+
entryPoints: ["./mod.ts"],
11+
outDir: "./npm",
12+
package: {
13+
name: "@httpland/compression-middleware",
14+
version,
15+
description: "HTTP compression middleware",
16+
keywords: [
17+
"http",
18+
"middleware",
19+
"header",
20+
"compression",
21+
"compress",
22+
"gzip",
23+
"deflate",
24+
"encoding",
25+
"encoder",
26+
"fetch-api",
27+
],
28+
engines: {
29+
node: "^18.x",
30+
},
31+
license: "MIT",
32+
homepage: "https://github.com/httpland/compression-middleware",
33+
repository: {
34+
type: "git",
35+
url: "git+https://github.com/httpland/compression-middleware.git",
36+
},
37+
bugs: {
38+
url: "https://github.com/httpland/compression-middleware/issues",
39+
},
40+
sideEffects: false,
41+
type: "module",
42+
publishConfig: {
43+
access: "public",
44+
},
45+
},
46+
mappings: {
47+
"https://esm.sh/v110/[email protected]": {
48+
name: "compressible",
49+
version: "2.0.18",
50+
},
51+
"https://deno.land/x/[email protected]/mod.ts": {
52+
name: "@httpland/http-middleware",
53+
version: "1.0.0",
54+
},
55+
"https://deno.land/x/[email protected]/header.ts": {
56+
name: "@httpland/http-utils",
57+
version: "1.0.0-beta.13",
58+
},
59+
"https://deno.land/x/[email protected]/mod.ts": {
60+
name: "isxx",
61+
version: "1.0.0-beta.24",
62+
},
63+
},
64+
packageManager: "pnpm",
65+
});

_tools/publish_npm.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { prerelease, valid } from "https://deno.land/x/[email protected]/mod.ts";
2+
import { makeOptions } from "./meta.ts";
3+
4+
if (import.meta.main) {
5+
const version = Deno.args[0];
6+
if (!version) {
7+
console.error("arg of version is required");
8+
Deno.exit(1);
9+
}
10+
if (!valid(version)) {
11+
console.error("The argument of version is invalid");
12+
Deno.exit(1);
13+
}
14+
15+
const isPrerelease = prerelease(version);
16+
const tag = isPrerelease?.[0] ?? "latest";
17+
18+
const pkg = makeOptions(version);
19+
const result = await Deno.run({
20+
cmd: ["npm", "publish", pkg.outDir, "--tag", String(tag)],
21+
stdout: "piped",
22+
})
23+
.output();
24+
25+
console.log(new TextDecoder().decode(result));
26+
}

0 commit comments

Comments
 (0)