-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.deno.js
60 lines (52 loc) · 1.51 KB
/
build.deno.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
import path from "path";
import {
mkdirSync,
readdirSync,
lstatSync,
readFileSync,
writeFileSync,
} from "fs";
import pkgInfo from "./package.json" assert { type: "json" };
const denoXURL = `https://deno.land/x/streamparser_json@v${pkgInfo.version}`;
function copyReadme(src, dest) {
writeFileSync(
path.join(dest, "README.md"),
readFileSync("./README.md")
.toString()
.replace(
/import \{ (.*) \} from '@streamparser\/json';/gm,
`import { $1 } from "${denoXURL}/index.ts";/`,
)
.replace(
/import { (.*) } from '@streamparser\/json\/(.*).js';/gm,
`import { $1 } from "${denoXURL}/$2.ts)";/`,
),
);
}
function processDir(src, dest) {
mkdirSync(dest, { recursive: true });
readdirSync(src).forEach((name) => {
const currentPath = path.join(src, name);
const destPath = path.join(dest, name);
const currentStats = lstatSync(currentPath);
if (currentStats.isDirectory()) {
processDir(currentPath, destPath);
return;
}
writeFileSync(
destPath,
readFileSync(currentPath)
.toString()
.replace(/from "(\.[.\\/-\w]+).js"/gm, 'from "$1.ts"')
.replace(/from "@streamparser\/json"/gm, `from "${denoXURL}/index.ts"`)
.replace(
/from "@streamparser\/json\/(.*).js"/gm,
`from "${denoXURL}/$1.ts"`,
),
);
});
}
const [, , src, dest] = process.argv; // './src', './dist'
processDir(path.join(src, "src"), dest);
copyReadme(src, dest);