mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
add generator for futur-lazy
This commit is contained in:
BIN
futur-lazy/generator/bun.lockb
Normal file
BIN
futur-lazy/generator/bun.lockb
Normal file
Binary file not shown.
33
futur-lazy/generator/index.ts
Normal file
33
futur-lazy/generator/index.ts
Normal 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)
|
||||
11
futur-lazy/generator/package.json
Normal file
11
futur-lazy/generator/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "generate-promises",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "latest"
|
||||
}
|
||||
}
|
||||
27
futur-lazy/generator/tsconfig.json
Normal file
27
futur-lazy/generator/tsconfig.json
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user