cloudmock 1.0.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/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # cloudmock
2
+
3
+ Local AWS emulation. 25 services. One command.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npx cloudmock
9
+ ```
10
+
11
+ Or install globally:
12
+
13
+ ```bash
14
+ npm install -g cloudmock
15
+ cloudmock
16
+ ```
17
+
18
+ ## What this does
19
+
20
+ This npm package downloads the pre-built CloudMock binary for your platform
21
+ (macOS, Linux, Windows on arm64/x64) and runs it. The binary is cached at
22
+ `~/.cloudmock/bin/` so subsequent runs start instantly.
23
+
24
+ ## Usage
25
+
26
+ ```bash
27
+ # Start CloudMock
28
+ npx cloudmock
29
+
30
+ # Point your AWS SDK at it
31
+ aws --endpoint-url=http://localhost:4566 s3 ls
32
+ ```
33
+
34
+ ## Links
35
+
36
+ - [Documentation](https://cloudmock.io/docs)
37
+ - [GitHub](https://github.com/neureaux/cloudmock)
38
+ - [License](https://github.com/neureaux/cloudmock/blob/main/LICENSE) (Apache-2.0)
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { chmod, mkdir, stat, writeFile } from "node:fs/promises";
5
+ import { createWriteStream } from "node:fs";
6
+ import { homedir, platform, arch } from "node:os";
7
+ import { join } from "node:path";
8
+ import { pipeline } from "node:stream/promises";
9
+ import { createRequire } from "node:module";
10
+
11
+ const require = createRequire(import.meta.url);
12
+ const { version } = require("../package.json");
13
+
14
+ const REPO = "neureaux/cloudmock";
15
+
16
+ // Map Node.js platform/arch to release binary names.
17
+ const PLATFORM_MAP = {
18
+ darwin: "darwin",
19
+ linux: "linux",
20
+ win32: "windows",
21
+ };
22
+
23
+ const ARCH_MAP = {
24
+ arm64: "arm64",
25
+ x64: "amd64",
26
+ };
27
+
28
+ function getBinaryName() {
29
+ const os = PLATFORM_MAP[platform()];
30
+ const cpu = ARCH_MAP[arch()];
31
+
32
+ if (!os || !cpu) {
33
+ console.error(
34
+ `Unsupported platform: ${platform()} ${arch()}. ` +
35
+ `Supported: darwin/linux/win32 on arm64/x64.`
36
+ );
37
+ process.exit(1);
38
+ }
39
+
40
+ const ext = os === "windows" ? ".exe" : "";
41
+ return `cloudmock-${os}-${cpu}${ext}`;
42
+ }
43
+
44
+ function getCachePath(binaryName) {
45
+ return join(homedir(), ".cloudmock", "bin", `${binaryName}-${version}`);
46
+ }
47
+
48
+ async function exists(path) {
49
+ try {
50
+ await stat(path);
51
+ return true;
52
+ } catch {
53
+ return false;
54
+ }
55
+ }
56
+
57
+ async function download(binaryName, dest) {
58
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${binaryName}`;
59
+
60
+ console.log(`CloudMock v${version} not cached. Downloading...`);
61
+ console.log(` ${url}`);
62
+
63
+ // Ensure cache directory exists.
64
+ await mkdir(join(homedir(), ".cloudmock", "bin"), { recursive: true });
65
+
66
+ let response;
67
+ try {
68
+ response = await fetch(url, { redirect: "follow" });
69
+ } catch (err) {
70
+ console.error(`\nDownload failed: ${err.message}\n`);
71
+ console.error("Alternatives:");
72
+ console.error(" docker run -p 4566:4566 ghcr.io/neureaux/cloudmock");
73
+ console.error(
74
+ " go install github.com/neureaux/cloudmock/cmd/gateway@latest"
75
+ );
76
+ process.exit(1);
77
+ }
78
+
79
+ if (!response.ok) {
80
+ console.error(`\nDownload failed: HTTP ${response.status}`);
81
+ console.error(` URL: ${url}\n`);
82
+ console.error("Alternatives:");
83
+ console.error(" docker run -p 4566:4566 ghcr.io/neureaux/cloudmock");
84
+ console.error(
85
+ " go install github.com/neureaux/cloudmock/cmd/gateway@latest"
86
+ );
87
+ process.exit(1);
88
+ }
89
+
90
+ const fileStream = createWriteStream(dest);
91
+ await pipeline(response.body, fileStream);
92
+
93
+ // Make executable (no-op on Windows).
94
+ if (platform() !== "win32") {
95
+ await chmod(dest, 0o755);
96
+ }
97
+
98
+ console.log(" Done.\n");
99
+ }
100
+
101
+ async function main() {
102
+ const binaryName = getBinaryName();
103
+ const cached = getCachePath(binaryName);
104
+
105
+ if (!(await exists(cached))) {
106
+ await download(binaryName, cached);
107
+ }
108
+
109
+ const child = spawn(cached, process.argv.slice(2), {
110
+ stdio: "inherit",
111
+ });
112
+
113
+ child.on("error", (err) => {
114
+ console.error(`Failed to start CloudMock: ${err.message}`);
115
+ process.exit(1);
116
+ });
117
+
118
+ child.on("exit", (code, signal) => {
119
+ if (signal) {
120
+ process.kill(process.pid, signal);
121
+ } else {
122
+ process.exit(code ?? 1);
123
+ }
124
+ });
125
+ }
126
+
127
+ main();
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "cloudmock",
3
+ "version": "1.0.0",
4
+ "description": "Local AWS emulation. 79 services. One command.",
5
+ "bin": {
6
+ "cloudmock": "bin/cloudmock.mjs"
7
+ },
8
+ "files": [
9
+ "bin/"
10
+ ],
11
+ "license": "Apache-2.0",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/neureaux/cloudmock"
15
+ },
16
+ "keywords": [
17
+ "aws",
18
+ "mock",
19
+ "local",
20
+ "development",
21
+ "testing",
22
+ "s3",
23
+ "dynamodb",
24
+ "lambda"
25
+ ]
26
+ }