apimock-rs 4.0.0-rc.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 ADDED
@@ -0,0 +1,7 @@
1
+ # API Mock (apimock-rs)
2
+
3
+ ```sh
4
+ npm install -D apimock-rs
5
+
6
+ npx apimock
7
+ ```
package/index.js ADDED
@@ -0,0 +1,41 @@
1
+ const os = require("os")
2
+ const { spawn } = require("child_process")
3
+
4
+ const binaryName = "apimock"
5
+
6
+ function binaryPath() {
7
+ const platform = os.platform()
8
+ let extension = ""
9
+ switch (platform) {
10
+ case "win32":
11
+ extension = ".exe"
12
+ break
13
+ default:
14
+ }
15
+
16
+ return `${binaryName}${extension}`
17
+ }
18
+
19
+ function spawnBinary(binaryPath) {
20
+ // passing command line arguments to the executable
21
+ const args = process.argv.slice(2)
22
+
23
+ const child = spawn(binPath, args, {
24
+ stdio: "inherit", // sharing std i/o with the parent brings memory efficiency
25
+ })
26
+
27
+ child.on("error", (err) => {
28
+ console.error(`failed to start: ${err.message}`)
29
+ process.exit(1)
30
+ })
31
+
32
+ child.on("exit", (code, signal) => {
33
+ if (signal) {
34
+ console.error(`exit by signal: ${signal}`)
35
+ process.exit(1)
36
+ }
37
+ process.exit(code)
38
+ })
39
+ }
40
+
41
+ spawnBinary(binaryPath())
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "apimock-rs",
3
+ "version": "4.0.0-rc.10",
4
+ "description": "HTTP server generating REST/JSON responses. Aims to be mocking helper to develop microservices and APIs.",
5
+ "author": "nabbisen<nabbisen@scqr.net",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/nabbisen/apimock-rs.git"
10
+ },
11
+ "bin": {
12
+ "apimock": "./index.js"
13
+ },
14
+ "files": [
15
+ "postinstall.js"
16
+ ],
17
+ "scripts": {
18
+ "postinstall": "node postinstall.js"
19
+ },
20
+ "optionalDependencies": {
21
+ "@apimock-rs/linux-x64-gnu": "4.0.0-rc.10",
22
+ "@apimock-rs/darwin-arm64": "4.0.0-rc.10",
23
+ "@apimock-rs/win32-x64-msvc": "4.0.0-rc.10"
24
+ },
25
+ "keywords": [
26
+ "api",
27
+ "mock",
28
+ "server",
29
+ "http",
30
+ "json",
31
+ "route-matching",
32
+ "dynamic-routing",
33
+ "custom-routes",
34
+ "devtool",
35
+ "developer-tool",
36
+ "testing",
37
+ "stub",
38
+ "simulate"
39
+ ]
40
+ }
package/postinstall.js ADDED
@@ -0,0 +1,55 @@
1
+ const fs = require("fs")
2
+ const os = require("os")
3
+ const path = require("path")
4
+
5
+ function srcDestBinaryPath() {
6
+ const platform = os.platform()
7
+
8
+ let targetPackage = null
9
+ let binaryName = "apimock"
10
+ let extension = ""
11
+
12
+ switch (platform) {
13
+ case "linux":
14
+ targetPackage = "bin-linux-x64-gnu"
15
+ break
16
+ case "darwin":
17
+ targetPackage = "bin-darwin-arm64"
18
+ break
19
+ case "win32":
20
+ targetPackage = "bin-win32-x64-msvc"
21
+ extension = ".exe"
22
+ break
23
+ default:
24
+ console.error(`Unsupported platform: ${platform}`)
25
+ process.exit(1)
26
+ }
27
+
28
+ const binDir = __dirname
29
+ const srcDir = path.join(binDir, "..", targetPackage)
30
+ const srcBinary = path.join(srcDir, `${binaryName}${extension}`)
31
+ const destBinary = path.join(binDir, `${binaryName}${extension}`)
32
+
33
+ return [srcBinary, destBinary]
34
+ }
35
+
36
+ function linkOrCopy(src, dest) {
37
+ try {
38
+ if (fs.existsSync(dest)) {
39
+ fs.rmSync(dest, { force: true })
40
+ }
41
+
42
+ // Try symbolic link first
43
+ fs.symlinkSync(src, dest, "file")
44
+ console.log(`linked ${src} --> ${dest}`)
45
+ } catch (e) {
46
+ // Fallback to file copy
47
+ console.warn(`symlink failed (${e.message}), falling back to copy.`)
48
+ fs.copyFileSync(src, dest)
49
+ fs.chmodSync(dest, 0o755)
50
+ console.log(`copied ${src} --> ${dest}`)
51
+ }
52
+ }
53
+
54
+ const [srcBinary, destBinary] = srcDestBinaryPath()
55
+ linkOrCopy(srcBinary, destBinary)