git-stack-cli 2.6.1 → 2.7.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.
@@ -0,0 +1,106 @@
1
+ import * as React from "react";
2
+
3
+ import * as Ink from "ink-cjs";
4
+
5
+ import { Await } from "~/app/Await";
6
+ import { FormatText } from "~/app/FormatText";
7
+ import { Store } from "~/app/Store";
8
+ import { command } from "~/command";
9
+ import { colors } from "~/core/colors";
10
+ import { invariant } from "~/core/invariant";
11
+
12
+ export function Config() {
13
+ return <Await fallback={null} function={run} />;
14
+
15
+ async function run() {
16
+ const state = Store.getState();
17
+ const actions = state.actions;
18
+
19
+ const config = await get_explicit_args();
20
+ const config_json = JSON.stringify(config).replace(/"/g, '\\"');
21
+
22
+ actions.output(
23
+ <Ink.Box flexDirection="column" gap={1} paddingTop={1}>
24
+ <Ink.Text></Ink.Text>
25
+
26
+ <FormatText
27
+ message="Add the line below to your shell rc file ({zshrc}, {bashrc}, etc.)"
28
+ values={{
29
+ zshrc: <Ink.Text color={colors.gray}>.zshrc</Ink.Text>,
30
+ bashrc: <Ink.Text color={colors.gray}>.bashrc</Ink.Text>,
31
+ }}
32
+ />
33
+
34
+ <FormatText
35
+ message={`{export} {ENV_VAR}{e}{q}{config_json}{q}`}
36
+ values={{
37
+ export: <Ink.Text color={colors.purple}>export</Ink.Text>,
38
+ ENV_VAR: <Ink.Text color={colors.yellow}>{ENV_VAR}</Ink.Text>,
39
+ e: <Ink.Text color={colors.purple}>{"="}</Ink.Text>,
40
+ q: <Ink.Text color={colors.white}>{'"'}</Ink.Text>,
41
+ config_json: <Ink.Text color={colors.green}>{config_json}</Ink.Text>,
42
+ }}
43
+ />
44
+ </Ink.Box>,
45
+ );
46
+
47
+ actions.exit(0);
48
+ }
49
+ }
50
+
51
+ export async function argv_with_config_from_env() {
52
+ if (!process.env.GIT_STACK_CONFIG) {
53
+ return await command(process.argv);
54
+ }
55
+
56
+ const env_config = parse_env_config();
57
+ return await command(process.argv, { env_config });
58
+ }
59
+
60
+ function parse_env_config() {
61
+ const GIT_STACK_CONFIG = process.env.GIT_STACK_CONFIG;
62
+ invariant(GIT_STACK_CONFIG, "GIT_STACK_CONFIG must exist");
63
+
64
+ try {
65
+ const env_config = JSON.parse(GIT_STACK_CONFIG);
66
+ return env_config;
67
+ } catch (error) {
68
+ // eslint-disable-next-line no-console
69
+ console.error(`ERROR GIT_STACK_CONFIG=${GIT_STACK_CONFIG}`);
70
+ // eslint-disable-next-line no-console
71
+ console.error("ERROR GIT_STACK_CONFIG environment variable is not valid JSON");
72
+ process.exit(18);
73
+ }
74
+ }
75
+
76
+ async function get_explicit_args() {
77
+ const default_argv = await command(["git", "stack"], COMMAND_OPTIONS);
78
+ const state_argv = await command(process.argv, COMMAND_OPTIONS);
79
+
80
+ const config: Record<string, any> = {};
81
+
82
+ // find delta between default_argv and argv
83
+ for (const key of Object.keys(state_argv)) {
84
+ if (key === "_" || key === "$0") continue;
85
+
86
+ const state_value = state_argv[key];
87
+ const default_value = default_argv[key];
88
+ const is_set = default_value !== state_value;
89
+ if (is_set) {
90
+ config[key] = state_value;
91
+ }
92
+ }
93
+
94
+ return config;
95
+ }
96
+
97
+ const ENV_VAR = "GIT_STACK_CONFIG";
98
+
99
+ type CommandOptions = NonNullable<Parameters<typeof command>[1]>;
100
+
101
+ const COMMAND_OPTIONS = {
102
+ parserConfiguration: {
103
+ // Should aliases be removed before returning results? Default is `false`
104
+ "strip-aliased": true,
105
+ },
106
+ } satisfies CommandOptions;
package/src/index.tsx CHANGED
@@ -11,13 +11,13 @@ import * as Ink from "ink-cjs";
11
11
 
12
12
  import { App } from "~/app/App";
13
13
  import { Store } from "~/app/Store";
14
- import { command } from "~/command";
14
+ import { argv_with_config_from_env } from "~/commands/Config";
15
15
  import { get_tmp_dir } from "~/core/get_tmp_dir";
16
16
  import { pretty_json } from "~/core/pretty_json";
17
17
 
18
18
  (async function main() {
19
19
  try {
20
- const argv = await command();
20
+ const argv = await argv_with_config_from_env();
21
21
 
22
22
  // required to get bun working with ink
23
23
  // https://github.com/oven-sh/bun/issues/6862#issuecomment-2429444852
@@ -4,6 +4,6 @@ declare namespace NodeJS {
4
4
  DEV?: "true" | "false";
5
5
  CLI_VERSION?: string;
6
6
  GIT_SEQUENCE_EDITOR_SCRIPT?: string;
7
- GIT_STACK_BRANCH_PREFIX?: string;
7
+ GIT_STACK_CONFIG?: string;
8
8
  }
9
9
  }
@@ -1,5 +0,0 @@
1
- import { short_id } from "~/core/short_id";
2
-
3
- export function gs_short_id() {
4
- return `gs-${short_id()}`;
5
- }