git-stack-cli 0.5.1 → 0.5.2

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.
@@ -3,7 +3,9 @@ import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import * as Ink from "ink";
5
5
  import { cli } from "../core/cli.js";
6
+ import { fetch_json } from "../core/fetch_json.js";
6
7
  import { read_json } from "../core/read_json.js";
8
+ import { semver_compare } from "../core/semver_compare.js";
7
9
  import { sleep } from "../core/sleep.js";
8
10
  import { Brackets } from "./Brackets.js";
9
11
  import { FormatText } from "./FormatText.js";
@@ -41,13 +43,12 @@ export function AutoUpdate(props) {
41
43
  handle_output(React.createElement(Ink.Text, { key: "init", dimColor: true }, "Checking for latest version..."));
42
44
  }
43
45
  const timeout_ms = 2 * 1000;
44
- const npm_res = await Promise.race([
45
- fetch(`https://registry.npmjs.org/${props.name}`),
46
+ const npm_json = await Promise.race([
47
+ fetch_json(`https://registry.npmjs.org/${props.name}`),
46
48
  sleep(timeout_ms).then(() => {
47
49
  throw new Error("timeout");
48
50
  }),
49
51
  ]);
50
- const npm_json = await npm_res.json();
51
52
  latest_version = npm_json?.["dist-tags"]?.latest;
52
53
  if (!latest_version) {
53
54
  throw new Error("unable to retrieve latest version from npm");
@@ -119,29 +120,3 @@ export function AutoUpdate(props) {
119
120
  output,
120
121
  status));
121
122
  }
122
- // returns +1 if version_a is greater than version_b
123
- // returns -1 if version_a is less than version_b
124
- // returns +0 if version_a is exactly equal to version_b
125
- //
126
- // Examples
127
- //
128
- // semver_compare("0.1.1", "0.0.2"); // 1
129
- // semver_compare("1.0.1", "0.0.2"); // 1
130
- // semver_compare("0.0.1", "1.0.2"); // -1
131
- // semver_compare("0.0.1", "0.1.2"); // -1
132
- // semver_compare("1.0.1", "1.0.1"); // 0
133
- //
134
- function semver_compare(version_a, version_b) {
135
- const split_a = version_a.split(".").map(Number);
136
- const split_b = version_b.split(".").map(Number);
137
- const max_split_parts = Math.max(split_a.length, split_b.length);
138
- for (let i = 0; i < max_split_parts; i++) {
139
- const num_a = split_a[i] || 0;
140
- const num_b = split_b[i] || 0;
141
- if (num_a > num_b)
142
- return 1;
143
- if (num_a < num_b)
144
- return -1;
145
- }
146
- return 0;
147
- }
@@ -3,6 +3,7 @@ import * as Ink from "ink";
3
3
  import { cli } from "../core/cli.js";
4
4
  import { is_command_available } from "../core/is_command_available.js";
5
5
  import { match_group } from "../core/match_group.js";
6
+ import { semver_compare } from "../core/semver_compare.js";
6
7
  import { Await } from "./Await.js";
7
8
  import { Command } from "./Command.js";
8
9
  import { Parens } from "./Parens.js";
@@ -23,45 +24,59 @@ export function DependencyCheck(props) {
23
24
  actions.exit(2);
24
25
  } },
25
26
  React.createElement(Await, { fallback: React.createElement(Ink.Text, { color: "yellow" },
26
- React.createElement(Ink.Text, null,
27
- "Checking ",
28
- React.createElement(Command, null, "gh"),
29
- " install...")), function: async () => {
30
- if (is_command_available("gh")) {
27
+ "Checking ",
28
+ React.createElement(Command, null, "node"),
29
+ " install..."), function: async () => {
30
+ const process_version = process.version.substring(1);
31
+ const semver_result = semver_compare(process_version, "14.0.0");
32
+ if (semver_result >= 0) {
31
33
  return;
32
34
  }
33
35
  actions.output(React.createElement(Ink.Text, { color: "yellow" },
34
- React.createElement(Command, null, "gh"),
36
+ React.createElement(Command, null, "node"),
35
37
  " must be installed."));
36
- actions.output(React.createElement(Ink.Text, { color: "yellow" },
37
- React.createElement(Ink.Text, null, "Visit "),
38
- React.createElement(Url, null, "https://cli.github.com"),
39
- React.createElement(Ink.Text, null, " to install the github cli "),
40
- React.createElement(Parens, null,
41
- React.createElement(Command, null, "gh"))));
42
- actions.exit(3);
38
+ actions.exit(2);
43
39
  } },
44
40
  React.createElement(Await, { fallback: React.createElement(Ink.Text, { color: "yellow" },
45
41
  React.createElement(Ink.Text, null,
46
42
  "Checking ",
47
- React.createElement(Command, null, "gh auth status"),
48
- "...")), function: async () => {
49
- const auth_output = await cli(`gh auth status`, {
50
- ignoreExitCode: true,
51
- });
52
- if (auth_output.code === 0) {
53
- const username = match_group(auth_output.stdout, RE.auth_username, "username");
54
- actions.set((state) => {
55
- state.username = username;
56
- });
43
+ React.createElement(Command, null, "gh"),
44
+ " install...")), function: async () => {
45
+ if (is_command_available("gh")) {
57
46
  return;
58
47
  }
59
48
  actions.output(React.createElement(Ink.Text, { color: "yellow" },
60
49
  React.createElement(Command, null, "gh"),
61
- React.createElement(Ink.Text, null, " requires login, please run "),
62
- React.createElement(Command, null, "gh auth login")));
63
- actions.exit(4);
64
- } }, props.children))));
50
+ " must be installed."));
51
+ actions.output(React.createElement(Ink.Text, { color: "yellow" },
52
+ React.createElement(Ink.Text, null, "Visit "),
53
+ React.createElement(Url, null, "https://cli.github.com"),
54
+ React.createElement(Ink.Text, null, " to install the github cli "),
55
+ React.createElement(Parens, null,
56
+ React.createElement(Command, null, "gh"))));
57
+ actions.exit(3);
58
+ } },
59
+ React.createElement(Await, { fallback: React.createElement(Ink.Text, { color: "yellow" },
60
+ React.createElement(Ink.Text, null,
61
+ "Checking ",
62
+ React.createElement(Command, null, "gh auth status"),
63
+ "...")), function: async () => {
64
+ const auth_status = await cli(`gh auth status`, {
65
+ ignoreExitCode: true,
66
+ });
67
+ if (auth_status.code === 0) {
68
+ const username = match_group(auth_status.stdout, RE.auth_username, "username");
69
+ actions.set((state) => {
70
+ state.username = username;
71
+ });
72
+ return;
73
+ }
74
+ actions.output(React.createElement(Ink.Text, { color: "yellow" },
75
+ React.createElement(Command, null, "gh"),
76
+ React.createElement(Ink.Text, null, " requires login, please run "),
77
+ React.createElement(Command, null, "gh auth login")));
78
+ actions.exit(4);
79
+ } }, props.children)))));
65
80
  }
66
81
  const RE = {
67
82
  // Logged in to github.com as magus
@@ -54,7 +54,7 @@ export function MultiSelect(props) {
54
54
  }, [selected_set]);
55
55
  Ink.useInput((_input, key) => {
56
56
  if (props.disabled) {
57
- console.debug("[MultiSelect] disabled, ignoring input");
57
+ // console.debug("[MultiSelect] disabled, ignoring input");
58
58
  return;
59
59
  }
60
60
  if (key.return) {
@@ -0,0 +1,24 @@
1
+ import https from "node:https";
2
+ export async function fetch_json(url) {
3
+ return new Promise((resolve, reject) => {
4
+ https
5
+ .get(url, (res) => {
6
+ let data = "";
7
+ res.on("data", (chunk) => {
8
+ data += chunk;
9
+ });
10
+ res.on("end", () => {
11
+ try {
12
+ const json = JSON.parse(data);
13
+ resolve(json);
14
+ }
15
+ catch (error) {
16
+ reject(error);
17
+ }
18
+ });
19
+ })
20
+ .on("error", (error) => {
21
+ reject(error);
22
+ });
23
+ });
24
+ }
@@ -0,0 +1,26 @@
1
+ // returns +1 if version_a is greater than version_b
2
+ // returns -1 if version_a is less than version_b
3
+ // returns +0 if version_a is exactly equal to version_b
4
+ //
5
+ // Examples
6
+ //
7
+ // semver_compare("0.1.1", "0.0.2"); // 1
8
+ // semver_compare("1.0.1", "0.0.2"); // 1
9
+ // semver_compare("0.0.1", "1.0.2"); // -1
10
+ // semver_compare("0.0.1", "0.1.2"); // -1
11
+ // semver_compare("1.0.1", "1.0.1"); // 0
12
+ //
13
+ export function semver_compare(version_a, version_b) {
14
+ const split_a = version_a.split(".").map(Number);
15
+ const split_b = version_b.split(".").map(Number);
16
+ const max_split_parts = Math.max(split_a.length, split_b.length);
17
+ for (let i = 0; i < max_split_parts; i++) {
18
+ const num_a = split_a[i] || 0;
19
+ const num_b = split_b[i] || 0;
20
+ if (num_a > num_b)
21
+ return 1;
22
+ if (num_a < num_b)
23
+ return -1;
24
+ }
25
+ return 0;
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-stack-cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "",
5
5
  "author": "magus",
6
6
  "license": "MIT",