@railway/cli 0.2.51 → 1.1.3

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 CHANGED
@@ -25,6 +25,12 @@ brew install railway
25
25
  npm i -g @railway/cli
26
26
  ```
27
27
 
28
+ ### Yarn
29
+
30
+ ```shell
31
+ yarn add global @railway/cli
32
+ ```
33
+
28
34
  ### curl
29
35
 
30
36
  ```shell
package/bin/railway.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { execFileSync } from "child_process";
3
+ import path from "path";
4
+ import { exit } from "process";
5
+ import { fileURLToPath } from "url";
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ try {
11
+ execFileSync(path.resolve(`${__dirname}/railway`), process.argv.slice(2), {
12
+ stdio: "inherit",
13
+ });
14
+ } catch (e) {
15
+ exit(1)
16
+ }
17
+
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Global configuration
3
+ */
4
+ export const CONFIG = {
5
+ /**
6
+ * The name of the binary
7
+ * @type {string}
8
+ */
9
+ name: "railway",
10
+
11
+ /**
12
+ * Where to save the unzipped files
13
+ * @type {string}
14
+ */
15
+ path: "./bin",
16
+
17
+ /**
18
+ * The URL to download the binary form
19
+ *
20
+ * - `{{arch}}` is one of the Golang achitectures listed below
21
+ * - `{{bin_name}}` is the name declared above
22
+ * - `{{platform}}` is one of the Golang platforms listed below
23
+ * - `{{version}}` is the version number as `0.0.0` (taken from package.json)
24
+ *
25
+ * @type {string}
26
+ */
27
+ url: "https://github.com/railwayapp/cli/releases/download/v{{version}}/{{bin_name}}_{{version}}_{{platform}}_{{arch}}.tar.gz",
28
+ };
29
+
30
+ /**
31
+ * Mapping from Node's `process.arch` to Golang's `$GOARCH`
32
+ */
33
+ export const ARCH_MAPPING = {
34
+ ia32: "386",
35
+ x64: "amd64",
36
+ // Re-add when railwayapp/cli#173 gets merged
37
+ // arm: "arm",
38
+ arm64: "arm64",
39
+ };
40
+
41
+ /**
42
+ * Mapping between Node's `process.platform` to Golang's
43
+ */
44
+ export const PLATFORM_MAPPING = {
45
+ darwin: "darwin",
46
+ linux: "linux",
47
+ win32: "windows",
48
+ // freebsd: "freebsd",
49
+ };
@@ -0,0 +1,56 @@
1
+ import { createWriteStream } from "fs";
2
+ import * as fs from "fs/promises";
3
+ import fetch from "node-fetch";
4
+ import { pipeline } from "stream/promises";
5
+ import tar from "tar";
6
+
7
+ import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js";
8
+
9
+ async function install() {
10
+ const packageJson = await fs.readFile("package.json").then(JSON.parse);
11
+ let version = packageJson.version;
12
+
13
+ if (typeof version !== "string") {
14
+ throw new Error("Missing version in package.json");
15
+ }
16
+
17
+ if (version[0] === "v") version = version.slice(1);
18
+
19
+ // Fetch Static Config
20
+ let { name: binName, path: binPath, url } = CONFIG;
21
+
22
+ // Binary name on Windows has .exe suffix
23
+ if (process.platform === "win32") {
24
+ binName += ".exe";
25
+
26
+ url = url.replace(/{{win_ext}}/g, ".exe");
27
+ } else {
28
+ url = url.replace(/{{win_ext}}/g, "");
29
+ }
30
+
31
+ url = url.replace(/{{arch}}/g, ARCH_MAPPING[process.arch]);
32
+ url = url.replace(/{{platform}}/g, PLATFORM_MAPPING[process.platform]);
33
+ url = url.replace(/{{version}}/g, version);
34
+ url = url.replace(/{{bin_name}}/g, binName);
35
+
36
+ const response = await fetch(url);
37
+ if (!response.ok) {
38
+ throw new Error("Failed fetching the binary: " + response.statusText);
39
+ }
40
+
41
+ const tarFile = "downloaded.tar.gz";
42
+
43
+ await fs.mkdir(binPath, { recursive: true });
44
+ await pipeline(response.body, createWriteStream(tarFile));
45
+ await tar.x({ file: tarFile, cwd: binPath });
46
+ await fs.rm(tarFile);
47
+ }
48
+
49
+ install()
50
+ .then(async () => {
51
+ process.exit(0);
52
+ })
53
+ .catch(async (err) => {
54
+ console.error(err);
55
+ process.exit(1);
56
+ });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@railway/cli",
3
- "version": "0.2.51",
3
+ "version": "1.1.3",
4
4
  "description": "Develop and deploy code with zero configuration",
5
- "main": "index.js",
5
+ "type": "module",
6
6
  "author": "Jake Runzer",
7
7
  "license": "ISC",
8
8
  "homepage": "https://github.com/railwayapp/cli/blob/master/README.md",
@@ -10,17 +10,20 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/railwayapp/cli.git"
12
12
  },
13
+ "engines": {
14
+ "node": ">=16.0.0"
15
+ },
13
16
  "scripts": {
14
- "postinstall": "go-npm install",
15
- "preuninstall": "go-npm uninstall"
17
+ "postinstall": "node ./npm-install/postinstall.js"
16
18
  },
17
- "goBinary": {
18
- "name": "railway",
19
- "path": "./bin",
20
- "url": "https://github.com/railwayapp/cli/releases/download/v{{version}}/railway_{{version}}_{{platform}}_{{arch}}.tar.gz"
19
+ "bin": {
20
+ "railway": "bin/railway.js"
21
21
  },
22
- "files": [],
22
+ "files": [
23
+ "npm-install"
24
+ ],
23
25
  "dependencies": {
24
- "go-npm": "^0.1.9"
26
+ "node-fetch": "^3.1.0",
27
+ "tar": "^6.1.11"
25
28
  }
26
29
  }