@mtayfur/opencode-prompt-enhancer 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ // Build script: compile TSX to JS using babel + solid preset.
2
+ // The @opentui/solid/bun-plugin doesn't work with bun v1.3.x (no registerBunPlugin),
3
+ // so we use babel directly.
4
+
5
+ import { transformAsync } from "@babel/core"
6
+ import solid from "babel-preset-solid"
7
+ import ts from "@babel/preset-typescript"
8
+ import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs"
9
+ import { dirname, relative, resolve } from "path"
10
+
11
+ const ROOT = resolve(import.meta.dirname, "..")
12
+ const DIST = resolve(ROOT, "dist")
13
+
14
+ function discoverSources(directory) {
15
+ return readdirSync(directory, { withFileTypes: true })
16
+ .flatMap((entry) => {
17
+ const absPath = resolve(directory, entry.name)
18
+
19
+ if (entry.isDirectory()) return discoverSources(absPath)
20
+ if (!entry.isFile() || !/\.tsx?$/.test(entry.name) || entry.name.endsWith(".d.ts")) return []
21
+
22
+ return [{
23
+ path: relative(ROOT, absPath).replaceAll("\\", "/"),
24
+ hasJSX: entry.name.endsWith(".tsx"),
25
+ }]
26
+ })
27
+ .sort((a, b) => a.path.localeCompare(b.path))
28
+ }
29
+
30
+ const SOURCES = discoverSources(resolve(ROOT, "plugins"))
31
+
32
+ async function compile(filePath, hasJSX) {
33
+ const absPath = resolve(ROOT, filePath)
34
+ const code = readFileSync(absPath, "utf8")
35
+
36
+ const presets = hasJSX
37
+ ? [[solid, { moduleName: "@opentui/solid", generate: "universal" }], [ts]]
38
+ : [[ts]]
39
+
40
+ const result = await transformAsync(code, {
41
+ filename: absPath,
42
+ configFile: false,
43
+ babelrc: false,
44
+ presets,
45
+ })
46
+
47
+ if (!result?.code) throw new Error(`No output for ${filePath}`)
48
+
49
+ const outPath = resolve(DIST, filePath.replace(/\.tsx?$/, ".js"))
50
+ mkdirSync(dirname(outPath), { recursive: true })
51
+ writeFileSync(outPath, result.code, "utf8")
52
+ console.log(` ${filePath} → ${outPath}`)
53
+ }
54
+
55
+ console.log("Building prompt-enhancer plugin...\n")
56
+
57
+ try {
58
+ for (const src of SOURCES) {
59
+ await compile(src.path, src.hasJSX)
60
+ }
61
+
62
+ // Create dist/index.js entry point
63
+ const indexPath = resolve(DIST, "index.js")
64
+ writeFileSync(indexPath, `export { default } from "./plugins/prompt-enhancer.js"\n`, "utf8")
65
+ console.log(` index.js (entry) → ${indexPath}`)
66
+
67
+ console.log("\nBuild complete.")
68
+ } catch (err) {
69
+ console.error("Build failed:", err.message)
70
+ process.exit(1)
71
+ }