-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-npm.ts
65 lines (57 loc) · 1.75 KB
/
build-npm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { build, emptyDir } from "dnt";
import { grantOrThrow } from "deno/permissions/mod.ts";
import {
basename,
dirname,
fromFileUrl,
join,
relative,
} from "deno/path/mod.ts";
import { valid } from "semver";
await grantOrThrow(
{ name: "env", variable: "VERSION" },
{ name: "env", variable: "SCOPE" },
);
const version = Deno.env.get("VERSION");
if (!version) {
throw new TypeError(`VERSION environment variable is missing`);
}
if (!valid(version)) {
throw new TypeError(`${version} isn't a valid semver version`);
}
const scope = Deno.env.get("SCOPE");
if (!scope) {
throw new TypeError(`SCOPE environment variable is missing`);
}
const rootDir = dirname(join(fromFileUrl(import.meta.url), ".."));
const name = basename(rootDir);
await emptyDir("./dist/npm");
await build({
entryPoints: ["./src/mod.ts"],
outDir: "./dist/npm",
shims: {
deno: "dev",
timers: true,
},
package: {
name: `@${scope.toLowerCase()}/${name.toLowerCase()}`,
version,
description:
"Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.",
keywords: ["async", "channel", "channels", "await"],
homepage: `https://github.com/Eyal-Shalev/${name}`,
bugs: {
url: `https://github.com/Eyal-Shalev/${name}/issues`,
},
license: "GPL-3.0-or-later",
author: `Eyal Shalev <eyalsh@gmail.com> (https://github.com/Eyal-Shalev)`,
repository: {
type: "git",
url: `git+https://github.com/Eyal-Shalev/${name}.git`,
},
},
importMap: relative(Deno.cwd(), join(rootDir, "scripts", "import_map.json")),
});
// post build steps
Deno.copyFileSync("LICENSE", "dist/npm/LICENSE");
Deno.copyFileSync("README.md", "dist/npm/README.md");