npgsqlrest 0.0.1

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.
Files changed (2) hide show
  1. package/package.json +27 -0
  2. package/postinstall.js +57 -0
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "npgsqlrest",
3
+ "version": "0.0.1",
4
+ "description": "Automatic REST API for PostgreSQL Databases Client Build",
5
+ "scripts": {
6
+ "postinstall": "node postinstall.js",
7
+ "start": "npx npgsqlrest ./.bin/appsettings.json ./npgsqlrest.json"
8
+ },
9
+ "bin": "./.bin/npgsqlrest.exe",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/vb-consulting/NpgsqlRest.git"
13
+ },
14
+ "keywords": [
15
+ "postgresql",
16
+ "server",
17
+ "rest",
18
+ "api",
19
+ "automatic"
20
+ ],
21
+ "author": "vb-consulting",
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/vb-consulting/NpgsqlRest/issues"
25
+ },
26
+ "homepage": "https://github.com/vb-consulting/NpgsqlRest#readme"
27
+ }
package/postinstall.js ADDED
@@ -0,0 +1,57 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const os = require("os");
4
+ const https = require("https");
5
+
6
+ const downloadDir = "./.bin/";
7
+ const downloadFrom = "https://github.com/vb-consulting/NpgsqlRest/releases/download/v2.7.0/";
8
+
9
+ function download(url, to) {
10
+ https.get(url, (response) => {
11
+ if (response.statusCode == 200) {
12
+ const file = fs.createWriteStream(to);
13
+ response.pipe(file);
14
+ file.on("finish", () => {
15
+ file.close();
16
+ console.info(`${to} ...`,);
17
+ });
18
+ } else if (response.statusCode == 302) {
19
+ download(response.headers.location, to);
20
+ } else {
21
+ console.error("Error downloading file:", to, response.statusCode, response.statusMessage);
22
+ }
23
+ }).on("error", (err) => {
24
+ fs.unlink(to, () => {
25
+ console.error("Error downloading file:", to, err);
26
+ });
27
+ });
28
+ }
29
+
30
+ const osType = os.type();
31
+ var downloadFileUrl;
32
+ var downloadTo;
33
+
34
+ if (osType === "Windows_NT") {
35
+ downloadFileUrl = `${downloadFrom}npgsqlrest-win64.exe`;
36
+ downloadTo = `${downloadDir}npgsqlrest.exe`;
37
+ } else if (osType === "Linux") {
38
+ downloadFileUrl = `${downloadFrom}npgsqlrest-linux64`;
39
+ downloadTo = `${downloadDir}npgsqlrest.exe`;
40
+ } else {
41
+ console.error("Unsupported OS detected:", osType);
42
+ process.exit(1);
43
+ }
44
+
45
+ if (!fs.existsSync(path.dirname(downloadTo))) {
46
+ fs.mkdirSync(path.dirname(downloadTo), { recursive: true });
47
+ }
48
+
49
+ if (!fs.existsSync(downloadTo)) {
50
+ download(downloadFileUrl, downloadTo);
51
+ }
52
+
53
+ downloadFileUrl = `${downloadFrom}appsettings.json`;
54
+ downloadTo = `${downloadDir}appsettings.json`;
55
+ if (!fs.existsSync(downloadTo)) {
56
+ download(downloadFileUrl, downloadTo);
57
+ }