pgai 0.14.0-beta.10
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.
- package/README.md +21 -0
- package/bin/pgai.ts +66 -0
- package/dist/bin/pgai.js +53 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# pgai
|
|
2
|
+
|
|
3
|
+
`pgai` is a thin wrapper around the [`postgresai`](../cli/README.md) CLI, intended to provide a short command name.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Run without installing:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx pgai --help
|
|
11
|
+
npx pgai prepare-db postgresql://admin@host:5432/dbname
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This is equivalent to:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx postgresai --help
|
|
18
|
+
npx postgresai prepare-db postgresql://admin@host:5432/dbname
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
|
package/bin/pgai.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import { resolve, dirname } from "path";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
|
|
13
|
+
function die(msg: string): never {
|
|
14
|
+
process.stderr.write(`${msg}\n`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let target: string;
|
|
19
|
+
// isTsFile determines runtime: true = use bun (for .ts), false = use node (for .js)
|
|
20
|
+
let isTsFile = false;
|
|
21
|
+
|
|
22
|
+
// Try to find the postgresai package
|
|
23
|
+
try {
|
|
24
|
+
// Resolve the exported "cli" entry point from the postgresai package.
|
|
25
|
+
// This uses the exports field which is the proper way to resolve ESM packages.
|
|
26
|
+
target = require.resolve("postgresai/cli");
|
|
27
|
+
isTsFile = target.endsWith(".ts");
|
|
28
|
+
} catch {
|
|
29
|
+
// Dev-friendly fallback when running from the monorepo checkout (postgresai lives under ../cli).
|
|
30
|
+
const fallbackJs = resolve(__dirname, "..", "..", "cli", "dist", "bin", "postgres-ai.js");
|
|
31
|
+
const fallbackTs = resolve(__dirname, "..", "..", "cli", "bin", "postgres-ai.ts");
|
|
32
|
+
|
|
33
|
+
if (existsSync(fallbackJs)) {
|
|
34
|
+
target = fallbackJs;
|
|
35
|
+
} else if (existsSync(fallbackTs)) {
|
|
36
|
+
target = fallbackTs;
|
|
37
|
+
isTsFile = true;
|
|
38
|
+
} else {
|
|
39
|
+
die(
|
|
40
|
+
[
|
|
41
|
+
"pgai: failed to locate postgresai package.",
|
|
42
|
+
"",
|
|
43
|
+
"This wrapper expects postgresai to be installed as a dependency.",
|
|
44
|
+
].join("\n")
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Determine if we should use node or bun based on the file extension
|
|
50
|
+
const runtime = isTsFile ? "bun" : process.execPath;
|
|
51
|
+
|
|
52
|
+
const child = spawn(runtime, [target, ...process.argv.slice(2)], {
|
|
53
|
+
stdio: "inherit",
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
child.on("exit", (code, signal) => {
|
|
57
|
+
if (signal) {
|
|
58
|
+
process.kill(process.pid, signal);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
process.exit(code ?? 0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
child.on("error", (err) => {
|
|
65
|
+
die(`pgai: failed to run postgresai: ${err instanceof Error ? err.message : String(err)}`);
|
|
66
|
+
});
|
package/dist/bin/pgai.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// bin/pgai.ts
|
|
5
|
+
import { spawn } from "child_process";
|
|
6
|
+
import { resolve, dirname } from "path";
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
import { createRequire } from "module";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
11
|
+
var __dirname2 = dirname(__filename2);
|
|
12
|
+
var require2 = createRequire(import.meta.url);
|
|
13
|
+
function die(msg) {
|
|
14
|
+
process.stderr.write(`${msg}
|
|
15
|
+
`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
var target;
|
|
19
|
+
var isTsFile = false;
|
|
20
|
+
try {
|
|
21
|
+
target = require2.resolve("postgresai/cli");
|
|
22
|
+
isTsFile = target.endsWith(".ts");
|
|
23
|
+
} catch {
|
|
24
|
+
const fallbackJs = resolve(__dirname2, "..", "..", "cli", "dist", "bin", "postgres-ai.js");
|
|
25
|
+
const fallbackTs = resolve(__dirname2, "..", "..", "cli", "bin", "postgres-ai.ts");
|
|
26
|
+
if (existsSync(fallbackJs)) {
|
|
27
|
+
target = fallbackJs;
|
|
28
|
+
} else if (existsSync(fallbackTs)) {
|
|
29
|
+
target = fallbackTs;
|
|
30
|
+
isTsFile = true;
|
|
31
|
+
} else {
|
|
32
|
+
die([
|
|
33
|
+
"pgai: failed to locate postgresai package.",
|
|
34
|
+
"",
|
|
35
|
+
"This wrapper expects postgresai to be installed as a dependency."
|
|
36
|
+
].join(`
|
|
37
|
+
`));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var runtime = isTsFile ? "bun" : process.execPath;
|
|
41
|
+
var child = spawn(runtime, [target, ...process.argv.slice(2)], {
|
|
42
|
+
stdio: "inherit"
|
|
43
|
+
});
|
|
44
|
+
child.on("exit", (code, signal) => {
|
|
45
|
+
if (signal) {
|
|
46
|
+
process.kill(process.pid, signal);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
process.exit(code ?? 0);
|
|
50
|
+
});
|
|
51
|
+
child.on("error", (err) => {
|
|
52
|
+
die(`pgai: failed to run postgresai: ${err instanceof Error ? err.message : String(err)}`);
|
|
53
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pgai",
|
|
3
|
+
"version": "0.14.0-beta.10",
|
|
4
|
+
"description": "Thin wrapper for postgresai CLI (provides `npx pgai ...` or `bunx pgai ...`)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"private": false,
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://gitlab.com/postgres-ai/postgres_ai.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://gitlab.com/postgres-ai/postgres_ai",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://gitlab.com/postgres-ai/postgres_ai/-/issues"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"pgai": "./dist/bin/pgai.js"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "bun build ./bin/pgai.ts --outdir ./dist/bin --target node && node -e \"const fs=require('fs');const f='./dist/bin/pgai.js';fs.writeFileSync(f,fs.readFileSync(f,'utf8').replace('#!/usr/bin/env bun','#!/usr/bin/env node'))\"",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"postgresai": "0.14.0-beta.10"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/bun": "^1.1.14"
|
|
31
|
+
}
|
|
32
|
+
}
|