-
Notifications
You must be signed in to change notification settings - Fork 33
/
build.js
44 lines (39 loc) · 1.18 KB
/
build.js
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
import * as coffee from "coffeescript";
import * as fs from "fs";
import * as path from "path";
import * as url from "url";
const DIR = path.dirname(url.fileURLToPath(import.meta.url));
const BUILD = path.join(DIR, "build");
const READ_MORE = "**[➡️ Full readme](https://github.com/lydell/js-tokens/)**";
const FILES_TO_COPY = [
{ src: "LICENSE" },
{ src: "index.d.ts" },
{ src: "package-real.json", dest: "package.json" },
{
src: "README.md",
transform: (content) => content.replace(/^##[^]*/m, READ_MORE),
},
{
src: "index.coffee",
dest: "index.js",
transform: (content) =>
coffee
.compile(content, { bare: true })
.replace(/ {2}/g, "\t")
.replace(/\/\/ (?:Note:|https).*\n/g, "")
.replace(/\n\n/g, "\n")
.replace(/\{\s*(tag: "[^"]+")\s*\}/g, "{$1}"),
},
];
fs.rmSync(BUILD, { recursive: true, force: true });
fs.mkdirSync(BUILD);
for (const { src, dest = src, transform } of FILES_TO_COPY) {
if (transform) {
fs.writeFileSync(
path.join(BUILD, dest),
transform(fs.readFileSync(path.join(DIR, src), "utf8")),
);
} else {
fs.copyFileSync(path.join(DIR, src), path.join(BUILD, dest));
}
}