-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_build_npm.ts
57 lines (49 loc) · 1.4 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
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
const { version, outDir, modules } = parse(Deno.args, {
string: ["version", "modules", "outDir"],
default: {
version: "0.1.0-alpha.1",
outDir: "./_npm_build",
},
});
const isCustomModules = !!modules;
if (isCustomModules) {
let mod = "";
for (const m of modules.split(",")) {
mod += `export * as ${m} from "./${m}.ts";\n`;
}
const encoder = new TextEncoder();
Deno.writeFileSync("./_custom_mod.ts", encoder.encode(mod));
}
await emptyDir(outDir);
await build({
entryPoints: isCustomModules ? ["./_custom_mod.ts"] : ["./mod.ts"],
test: false,
outDir,
shims: {
timers: true,
deno: true,
undici: true,
},
package: {
// package.json properties
name: "ts-utils",
version: version,
description: "Small everyday TypeScript utils with no dependencies",
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/antonvasin/ts-utils.git",
},
bugs: {
url: "https://github.com/antonvasin/ts-utils/issues",
},
},
postBuild() {
// steps to run after building and before running the tests
Deno.copyFileSync("LICENSE", `${outDir}/LICENSE`);
Deno.copyFileSync("README.md", `${outDir}/README.md`);
},
});
isCustomModules && Deno.removeSync("./_custom_mod.ts");