Skip to content

Commit 06fdfd8

Browse files
committed
feat: move header to header.txt
1 parent 8f01037 commit 06fdfd8

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/main/java/org/densy/scriptify/declaration/ScriptTsDeclarationGenerator.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.densy.scriptify.declaration.util.JavaToTypeScriptConverter;
1010

1111
import java.io.IOException;
12+
import java.io.InputStream;
13+
import java.nio.charset.StandardCharsets;
1214
import java.nio.file.Files;
1315
import java.nio.file.Path;
1416
import java.util.ArrayList;
@@ -30,14 +32,18 @@ public ScriptTsDeclarationGenerator(Script<?> script) {
3032
*
3133
* @return String header
3234
*/
33-
public String getHeader() {
34-
StringBuilder sb = new StringBuilder("/**\n");
35-
sb.append(" * Auto-generated by Scriptify DTS Generator\n");
36-
sb.append(" * https://github.com/DensyDev/Scriptify-DTS-Generator\n");
37-
sb.append(" */\n\n");
38-
return sb.toString();
35+
protected String getHeader() {
36+
try (InputStream is = getClass().getClassLoader().getResourceAsStream("header.txt")) {
37+
if (is == null) {
38+
throw new IllegalStateException("Resource header.txt not found");
39+
}
40+
return new String(is.readAllBytes(), StandardCharsets.UTF_8) + "\n\n";
41+
} catch (Exception e) {
42+
throw new RuntimeException("Failed to load header", e);
43+
}
3944
}
4045

46+
4147
/**
4248
* Generates a declaration of constants and functions.
4349
*
@@ -103,7 +109,7 @@ public String generate() {
103109
*/
104110
public void save(Path path) {
105111
try {
106-
Files.writeString(path, this.generate());
112+
Files.writeString(path, this.generate(), StandardCharsets.UTF_8);
107113
} catch (IOException e) {
108114
throw new RuntimeException(e);
109115
}

src/main/resources/header.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Auto-generated by Scriptify DTS Generator
3+
* https://github.com/DensyDev/Scriptify-DTS-Generator
4+
*/

0 commit comments

Comments
 (0)