-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
_build_npm.ts
91 lines (85 loc) · 2.44 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
// dnt deps can not be moved to dev_deps.ts
import { build, emptyDir } from "@deno/dnt";
import type { PackageJson } from "@deno/dnt";
import * as pc from "jsr:@std/fmt@0.225.1/colors";
export async function buildDnt() {
let version = Deno.args[0];
const GITHUB_REF = Deno.env.get("GITHUB_REF");
const PKG_VERSION = Deno.env.get("PKG_VERSION");
if (!version) {
if (PKG_VERSION) {
console.log(`NPM_VERSION values is "${pc.green(PKG_VERSION)}"`);
version = PKG_VERSION;
} else if (GITHUB_REF) {
// drop the ref/tag/ and the v prefix
version = GITHUB_REF.replace(/^.+\/[vV]?/g, "");
console.log(
`GITHUB_REF values is ${
pc.green(
GITHUB_REF,
)
} will be used as version: "${pc.green(version)}"`,
);
}
}
if (!version) {
console.error("Missing version number");
console.error("usage: deno run -A _build_npm.ts v0.0.0");
Deno.exit(-1);
}
// allow only semver string
if (!version.match(/[\d]+\.[\d]+\.[\d]+/)) {
console.error(
`version number ${
pc.green(version)
} do not match Semantic Versioning syntax ${
pc.green("major.minor.path")
}`,
);
Deno.exit(-1);
}
const packageJson: PackageJson = {
name: "@denodnt/logger",
author: "zfx",
license: "MIT",
funding: "https://github.com/deno-library/logger?sponsor=1",
contributors: [
"fuxing Zhang <fuxing.zhang@qq.com> (https://github.com/fuxingZhang)",
"Uriel Chemouni <uchemouni@gmail.com> (https://uriel.ovh/)",
],
description: "deno logger available for deno and NPM",
keywords: ["logger", "deno", "rotate"],
private: false,
homepage: "https://github.com/deno-library/logger",
version,
repository: {
type: "git",
url: "git+https://github.com/deno-library/logger",
},
bugs: {
url: "https://github.com/deno-library/logger/issues",
},
};
await emptyDir("./npm");
await build({
entryPoints: ["./mod.ts"],
outDir: "./npm",
test: true,
shims: {
deno: true,
},
compilerOptions: {},
package: packageJson,
});
// post build steps
Deno.copyFileSync("LICENSE", "npm/LICENSE");
let readme = Deno.readTextFileSync("README.md");
readme = readme.replaceAll(
/https:\/\/deno.land\/x\/logger@v[0-9.]+\/(logger|mod)\.ts/g,
"@denodnt/logger",
);
Deno.writeTextFileSync("npm/README.md", readme);
}
if (import.meta.main) {
buildDnt();
}