-
Notifications
You must be signed in to change notification settings - Fork 4
/
_build_npm.ts
executable file
·98 lines (85 loc) · 2.92 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write --allow-run=npm,cmd --allow-net=deno.land
// Copyright 2018-2022 Gamebridge.ai authors. All rights reserved. MIT license.
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
const entryPointDefault = "./mod.ts";
const outDirDefault = "./dist";
const versionDefault = "v0.0.0-test";
const helpText = `
Deno to node transpiler, converts the ts_serialize module to a node compatible \
module, and writes it to .github/workflows/npm, or the directory of your choice.
This must be run from the project root if using the default arguments.
Usage:
./_build_npm.ts [-v ${versionDefault}] [-e ${entryPointDefault}] [-o ${outDirDefault}]
./_build_npm.ts --help
Command line arguments:
-h, --help Prints this help message, then exits.
-v, --version=[version] The version value to set in the resulting package.json. Defaults to "${versionDefault}".
-e, --entry-point=[path] The path to the mod.ts file to transpile into the npm package. Defaults to "${entryPointDefault}"
-o, --out=[path] The path to the target directory where the built files should be placed. Defaults to "${outDirDefault}"
`;
function printHelpText(message = "") {
if (message.length) {
console.error(`\n${message}`);
console.log(helpText);
Deno.exit(1);
}
console.log(helpText);
Deno.exit(0);
}
const flags = parse(Deno.args, {
string: ["v", "e", "o"],
boolean: ["h"],
alias: { h: "help", e: "entry-point", v: "version", o: "out" },
default: { e: entryPointDefault, o: outDirDefault, v: versionDefault },
unknown: () => printHelpText("Unknown argument"),
});
if (flags.h) {
printHelpText();
}
try {
await emptyDir(flags.o);
await build({
entryPoints: [flags.e],
outDir: flags.o,
compilerOptions: { target: "ES2021" },
shims: {
deno: true,
},
package: {
name: "@gamebridgeai/ts_serialize",
version: flags.v,
description: "A zero dependency library for serializing data.",
repository: {
type: "git",
url: "https://github.com/GameBridgeAI/ts_serialize.git",
},
author: "GameBridgeAI",
license: "MIT",
bugs: {
url: "https://github.com/GameBridgeAI/ts_serialize/issues",
},
homepage: "https://github.com/GameBridgeAI/ts_serialize",
keywords: [
"ts_serialize",
"ts_serializable",
"ts-serialize",
"ts-serializable",
"typescript",
"serializable",
"serialize",
"deserialize",
"serialization",
"deserialization",
"json",
"node",
"deno",
],
},
});
await Deno.copyFile("LICENSE", `${flags.o}/LICENSE`);
await Deno.copyFile("README.md", `${flags.o}/README.md`);
await Deno.copyFile("CHANGELOG.md", `${flags.o}/CHANGELOG.md`);
} catch (e) {
printHelpText(e.message);
}