infraflow 0.0.0-stage → 0.1.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.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # infraflow
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The [InfraFlow](https://infraflow.app) command line.
4
+
5
+ ```sh
6
+ npm install -g infraflow # or: npx infraflow <command>
7
+ ```
8
+
9
+ No token is needed to install it. What you sign in with depends on what you
10
+ want to do, and the two are independent:
11
+
12
+ | To… | Sign in with | Command |
13
+ | --- | --- | --- |
14
+ | deploy, read logs, open a shell, change variables | an API token (Settings, then API tokens) | `infraflow auth <token>` |
15
+ | expose services of this machine through tunnels | a machine token (Tunnels, then Add a machine) | `infraflow login <token>` |
16
+
17
+ ```sh
18
+ infraflow auth ifl_…
19
+ infraflow up api # send this folder, build it, deploy it
20
+ infraflow link api # this folder is `api` from now on
21
+ infraflow run -- npm run dev # run locally with the service's variables
22
+ infraflow logs --follow
23
+ infraflow shell
24
+ ```
25
+
26
+ The program is a single native file. This package fetches the one for your
27
+ system the first time it runs, from `https://infraflow.app/dl/`. Set
28
+ `INFRAFLOW_ORIGIN` to use another InfraFlow platform, and `INFRAFLOW_REFETCH=1`
29
+ to fetch it again.
30
+
31
+ Without Node.js:
32
+
33
+ ```sh
34
+ curl -fsSL https://infraflow.app/install.sh | sh # Linux, macOS
35
+ irm https://infraflow.app/install.ps1 | iex # Windows
36
+ ```
37
+
38
+ Documentation: <https://infraflow.app/docs/cli>
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ // Runs the InfraFlow program. The program itself is a single native file:
3
+ // it is fetched the first time, for this system, from the platform that
4
+ // publishes it, and kept beside this script.
5
+ //
6
+ // Fetching at first run rather than at install means it also works with
7
+ // package managers that do not run install scripts.
8
+
9
+ const { spawnSync } = require("node:child_process");
10
+ const fs = require("node:fs");
11
+ const os = require("node:os");
12
+ const path = require("node:path");
13
+
14
+ const ORIGIN = (
15
+ process.env.INFRAFLOW_ORIGIN || "https://infraflow.app"
16
+ ).replace(/\/+$/, "");
17
+
18
+ const SYSTEMS = { darwin: "darwin", linux: "linux", win32: "windows" };
19
+ const PROCESSORS = { x64: "x86_64", arm64: "aarch64" };
20
+
21
+ function asset() {
22
+ const system = SYSTEMS[process.platform];
23
+ const processor = PROCESSORS[process.arch];
24
+ if (
25
+ !system ||
26
+ !processor ||
27
+ (system === "windows" && processor !== "x86_64")
28
+ ) {
29
+ throw new Error(
30
+ `no InfraFlow build exists for ${process.platform} on ${process.arch}`,
31
+ );
32
+ }
33
+ return `infraflow-${system}-${processor}${system === "windows" ? ".exe" : ""}`;
34
+ }
35
+
36
+ /** Where the program is kept: beside this script, or the user's cache when
37
+ * the package's folder cannot be written to (a global install as root). */
38
+ function home(name) {
39
+ const beside = path.join(__dirname, name);
40
+ try {
41
+ fs.accessSync(__dirname, fs.constants.W_OK);
42
+ return beside;
43
+ } catch {
44
+ const cache = path.join(os.homedir(), ".cache", "infraflow");
45
+ fs.mkdirSync(cache, { recursive: true });
46
+ return path.join(cache, name);
47
+ }
48
+ }
49
+
50
+ async function fetched(name, target) {
51
+ const url = `${ORIGIN}/dl/${name}`;
52
+ process.stderr.write(`Fetching ${url}\n`);
53
+ const response = await fetch(url, { redirect: "follow" });
54
+ if (!response.ok) {
55
+ throw new Error(
56
+ `${url} answered ${response.status}: no build is published for this system`,
57
+ );
58
+ }
59
+ const bytes = Buffer.from(await response.arrayBuffer());
60
+ // Written aside, then moved: a download cut short is never run.
61
+ const partial = `${target}.${process.pid}.part`;
62
+ fs.writeFileSync(partial, bytes, { mode: 0o755 });
63
+ fs.renameSync(partial, target);
64
+ }
65
+
66
+ async function main() {
67
+ const name = asset();
68
+ const target = home(name);
69
+ if (!fs.existsSync(target) || process.env.INFRAFLOW_REFETCH) {
70
+ await fetched(name, target);
71
+ }
72
+ const ran = spawnSync(target, process.argv.slice(2), { stdio: "inherit" });
73
+ if (ran.error) throw ran.error;
74
+ process.exit(ran.status ?? 1);
75
+ }
76
+
77
+ main().catch((error) => {
78
+ process.stderr.write(`infraflow: ${error.message}\n`);
79
+ process.exit(1);
80
+ });
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "infraflow",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "The InfraFlow command line: deploy a folder, follow logs, open a shell, expose local services through tunnels.",
5
+ "license": "MIT",
6
+ "homepage": "https://infraflow.app/docs/cli",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/plumsydev/infraflow.git",
10
+ "directory": "packages/cli-npm"
11
+ },
12
+ "keywords": [
13
+ "infraflow",
14
+ "deploy",
15
+ "tunnel",
16
+ "cli"
17
+ ],
18
+ "bin": {
19
+ "infraflow": "bin/infraflow.js"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "README.md"
24
+ ],
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "os": [
29
+ "darwin",
30
+ "linux",
31
+ "win32"
32
+ ],
33
+ "cpu": [
34
+ "x64",
35
+ "arm64"
36
+ ]
37
+ }