-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabap.mjs
76 lines (63 loc) · 2.21 KB
/
abap.mjs
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
import * as fs from "node:fs";
import * as path from "node:path";
console.log("Running abap.mjs");
let output = "export const abapfiles = {\n";
let files = {};
function escape(input) {
if (input.charCodeAt(0) === 0xFEFF) {
input = input.substr(1);
}
return input.replaceAll("\\", "\\\\")
.replaceAll("`", "\\`")
.replaceAll("${", "\\${").trimEnd();
}
function add(name, contents) {
output += `"${name}": \`${escape(contents)}\`,\n`;
files[name] = contents;
}
/////////////////////////////////////////
for (const dirent of fs.readdirSync("open-abap-core/src", {recursive: true, withFileTypes: true})) {
if (dirent.isDirectory() || dirent.name.endsWith(".testclasses.abap")) {
continue;
}
const contents = fs.readFileSync(path.join(dirent.parentPath, dirent.name)).toString();
add(dirent.name, contents);
}
/////////////////////////////////////////
for (let i = 1; i < 99; i++) {
let prefixed = i + "";
if (prefixed.length < 3) {
prefixed = "0" + prefixed;
}
if (prefixed.length < 3) {
prefixed = "0" + prefixed;
}
const filename = "abap2xlsx-demos/src/demo" + prefixed + "/zcl_excel_demo" + i + ".clas.abap";
try {
const contents = fs.readFileSync(filename, "utf-8").toString("utf-8");
add("zcl_excel_demo" + i + ".clas.abap", contents);
} catch {
continue;
}
}
{
const contents = fs.readFileSync("abap2xlsx-demos/src/zif_excel_demo_output.intf.abap").toString();
add("zif_excel_demo_output.intf.abap", contents);
}
/////////////////////////////////////////
const filter = JSON.parse(fs.readFileSync("abap2xlsx/abap_transpile.json")).input_filter;
for (const dirent of fs.readdirSync("abap2xlsx/src", {recursive: true, withFileTypes: true})) {
if (dirent.isDirectory() || dirent.name.endsWith(".testclasses.abap")) {
continue;
}
if (filter.some(f => path.join(dirent.parentPath, dirent.name).replaceAll("\\", "/").match(f)) === false) {
continue;
}
const contents = fs.readFileSync(path.join(dirent.parentPath, dirent.name)).toString();
add(dirent.name, contents);
}
/////////////////////////////////////////
fs.writeFileSync("src/abap.js", output + "\n};");
for (const filename in files) {
fs.writeFileSync(path.join("input", filename), files[filename]);
}