-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-content.ts
53 lines (47 loc) · 1.29 KB
/
render-content.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
import { render } from "../../src";
import { promises as fs } from "fs";
import prettier from "prettier";
import { getFiles } from "../../dev/common/get-files";
/**
* @param file Usually __filename from the calling script
*/
const runRender = async (file: string) => {
const expectedOutputPath = file.replace("spec.ts", "output.ts");
const content = render({
from: {
kind: "file-list",
files: [file],
tsConfig: {
esModuleInterop: true,
strict: true
}
},
expectedOutputPath,
deno: false
});
const formatted = (() => {
try {
return prettier.format(content, {
parser: "typescript"
});
} catch (err) {
console.log(`Error in ${expectedOutputPath}: ${err.message}`);
return content;
}
})();
await fs.writeFile(expectedOutputPath, formatted);
};
(async () => {
const files = await getFiles("./test/render");
const outputFiles = new Array<string>();
const specFiles = new Array<string>();
files.forEach(file => {
if (file.endsWith(".output.ts")) {
outputFiles.push(file);
} else if (file.endsWith(".spec.ts")) {
specFiles.push(file);
}
});
await Promise.all(outputFiles.map(file => fs.unlink(file)));
await Promise.all(specFiles.map(file => runRender(file)));
})();