@jelou/cli 0.1.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/bin/jelou ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { existsSync } = require("fs");
4
+ const { join } = require("path");
5
+ const { execFileSync } = require("child_process");
6
+
7
+ const ext = process.platform === "win32" ? ".exe" : "";
8
+ const bin = join(__dirname, `jelou${ext}`);
9
+
10
+ if (!existsSync(bin)) {
11
+ console.error(
12
+ "jelou binary not found. Try reinstalling:\n\n" +
13
+ " npm install -g @jelou/cli\n"
14
+ );
15
+ process.exit(1);
16
+ }
17
+
18
+ try {
19
+ execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
20
+ } catch (err) {
21
+ if (err.status !== undefined) process.exit(err.status);
22
+ throw err;
23
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@jelou/cli",
3
+ "version": "0.1.0",
4
+ "description": "Jelou Functions CLI — deploy serverless TypeScript functions to the edge",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/JelouLatam/jelou-functions-api.git",
9
+ "directory": "packages/cli"
10
+ },
11
+ "homepage": "https://jelou.ai",
12
+ "bin": {
13
+ "jelou": "bin/jelou"
14
+ },
15
+ "scripts": {
16
+ "postinstall": "node scripts/postinstall.js"
17
+ },
18
+ "files": [
19
+ "bin/",
20
+ "scripts/",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "keywords": [
25
+ "jelou",
26
+ "serverless",
27
+ "functions",
28
+ "cli",
29
+ "deploy",
30
+ "edge",
31
+ "typescript",
32
+ "deno"
33
+ ],
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } = require("fs");
4
+ const { join } = require("path");
5
+ const https = require("https");
6
+ const { execSync } = require("child_process");
7
+
8
+ const pkg = require("../package.json");
9
+ const VERSION = pkg.version;
10
+ const REPO = "JelouLatam/jelou-functions-api";
11
+ const BIN_DIR = join(__dirname, "..", "bin");
12
+ const BIN_PATH = join(BIN_DIR, process.platform === "win32" ? "jelou.exe" : "jelou");
13
+
14
+ const PLATFORM_MAP = {
15
+ "darwin-arm64": "jelou-aarch64-apple-darwin",
16
+ "darwin-x64": "jelou-x86_64-apple-darwin",
17
+ "linux-x64": "jelou-x86_64-unknown-linux-gnu",
18
+ "linux-arm64": "jelou-aarch64-unknown-linux-gnu",
19
+ "win32-x64": "jelou-x86_64-pc-windows-msvc.exe",
20
+ };
21
+
22
+ function getAssetName() {
23
+ const key = `${process.platform}-${process.arch}`;
24
+ const name = PLATFORM_MAP[key];
25
+ if (!name) {
26
+ console.error(
27
+ `@jelou/cli: unsupported platform ${key}.\n` +
28
+ `Supported: ${Object.keys(PLATFORM_MAP).join(", ")}\n` +
29
+ `Install manually from https://github.com/${REPO}/releases`
30
+ );
31
+ process.exit(1);
32
+ }
33
+ return name;
34
+ }
35
+
36
+ function download(url, dest) {
37
+ return new Promise((resolve, reject) => {
38
+ const follow = (url) => {
39
+ https.get(url, { headers: { "User-Agent": "jelou-cli-postinstall" } }, (res) => {
40
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
41
+ follow(res.headers.location);
42
+ return;
43
+ }
44
+ if (res.statusCode !== 200) {
45
+ reject(new Error(`Download failed: HTTP ${res.statusCode} from ${url}`));
46
+ return;
47
+ }
48
+ const file = createWriteStream(dest);
49
+ res.pipe(file);
50
+ file.on("finish", () => file.close(resolve));
51
+ file.on("error", (err) => {
52
+ unlinkSync(dest);
53
+ reject(err);
54
+ });
55
+ }).on("error", reject);
56
+ };
57
+ follow(url);
58
+ });
59
+ }
60
+
61
+ async function main() {
62
+ if (process.env.JELOU_CLI_SKIP_INSTALL) {
63
+ console.log("@jelou/cli: skipping binary download (JELOU_CLI_SKIP_INSTALL)");
64
+ return;
65
+ }
66
+
67
+ const asset = getAssetName();
68
+ const url = `https://github.com/${REPO}/releases/download/cli-v${VERSION}/${asset}`;
69
+
70
+ if (!existsSync(BIN_DIR)) mkdirSync(BIN_DIR, { recursive: true });
71
+
72
+ console.log(`@jelou/cli: downloading ${asset} v${VERSION}...`);
73
+
74
+ try {
75
+ await download(url, BIN_PATH);
76
+ if (process.platform !== "win32") {
77
+ chmodSync(BIN_PATH, 0o755);
78
+ }
79
+ console.log("@jelou/cli: installed successfully");
80
+ } catch (err) {
81
+ console.error(`@jelou/cli: failed to download binary — ${err.message}`);
82
+ console.error(`Download manually from: https://github.com/${REPO}/releases/tag/cli-v${VERSION}`);
83
+ process.exit(0);
84
+ }
85
+ }
86
+
87
+ main();