Skip to content

Commit 46066aa

Browse files
committed
chore(_tools): add npm build script
1 parent 8d165d8 commit 46066aa

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
typeCheck: true,
7+
entryPoints: ["./mod.ts"],
8+
outDir: "./npm",
9+
package: {
10+
name: "@httpland/authorization-parser",
11+
version,
12+
description: "HTTP Authorization field parser and serializer",
13+
keywords: [
14+
"http",
15+
"authorization",
16+
"parse",
17+
"parser",
18+
"header",
19+
"serializer",
20+
"serialize",
21+
"stringify",
22+
"field",
23+
"rfc-9110",
24+
],
25+
license: "MIT",
26+
homepage: "https://github.com/httpland/authorization-parser",
27+
repository: {
28+
type: "git",
29+
url: "git+https://github.com/httpland/authorization-parser.git",
30+
},
31+
bugs: {
32+
url: "https://github.com/httpland/authorization-parser/issues",
33+
},
34+
sideEffects: false,
35+
type: "module",
36+
publishConfig: {
37+
access: "public",
38+
},
39+
},
40+
packageManager: "pnpm",
41+
mappings: {
42+
"https://deno.land/x/[email protected]/to_lower_case.ts": {
43+
name: "@miyauci/prelude",
44+
version: "1.2.0",
45+
subPath: "to_lower_case.js",
46+
},
47+
"https://deno.land/x/[email protected]/trim.ts": {
48+
name: "@miyauci/prelude",
49+
version: "1.2.0",
50+
subPath: "trim.js",
51+
},
52+
"https://deno.land/x/[email protected]/head.ts": {
53+
name: "@miyauci/prelude",
54+
version: "1.2.0",
55+
subPath: "head.js",
56+
},
57+
},
58+
});

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