forge-sql-orm 1.0.11 → 1.0.12
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/dist-cli/forgeSqlCLI.js +28 -17
- package/package.json +1 -1
package/dist-cli/forgeSqlCLI.js
CHANGED
|
@@ -4,36 +4,47 @@ const path = require("path");
|
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const os = require("os");
|
|
6
6
|
|
|
7
|
-
// Get
|
|
7
|
+
// Get CLI arguments (excluding "node" and script path)
|
|
8
8
|
const args = process.argv.slice(2).join(" ");
|
|
9
9
|
|
|
10
|
-
// Resolve the path to cli.ts
|
|
10
|
+
// Resolve the path to cli.ts (your TypeScript entry file)
|
|
11
11
|
const cliPath = path.resolve(__dirname, "cli.js");
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
|
|
13
|
+
// Detect platform-specific `ts-node` binary paths
|
|
14
|
+
const localTsNode = path.resolve(__dirname, "../node_modules/.bin/ts-node") + (os.platform() === "win32" ? ".cmd" : "");
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
if (os.platform() === "win32") {
|
|
18
|
-
localTsNode += ".cmd";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Function to execute a shell command
|
|
16
|
+
// Function to run a command
|
|
22
17
|
const runCommand = (cmd) => {
|
|
23
18
|
try {
|
|
24
|
-
// Execute the command with inherited stdio for proper CLI output
|
|
25
19
|
execSync(cmd, { stdio: "inherit", shell: true });
|
|
26
|
-
process.exit(0);
|
|
20
|
+
process.exit(0);
|
|
27
21
|
} catch (e) {
|
|
28
22
|
console.error("⚠️ Command execution failed:", e.message);
|
|
29
|
-
process.exit(1);
|
|
23
|
+
process.exit(1);
|
|
30
24
|
}
|
|
31
25
|
};
|
|
32
26
|
|
|
33
|
-
//
|
|
27
|
+
// **1. Check if `ts-node` is globally installed**
|
|
28
|
+
const isGlobalTsNodeInstalled = (() => {
|
|
29
|
+
try {
|
|
30
|
+
execSync("ts-node --version", { stdio: "ignore" }); // Check if `ts-node` runs without error
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
|
|
37
|
+
if (isGlobalTsNodeInstalled) {
|
|
38
|
+
console.log("✅ Using global ts-node");
|
|
39
|
+
runCommand(`ts-node ${cliPath} ${args}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// **2. If not, check for local ts-node**
|
|
34
43
|
if (fs.existsSync(localTsNode)) {
|
|
44
|
+
console.log("✅ Using local ts-node");
|
|
35
45
|
runCommand(`"${localTsNode}" ${cliPath} ${args}`);
|
|
36
|
-
} else {
|
|
37
|
-
console.warn("⚠️ Local ts-node not found, trying npx ts-node...");
|
|
38
|
-
runCommand(`npx ts-node ${cliPath} ${args}`);
|
|
39
46
|
}
|
|
47
|
+
|
|
48
|
+
// **3. If neither found, fallback to npx**
|
|
49
|
+
console.warn("⚠️ Neither global nor local ts-node found, using npx...");
|
|
50
|
+
runCommand(`npx ts-node ${cliPath} ${args}`);
|