npgsqlrest 3.8.0 → 3.9.0

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/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "npgsqlrest",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "Automatic REST API for PostgreSQL Databases Client Build",
5
5
  "scripts": {
6
6
  "postinstall": "node postinstall.js",
7
- "uninstall": "node uninstall.js",
8
- "start": "npx npgsqlrest ./appsettings.json ./npgsqlrest.json"
7
+ "preuninstall": "node uninstall.js",
8
+ "start": "npx npgsqlrest"
9
9
  },
10
10
  "bin": {
11
- "npgsqlrest": "node_modules/.bin/npgsqlrest",
12
- "npgsqlrest-config-copy": "./config-copy.js"
11
+ "npgsqlrest": "./bin/npgsqlrest.js"
13
12
  },
14
13
  "repository": {
15
14
  "type": "git",
package/postinstall.js CHANGED
@@ -5,8 +5,10 @@ const path = require("path");
5
5
  const os = require("os");
6
6
  const https = require("https");
7
7
 
8
- const downloadDir = "../.bin/";
9
- const downloadFrom = "https://github.com/NpgsqlRest/NpgsqlRest/releases/download/v3.8.0/";
8
+ const downloadFrom = "https://github.com/NpgsqlRest/NpgsqlRest/releases/download/v3.9.0/";
9
+
10
+ // Download binary next to this script, not to ../.bin/
11
+ const binDir = path.join(__dirname, "bin");
10
12
 
11
13
  function download(url, to, done) {
12
14
  https.get(url, (response) => {
@@ -15,13 +17,13 @@ function download(url, to, done) {
15
17
  response.pipe(file);
16
18
  file.on("finish", () => {
17
19
  file.close();
18
- console.info(`${to} ...`,);
20
+ console.info(`Downloaded ${path.basename(to)}`);
19
21
  if (done) {
20
22
  done();
21
23
  }
22
24
  });
23
25
  } else if (response.statusCode == 302) {
24
- download(response.headers.location, to);
26
+ download(response.headers.location, to, done);
25
27
  } else {
26
28
  console.error("Error downloading file:", to, response.statusCode, response.statusMessage);
27
29
  }
@@ -33,36 +35,34 @@ function download(url, to, done) {
33
35
  }
34
36
 
35
37
  const osType = os.type();
36
- var downloadFileUrl;
37
- var downloadTo;
38
+ const arch = os.arch();
39
+ var binaryUrl;
40
+ var binaryName;
38
41
 
39
- if (osType === "Windows_NT") {
40
- downloadFileUrl = `${downloadFrom}npgsqlrest-win64.exe`;
41
- downloadTo = `${downloadDir}npgsqlrest.exe`;
42
- } else if (osType === "Linux") {
43
- downloadFileUrl = `${downloadFrom}npgsqlrest-linux64`;
44
- downloadTo = `${downloadDir}npgsqlrest`;
45
- } else if (osType === "Darwin") {
46
- downloadFileUrl = `${downloadFrom}npgsqlrest-osx-arm64`;
47
- downloadTo = `${downloadDir}npgsqlrest`;
42
+ if (osType === "Windows_NT" && arch === "x64") {
43
+ binaryUrl = `${downloadFrom}npgsqlrest-win64.exe`;
44
+ binaryName = "npgsqlrest.exe";
45
+ } else if (osType === "Linux" && arch === "x64") {
46
+ binaryUrl = `${downloadFrom}npgsqlrest-linux64`;
47
+ binaryName = "npgsqlrest";
48
+ } else if (osType === "Linux" && arch === "arm64") {
49
+ binaryUrl = `${downloadFrom}npgsqlrest-linux-arm64`;
50
+ binaryName = "npgsqlrest";
51
+ } else if (osType === "Darwin" && arch === "arm64") {
52
+ binaryUrl = `${downloadFrom}npgsqlrest-osx-arm64`;
53
+ binaryName = "npgsqlrest";
48
54
  } else {
49
- console.error("Unsupported OS detected:", osType);
55
+ console.error(`Unsupported platform: ${osType} ${arch}`);
50
56
  process.exit(1);
51
57
  }
52
58
 
53
- if (!fs.existsSync(path.dirname(downloadTo))) {
54
- fs.mkdirSync(path.dirname(downloadTo), { recursive: true });
59
+ if (!fs.existsSync(binDir)) {
60
+ fs.mkdirSync(binDir, { recursive: true });
55
61
  }
56
62
 
57
- if (fs.existsSync(downloadTo)) {
58
- fs.unlinkSync(downloadTo);
63
+ const binaryPath = path.join(binDir, binaryName);
64
+ if (fs.existsSync(binaryPath)) {
65
+ fs.unlinkSync(binaryPath);
59
66
  }
60
- download(downloadFileUrl, downloadTo);
61
-
62
67
 
63
- downloadFileUrl = `${downloadFrom}appsettings.json`;
64
- downloadTo = "./appsettings.json";
65
- if (fs.existsSync(downloadFileUrl)) {
66
- fs.unlinkSync(downloadFileUrl, downloadTo);
67
- }
68
- download(downloadFileUrl, downloadTo);
68
+ download(binaryUrl, binaryPath);
package/uninstall.js CHANGED
@@ -1,21 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const fs = require("fs");
4
+ const path = require("path");
4
5
  const os = require("os");
5
6
 
6
- const downloadDir = "../.bin/";
7
- const osType = os.type();
7
+ const binDir = path.join(__dirname, "bin");
8
+ const ext = os.type() === "Windows_NT" ? ".exe" : "";
9
+ const binaryPath = path.join(binDir, `npgsqlrest${ext}`);
8
10
 
9
- var downloadTo;
10
-
11
- if (osType === "Windows_NT") {
12
- downloadTo = `${downloadDir}npgsqlrest.exe`;
13
- } else {
14
- downloadTo = `${downloadDir}npgsqlrest`;
15
- }
16
-
17
- if (fs.existsSync(downloadTo)) {
18
- fs.unlinkSync(downloadTo);
11
+ if (fs.existsSync(binaryPath)) {
12
+ fs.unlinkSync(binaryPath);
19
13
  }
20
-
21
-
package/config-copy.js DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
-
6
- // Get the destination directory from the command line arguments, or use the current directory
7
- const destDir = process.argv[2] || process.cwd();
8
-
9
- // Path to the source file
10
- const srcFile = path.join(__dirname, "appsettings.json");
11
-
12
- // Path to the destination file
13
- const destFile = path.join(destDir, "appsettings.json");
14
-
15
- // Copy the file
16
- fs.copyFileSync(srcFile, destFile);
17
-
18
- console.log(`Copied appsettings.json to ${destFile}`);