-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.deno.js
57 lines (51 loc) · 1.47 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
#!/usr/bin/env node
const path = require("path");
const {
mkdirSync,
readdirSync,
lstatSync,
readFileSync,
writeFileSync,
} = require("fs");
function copyReadme(dest) {
writeFileSync(
path.join(dest, "README.md"),
readFileSync("./README.md").toString()
.replace(
/import \{ JSONparser \} from '@streamparser\/json';/gm,
"import JSONparser from 'https://deno.land/x/[email protected]/jsonparse.ts';/",
)
.replace(
/import { Tokenizer } from '@streamparser\/json';/gm,
"import Tokenizer from 'https://deno.land/x/[email protected]/tokenizer.ts';/",
)
.replace(
/import { Parser } from '@streamparser\/json';/gm,
"import Parser from 'https://deno.land/x/[email protected]/parser.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]+)"/gm,
"from '$1.ts'",
),
);
});
}
const src = process.argv[2]; // './src'
const dest = process.argv[3]; // './dist'
copyReadme(dest);
processDir(src, dest);