Skip to content

Commit a904ef1

Browse files
authored
update example (#9)
1 parent 7655531 commit a904ef1

File tree

10 files changed

+78
-21
lines changed

10 files changed

+78
-21
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules
33
abap2xlsx
44
abap2xlsx-demos
55
open-abap-core
6-
src/abap.ts
6+
src/abap.ts
7+
input
8+
output

abap.mjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as fs from "node:fs";
22
import * as path from "node:path";
33

4-
console.log("Building abap.js");
4+
console.log("Running abap.mjs");
55

66
let output = "export const abapfiles = {\n";
7+
let files = {};
78

89
function escape(input) {
910
if (input.charCodeAt(0) === 0xFEFF) {
@@ -12,26 +13,31 @@ function escape(input) {
1213
return input.replaceAll("`", "\\`").replaceAll("${", "\\${").trimEnd();
1314
}
1415

16+
function add(name, contents) {
17+
output += `"${name}": \`${escape(contents)}\`,\n`;
18+
files[name] = contents;
19+
}
20+
1521
/////////////////////////////////////////
1622

1723
for (const dirent of fs.readdirSync("open-abap-core/src", {recursive: true, withFileTypes: true})) {
1824
if (dirent.isDirectory() || dirent.name.endsWith(".testclasses.abap")) {
1925
continue;
2026
}
2127
const contents = fs.readFileSync(path.join(dirent.parentPath, dirent.name)).toString();
22-
output += `"${dirent.name}": \`${escape(contents)}\`,\n`;
28+
add(dirent.name, contents);
2329
}
2430

2531
/////////////////////////////////////////
2632

2733
{
28-
const contents = fs.readFileSync("abap2xlsx-demos/src/zcl_excel_demo1.clas.abap", "utf-8").toString("utf-8");
29-
output += `"zcl_excel_demo1.clas.abap": \`${escape(contents)}\`,\n`;
34+
const contents = fs.readFileSync("abap2xlsx-demos/src/demo001/zcl_excel_demo1.clas.abap", "utf-8").toString("utf-8");
35+
add("zcl_excel_demo1.clas.abap", contents);
3036
}
3137

3238
{
3339
const contents = fs.readFileSync("abap2xlsx-demos/src/zif_excel_demo_output.intf.abap").toString();
34-
output += `"zif_excel_demo_output.intf.abap": \`${escape(contents)}\`,\n`;
40+
add("zif_excel_demo_output.intf.abap", contents);
3541
}
3642

3743
/////////////////////////////////////////
@@ -45,9 +51,12 @@ for (const dirent of fs.readdirSync("abap2xlsx/src", {recursive: true, withFileT
4551
continue;
4652
}
4753
const contents = fs.readFileSync(path.join(dirent.parentPath, dirent.name)).toString();
48-
output += `"${dirent.name}": \`${escape(contents)}\`,\n`;
54+
add(dirent.name, contents);
4955
}
5056

5157
/////////////////////////////////////////
5258

53-
fs.writeFileSync("src/abap.ts", output + "\n};");
59+
fs.writeFileSync("src/abap.ts", output + "\n};");
60+
for (const filename in files) {
61+
fs.writeFileSync(path.join("input", filename), files[filename]);
62+
}

abap_transpile.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"input_folder": "input",
3+
"input_filter": [],
4+
"output_folder": "output",
5+
"libs": [],
6+
"write_unit_tests": false,
7+
"write_source_map": false,
8+
"options": {
9+
"ignoreSyntaxCheck": false,
10+
"addFilenames": true,
11+
"addCommonJS": true,
12+
"unknownTypes": "runtimeError",
13+
"skip": []
14+
}
15+
}

examples.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as fs from "node:fs";
2+
import {initializeABAP} from "./output/init.mjs";
3+
await initializeABAP();
4+
5+
console.log("Running examples.mjs");
6+
7+
const excel = await abap.Classes["ZCL_EXCEL_DEMO1"].zif_excel_demo_output$run();
8+
9+
const writer = new abap.Classes["ZCL_EXCEL_WRITER_2007"]();
10+
await writer.constructor_();
11+
12+
const xstring = await writer.zif_excel_writer$write_file({io_excel: excel});
13+
14+
fs.writeFileSync("public/zcl_excel_demo1.xlsx", Buffer.from(xstring.get(), "hex"));

package-lock.json

Lines changed: 21 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
"clone": "npm run clone1 && npm run clone2 && npm run clone3",
1111
"dev": "webpack serve --mode development --env development",
1212
"webpack": "webpack",
13-
"test": "npm run clone && node abap.mjs && npm run webpack"
13+
"transpile": "abap_transpile abap_transpile.json",
14+
"test": "npm run clone && rm -rf input && mkdir input && node abap.mjs && npm run transpile && node examples.mjs && npm run webpack"
1415
},
1516
"author": "",
1617
"license": "MIT",
1718
"devDependencies": {
1819
"@abaplint/monaco": "^2.113.6",
19-
"@abaplint/runtime": "^2.10.15",
20-
"@abaplint/transpiler": "^2.10.15",
20+
"@abaplint/runtime": "^2.10.16",
21+
"@abaplint/transpiler": "^2.10.16",
22+
"@abaplint/transpiler-cli": "^2.10.16",
2123
"buffer": "^6.0.3",
2224
"copy-webpack-plugin": "^12.0.2",
2325
"crypto-browserify": "^3.12.0",

public/demo1.xlsx

-5.84 KB
Binary file not shown.

public/zcl_excel_demo1.xlsx

6.18 KB
Binary file not shown.

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
global.MonacoEnvironment = {
33
globalAPI: true,
44
getWorkerUrl: function (_moduleId: any, label: any) {
5+
/*
56
if (label === "json") {
67
return "./json.worker.bundle.js";
78
}
89
if (label === "typescript" || label === "javascript") {
910
return "./ts.worker.bundle.js";
1011
}
12+
*/
1113
return "./editor.worker.bundle.js";
1214
},
1315
};
@@ -96,7 +98,7 @@ async function abapChanged() {
9698
abapMonaco.updateMarkers(reg, model1);
9799

98100
if (contents === abapfiles[top]) {
99-
document.getElementById("container2").innerHTML = `<iframe src="https://view.officeapps.live.com/op/view.aspx?src=https://abap2xlsx.github.io/abap2xlsx-web/demo1.xlsx" title="Excel"></iframe>`;
101+
document.getElementById("container2").innerHTML = `<iframe src="https://view.officeapps.live.com/op/view.aspx?src=https://abap2xlsx.github.io/abap2xlsx-web/zcl_excel_demo1.xlsx" title="Excel"></iframe>`;
100102

101103
setTimeout(() => monaco.editor.getEditors()[0].focus(), 1000);
102104
} else {

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = {
7777
}),
7878
new CopyPlugin({
7979
patterns: [
80-
{ from: "./public/demo1.xlsx", to: "demo1.xlsx" },
80+
{ from: "./public/*.xlsx", to: "[name].xlsx" },
8181
],
8282
}),
8383
],

0 commit comments

Comments
 (0)