Skip to content

Commit 14aa1bb

Browse files
committed
chore(_tools): add npm build script
1 parent dba43a8 commit 14aa1bb

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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: [
8+
"esnext",
9+
"dom",
10+
"dom.iterable",
11+
],
12+
},
13+
typeCheck: false,
14+
entryPoints: ["./mod.ts"],
15+
outDir: "./npm",
16+
package: {
17+
name: "@httpland/conditional-request-middleware",
18+
version,
19+
description: "HTTP conditional request middleware",
20+
keywords: [
21+
"http",
22+
"conditional-request",
23+
"conditional",
24+
"middleware",
25+
"etag",
26+
"last-modified",
27+
"range",
28+
"if-match",
29+
"if-none-match",
30+
"if-modified-since",
31+
"if-unmodified-since",
32+
"if-range",
33+
],
34+
license: "MIT",
35+
homepage: "https://github.com/httpland/conditional-request-middleware",
36+
repository: {
37+
type: "git",
38+
url: "git+https://github.com/httpland/conditional-request-middleware.git",
39+
},
40+
bugs: {
41+
url: "https://github.com/httpland/conditional-request-middleware/issues",
42+
},
43+
sideEffects: false,
44+
type: "module",
45+
publishConfig: {
46+
access: "public",
47+
},
48+
},
49+
packageManager: "pnpm",
50+
mappings: {
51+
"https://deno.land/x/[email protected]/mod.ts": {
52+
name: "isxx",
53+
version: "1.0.0-beta.24",
54+
},
55+
"https://deno.land/x/[email protected]/mod.ts": {
56+
name: "@httpland/http-middleware",
57+
version: "1.0.0",
58+
},
59+
"https://deno.land/x/[email protected]/header.ts": {
60+
name: "@httpland/http-utils",
61+
version: "1.0.0-beta.14",
62+
},
63+
"https://deno.land/x/[email protected]/method.ts": {
64+
name: "@httpland/http-utils",
65+
version: "1.0.0-beta.14",
66+
},
67+
"https://deno.land/x/[email protected]/mod.ts": {
68+
name: "@httpland/etag-parser",
69+
version: "1.0.0",
70+
},
71+
"https://deno.land/x/[email protected]/mod.ts": {
72+
name: "@miyauci/result",
73+
version: "1.0.0",
74+
},
75+
"https://deno.land/x/[email protected]/mod.ts": {
76+
name: "@httpland/range-request-middleware",
77+
version: "1.0.0-beta.1",
78+
},
79+
},
80+
});

_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)