add generator for futur-lazy

This commit is contained in:
WhatCats
2025-01-06 23:08:59 +01:00
parent 4236adbd9e
commit 6174193145
11 changed files with 595 additions and 188 deletions

Binary file not shown.

View File

@@ -0,0 +1,33 @@
const PACKAGE = "src/main/java/dev/tommyjs/futur"
const SIGNAL = "// Generated delegates to static factory"
const regex = /( {4}\/\*\*.+?)?((?:\S| )+? )(\S+)(\(.*?\))(?: {.+?}|;)/gs
const content = await Bun.file(`../../futur-api/${PACKAGE}/promise/PromiseFactory.java`).text()
const methods = [""]
for (const match of content.matchAll(regex)) {
let [_, docs, head, name, params] = match
head = head.trimStart()
if (head.startsWith("static")) continue
if (head.startsWith("default")) head = head.slice(8);
const args = Array.from(params.matchAll(/ ([a-zA-Z1-9]+)[,)]/gs))
.map(v => v[1]).join(", ")
methods.push(
[
`${docs} public static ${head}${name}${params} {`,
` return factory.${name}(${args});`,
" }"
].join("\n")
)
}
const output = Bun.file(`../${PACKAGE}/lazy/Promises.java`)
const existing = await output.text()
const cutIndex = existing.indexOf(SIGNAL) + SIGNAL.length;
const newContent = existing.slice(0, cutIndex) + methods.join("\n\n") + "\n\n}"
await Bun.write(output, newContent)

View File

@@ -0,0 +1,11 @@
{
"name": "generate-promises",
"module": "index.ts",
"type": "module",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "latest"
}
}

View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}