git-stack-cli 0.8.2 → 0.8.4

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.
Files changed (46) hide show
  1. package/dist/__fixtures__/metadata.json +186 -0
  2. package/dist/app/App copy.js +30 -0
  3. package/dist/app/ArgCheck.js +21 -0
  4. package/dist/app/Brackets copy.js +10 -0
  5. package/dist/app/Counter.js +19 -0
  6. package/dist/app/GatherMetadata copy.js +91 -0
  7. package/dist/app/GatherMetadata.js +9 -0
  8. package/dist/app/InitMetadata.js +14 -0
  9. package/dist/app/Input.js +15 -0
  10. package/dist/app/KeepAlive.js +11 -0
  11. package/dist/app/LocalMergeRebase.js +19 -1
  12. package/dist/app/Main copy.js +200 -0
  13. package/dist/app/ManualRebase copy.js +127 -0
  14. package/dist/app/ManualRebase.js +19 -1
  15. package/dist/app/MultiSelect copy.js +76 -0
  16. package/dist/app/NPMAutoUpdate.js +34 -0
  17. package/dist/app/Parens copy.js +9 -0
  18. package/dist/app/PostRebaseStatus copy.js +23 -0
  19. package/dist/app/PreSelectCommitRanges copy.js +21 -0
  20. package/dist/app/SelectCommitRange.js +1 -0
  21. package/dist/app/Status copy.js +46 -0
  22. package/dist/app/Store.js +1 -0
  23. package/dist/app/Url copy.js +6 -0
  24. package/dist/app/YesNoPrompt copy.js +24 -0
  25. package/dist/cli.js +9 -0
  26. package/dist/core/Metadata copy.js +37 -0
  27. package/dist/core/StackTable.js +38 -0
  28. package/dist/core/SummaryTable.js +38 -0
  29. package/dist/core/ZustandStore.js +23 -0
  30. package/dist/core/cli copy.js +44 -0
  31. package/dist/core/color.js +83 -0
  32. package/dist/core/dependency_check.js +27 -0
  33. package/dist/core/exit.js +4 -0
  34. package/dist/core/get_commit_metadata.js +61 -0
  35. package/dist/core/id.js +61 -0
  36. package/dist/core/invariant copy.js +5 -0
  37. package/dist/core/isFiniteValue.js +3 -0
  38. package/dist/core/is_dev.js +1 -0
  39. package/dist/core/readJson.js +3 -0
  40. package/dist/core/serialize_json.js +17 -0
  41. package/dist/core/sleep copy.js +3 -0
  42. package/dist/main copy.js +266 -0
  43. package/dist/main.backup.js +266 -0
  44. package/dist/main.js +265 -0
  45. package/package.json +6 -4
  46. /package/dist/app/{Main.js → main.js} +0 -0
@@ -0,0 +1,200 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ import { v4 as uuid_v4 } from "uuid";
4
+ import * as CommitMetadata from "../core/CommitMetadata.js";
5
+ import * as Metadata from "../core/Metadata.js";
6
+ import { cli } from "../core/cli.js";
7
+ import * as github from "../core/github.js";
8
+ import { invariant } from "../core/invariant.js";
9
+ import { match_group } from "../core/match_group.js";
10
+ import { Await } from "./Await.js";
11
+ import { Exit } from "./Exit.js";
12
+ import { Store } from "./Store.js";
13
+ export function GatherMetadata(props) {
14
+ const argv = Store.useState((state) => state.argv);
15
+ invariant(argv, "argv must exist");
16
+ return (React.createElement(Await, { fallback: null, function: () => gather_metadata({ argv }) }, props.children));
17
+ }
18
+ async function gather_metadata(args) {
19
+ const actions = Store.getState().actions;
20
+ const head = (await cli("git rev-parse HEAD")).stdout;
21
+ const merge_base = (await cli("git merge-base HEAD master")).stdout;
22
+ // handle when there are no detected changes
23
+ if (head === merge_base) {
24
+ actions.newline();
25
+ actions.output(React.createElement(Ink.Text, { color: "gray" }, "No changes detected."));
26
+ actions.output(React.createElement(Exit, { clear: true, code: 0 }));
27
+ return;
28
+ }
29
+ const branch_name = (await cli("git rev-parse --abbrev-ref HEAD")).stdout;
30
+ // git@github.com:magus/git-multi-diff-playground.git
31
+ // https://github.com/magus/git-multi-diff-playground.git
32
+ const origin_url = (await cli(`git config --get remote.origin.url`)).stdout;
33
+ const repo_path = match_group(origin_url, RE.repo_path, "repo_path");
34
+ const commit_metadata_list = await CommitMetadata.all();
35
+ Store.setState((state) => {
36
+ state.head = head;
37
+ state.merge_base = merge_base;
38
+ state.branch_name = branch_name;
39
+ state.repo_path = repo_path;
40
+ state.commit_metadata_list = commit_metadata_list;
41
+ });
42
+ // print_table(repo_path, commit_metadata_list);
43
+ const needs_update = commit_metadata_list.some((meta) => !meta.pr_exists || meta.pr_dirty);
44
+ if (args.argv.check) {
45
+ actions.output(React.createElement(Exit, { clear: true, code: 0 }));
46
+ return;
47
+ }
48
+ if (!args.argv.force && !needs_update) {
49
+ actions.newline();
50
+ actions.output(React.createElement(Ink.Text, null, "\u2705 Everything up to date."));
51
+ actions.output(React.createElement(Ink.Text, { color: "gray" },
52
+ React.createElement(Ink.Text, null, "Run with"),
53
+ React.createElement(Ink.Text, { bold: true, color: "yellow" }, ` --force `),
54
+ React.createElement(Ink.Text, null, "to force update all pull requests.")));
55
+ actions.output(React.createElement(Exit, { clear: true, code: 0 }));
56
+ }
57
+ Store.setState((state) => {
58
+ state.step = "select-commit-ranges";
59
+ });
60
+ }
61
+ async function manual_rebase(args) {
62
+ const temp_branch_name = `${args.branch_name}_${uuid_v4()}`;
63
+ try {
64
+ // create temporary branch based on merge base
65
+ await cli(`git checkout -b ${temp_branch_name} ${args.merge_base}`);
66
+ const picked_commit_metadata_list = [];
67
+ // cherry-pick and amend commits one by one
68
+ for (let i = 0; i < args.commit_metadata_list.length; i++) {
69
+ const sha = args.commit_metadata_list[i].sha;
70
+ let base;
71
+ if (i === 0) {
72
+ base = "master";
73
+ }
74
+ else {
75
+ base = picked_commit_metadata_list[i - 1].metadata.id;
76
+ invariant(base, `metadata must be set on previous commit [${i}]`);
77
+ }
78
+ await cli(`git cherry-pick ${sha}`);
79
+ const commit = await CommitMetadata.commit(sha, base);
80
+ if (!commit.metadata.id) {
81
+ commit.metadata.id = uuid_v4();
82
+ await Metadata.write(commit);
83
+ }
84
+ picked_commit_metadata_list.push(commit);
85
+ // always push to origin since github requires commit shas to line up perfectly
86
+ console.debug();
87
+ console.debug(`Syncing [${commit.metadata.id}] ...`);
88
+ await cli(`git push -f origin HEAD:${commit.metadata.id}`);
89
+ if (commit.pr_exists) {
90
+ // ensure base matches pr in github
91
+ await github.pr_base(commit.metadata.id, base);
92
+ }
93
+ else {
94
+ try {
95
+ // delete metadata id branch if leftover
96
+ await cli(`git branch -D ${commit.metadata.id}`, {
97
+ ignoreExitCode: true,
98
+ });
99
+ // move to temporary branch for creating pr
100
+ await cli(`git checkout -b ${commit.metadata.id}`);
101
+ // create pr in github
102
+ await github.pr_create(commit.metadata.id, base);
103
+ }
104
+ catch (err) {
105
+ console.error("Moving back to temp branch...");
106
+ console.error(err);
107
+ }
108
+ finally {
109
+ // move back to temp branch
110
+ await cli(`git checkout ${temp_branch_name}`);
111
+ // delete metadata id branch if leftover
112
+ await cli(`git branch -D ${commit.metadata.id}`, {
113
+ ignoreExitCode: true,
114
+ });
115
+ }
116
+ }
117
+ }
118
+ // after all commits have been cherry-picked and amended
119
+ // move the branch pointer to the temporary branch (with the metadata)
120
+ await cli(`git branch -f ${args.branch_name} ${temp_branch_name}`);
121
+ }
122
+ catch (err) {
123
+ console.error("Restoring original branch...");
124
+ console.error(err);
125
+ }
126
+ finally {
127
+ // always put self back in original branch
128
+ await cli(`git checkout ${args.branch_name}`);
129
+ // ...and cleanup temporary branch
130
+ await cli(`git branch -D ${temp_branch_name}`, { ignoreExitCode: true });
131
+ }
132
+ // print_table(repo_path, await CommitMetadata.all());
133
+ }
134
+ const RE = {
135
+ // git@github.com:magus/git-multi-diff-playground.git
136
+ // https://github.com/magus/git-multi-diff-playground.git
137
+ repo_path: /(?<repo_path>[^:^/]+\/[^/]+)\.git/,
138
+ };
139
+ // function print_table(
140
+ // repo_path: string,
141
+ // commit_metadata_list: Array<Awaited<ReturnType<typeof CommitMetadata.commit>>>
142
+ // ) {
143
+ // console.debug();
144
+ // for (const args of commit_metadata_list) {
145
+ // print_table_row(repo_path, args);
146
+ // }
147
+ // }
148
+ // function print_table_row(
149
+ // repo_path: string,
150
+ // args: Awaited<ReturnType<typeof CommitMetadata.commit>>
151
+ // ) {
152
+ // let icon;
153
+ // let status;
154
+ // if (!args.pr_exists) {
155
+ // icon = "🌱";
156
+ // status = "NEW";
157
+ // } else if (args.pr_dirty) {
158
+ // icon = "⚠️";
159
+ // status = "OUTDATED";
160
+ // } else {
161
+ // icon = "✅";
162
+ // status = "SYNCED";
163
+ // }
164
+ // // print clean metadata about this commit / branch
165
+ // const parts = [
166
+ // icon,
167
+ // " ",
168
+ // col(status, 10, "left"),
169
+ // col(args.message, 80, "left"),
170
+ // ];
171
+ // if (args.pr?.number) {
172
+ // parts.push(` https://github.com/${repo_path}/pull/${args.pr.number}`);
173
+ // }
174
+ // console.debug(...parts);
175
+ // }
176
+ // const RE = {
177
+ // all_newline: /\n/g,
178
+ // // git@github.com:magus/git-multi-diff-playground.git
179
+ // // https://github.com/magus/git-multi-diff-playground.git
180
+ // repo_path: /(?<repo_path>[^:^/]+\/[^/]+)\.git/,
181
+ // };
182
+ // function trunc(value: string, length: number) {
183
+ // return value.substring(0, length);
184
+ // }
185
+ // function pad(value: string, length: number, align: "left" | "right") {
186
+ // const space_count = Math.max(0, length - value.length);
187
+ // const padding = " ".repeat(space_count);
188
+ // if (align === "left") {
189
+ // return `${value}${padding}`;
190
+ // } else {
191
+ // return `${padding}${value}`;
192
+ // }
193
+ // }
194
+ // function col(value: string, length: number, align: "left" | "right") {
195
+ // let column = value;
196
+ // column = column.replace(RE.all_newline, " ");
197
+ // column = trunc(column, length);
198
+ // column = pad(column, length, align);
199
+ // return column;
200
+ // }
@@ -0,0 +1,127 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ import * as CommitMetadata from "../core/CommitMetadata.js";
4
+ import * as Metadata from "../core/Metadata.js";
5
+ import { cli } from "../core/cli.js";
6
+ import * as github from "../core/github.js";
7
+ import { invariant } from "../core/invariant.js";
8
+ import { short_id } from "../core/short_id.js";
9
+ import { Await } from "./Await.js";
10
+ import { Brackets } from "./Brackets.js";
11
+ import { Store } from "./Store.js";
12
+ export function ManualRebase(props) {
13
+ return (React.createElement(Await, { fallback: React.createElement(Ink.Text, { color: "yellow" }, "Rebasing commits..."), function: () => run(props) }));
14
+ }
15
+ async function run(props) {
16
+ const state = Store.getState();
17
+ const actions = state.actions;
18
+ const branch_name = state.branch_name;
19
+ const merge_base = state.merge_base;
20
+ const commit_map = state.commit_map;
21
+ invariant(branch_name, "branch_name must exist");
22
+ invariant(merge_base, "merge_base must exist");
23
+ invariant(commit_map, "commit_map must exist");
24
+ // always listen for SIGINT event and restore git state
25
+ process.once("SIGINT", handle_exit);
26
+ const temp_branch_name = `${branch_name}_${short_id()}`;
27
+ const commit_range = await CommitMetadata.range(commit_map);
28
+ // reverse commit list so that we can cherry-pick in order
29
+ commit_range.group_list.reverse();
30
+ let rebase_merge_base = merge_base;
31
+ let rebase_group_index = 0;
32
+ for (let i = 0; i < commit_range.group_list.length; i++) {
33
+ const group = commit_range.group_list[i];
34
+ if (!group.dirty) {
35
+ continue;
36
+ }
37
+ if (i > 0) {
38
+ const last_group = commit_range.group_list[i - 1];
39
+ const last_commit = last_group.commits[last_group.commits.length - 1];
40
+ rebase_merge_base = last_commit.sha;
41
+ rebase_group_index = i;
42
+ }
43
+ break;
44
+ }
45
+ try {
46
+ // create temporary branch based on merge base
47
+ await cli(`git checkout -b ${temp_branch_name} ${rebase_merge_base}`);
48
+ for (let i = rebase_group_index; i < commit_range.group_list.length; i++) {
49
+ const group = commit_range.group_list[i];
50
+ invariant(group.base, "group.base must exist");
51
+ // cherry-pick and amend commits one by one
52
+ for (const commit of group.commits) {
53
+ await cli(`git cherry-pick ${commit.sha}`);
54
+ if (commit.branch_id !== group.id) {
55
+ const new_message = await Metadata.write(commit.message, group.id);
56
+ await cli(`git commit --amend -m "${new_message}"`);
57
+ }
58
+ }
59
+ actions.output(React.createElement(Ink.Text, { color: "yellow", wrap: "truncate-end" },
60
+ "Syncing ",
61
+ React.createElement(Brackets, null, group.pr?.title || group.id),
62
+ "..."));
63
+ if (!props.skipSync) {
64
+ // push to origin since github requires commit shas to line up perfectly
65
+ await cli(`git push -f origin HEAD:${group.id}`);
66
+ if (group.pr) {
67
+ // ensure base matches pr in github
68
+ await github.pr_base(group.id, group.base);
69
+ }
70
+ else {
71
+ // delete local group branch if leftover
72
+ await cli(`git branch -D ${group.id}`, { ignoreExitCode: true });
73
+ // move to temporary branch for creating pr
74
+ await cli(`git checkout -b ${group.id}`);
75
+ // create pr in github
76
+ await github.pr_create(group.id, group.base);
77
+ // move back to temp branch
78
+ await cli(`git checkout ${temp_branch_name}`);
79
+ }
80
+ }
81
+ }
82
+ // after all commits have been cherry-picked and amended
83
+ // move the branch pointer to the newly created temporary branch
84
+ // now we are in locally in sync with github and on the original branch
85
+ await cli(`git branch -f ${branch_name} ${temp_branch_name}`);
86
+ restore_git();
87
+ actions.set((state) => {
88
+ state.step = "post-rebase-status";
89
+ });
90
+ }
91
+ catch (err) {
92
+ actions.output(React.createElement(Ink.Text, { color: "#ef4444" }, "Error during rebase."));
93
+ if (err instanceof Error) {
94
+ actions.debug(React.createElement(Ink.Text, { color: "#ef4444" }, err.message));
95
+ }
96
+ handle_exit();
97
+ }
98
+ // cleanup git operations if cancelled during manual rebase
99
+ function restore_git() {
100
+ // signint handler MUST run synchronously
101
+ // trying to use `await cli(...)` here will silently fail since
102
+ // all children processes receive the SIGINT signal
103
+ const spawn_options = { ignoreExitCode: true };
104
+ // always put self back in original branch
105
+ cli.sync(`git checkout ${branch_name}`, spawn_options);
106
+ // ...and cleanup temporary branch
107
+ cli.sync(`git branch -D ${temp_branch_name}`, spawn_options);
108
+ if (commit_range) {
109
+ // ...and cleanup pr group branches
110
+ for (const group of commit_range.group_list) {
111
+ cli.sync(`git branch -D ${group.id}`, spawn_options);
112
+ }
113
+ }
114
+ }
115
+ function handle_exit() {
116
+ actions.output(React.createElement(Ink.Text, { color: "yellow" },
117
+ "Restoring ",
118
+ React.createElement(Brackets, null, branch_name),
119
+ "..."));
120
+ restore_git();
121
+ actions.output(React.createElement(Ink.Text, { color: "yellow" },
122
+ "Restored ",
123
+ React.createElement(Brackets, null, branch_name),
124
+ "."));
125
+ actions.exit(5);
126
+ }
127
+ }
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import fs from "node:fs";
2
3
  import * as Ink from "ink";
3
4
  import * as CommitMetadata from "../core/CommitMetadata.js";
4
5
  import * as Metadata from "../core/Metadata.js";
@@ -22,10 +23,14 @@ async function run(props) {
22
23
  const branch_name = state.branch_name;
23
24
  const merge_base = state.merge_base;
24
25
  const commit_map = state.commit_map;
26
+ const cwd = state.cwd;
27
+ const repo_root = state.repo_root;
25
28
  invariant(argv, "argv must exist");
26
29
  invariant(branch_name, "branch_name must exist");
27
30
  invariant(merge_base, "merge_base must exist");
28
31
  invariant(commit_map, "commit_map must exist");
32
+ invariant(cwd, "cwd must exist");
33
+ invariant(repo_root, "repo_root must exist");
29
34
  // always listen for SIGINT event and restore git state
30
35
  process.once("SIGINT", handle_exit);
31
36
  const temp_branch_name = `${branch_name}_${short_id()}`;
@@ -48,6 +53,9 @@ async function run(props) {
48
53
  break;
49
54
  }
50
55
  try {
56
+ // must perform rebase from repo root for applying git patch
57
+ process.chdir(repo_root);
58
+ await cli(`pwd`);
51
59
  // create temporary branch based on merge base
52
60
  await cli(`git checkout -b ${temp_branch_name} ${rebase_merge_base}`);
53
61
  const pr_url_list = commit_range.group_list.map(get_group_url);
@@ -60,9 +68,13 @@ async function run(props) {
60
68
  const selected_url = get_group_url(group);
61
69
  // cherry-pick and amend commits one by one
62
70
  for (const commit of group.commits) {
71
+ // ensure clean base to avoid conflicts when applying patch
72
+ await cli(`git clean -fd`);
73
+ // create, apply and cleanup patch
63
74
  await cli(`git format-patch -1 ${commit.sha} --stdout > ${PATCH_FILE}`);
64
75
  await cli(`git apply ${PATCH_FILE}`);
65
76
  await cli(`rm ${PATCH_FILE}`);
77
+ // add all changes to stage
66
78
  await cli(`git add --all`);
67
79
  const new_message = await Metadata.write(commit.message, group.id);
68
80
  const git_commit_comand = [`git commit -m "${new_message}"`];
@@ -184,6 +196,12 @@ async function run(props) {
184
196
  cli.sync(`git branch -D ${group.id}`, spawn_options);
185
197
  }
186
198
  }
199
+ // restore back to original dir
200
+ invariant(cwd, "cwd must exist");
201
+ if (fs.existsSync(cwd)) {
202
+ process.chdir(cwd);
203
+ }
204
+ cli.sync(`pwd`, spawn_options);
187
205
  }
188
206
  function handle_exit() {
189
207
  actions.output(React.createElement(Ink.Text, { color: colors.yellow },
@@ -199,4 +217,4 @@ async function run(props) {
199
217
  }
200
218
  }
201
219
  const get_group_url = (group) => group.pr?.url || group.id;
202
- const PATCH_FILE = "mypatch.patch";
220
+ const PATCH_FILE = "git-stack-cli-patch.patch";
@@ -0,0 +1,76 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ import { clamp } from "../core/clamp.js";
4
+ export function MultiSelect(props) {
5
+ const [selected, select] = React.useReducer((state, value) => {
6
+ const next = new Set(state);
7
+ if (next.has(value)) {
8
+ next.delete(value);
9
+ }
10
+ else {
11
+ next.add(value);
12
+ }
13
+ return next;
14
+ }, new Set());
15
+ // clamp index to keep in item range
16
+ const [index, set_index] = React.useReducer((_, value) => {
17
+ return clamp(value, 0, props.items.length - 1);
18
+ }, 0);
19
+ React.useEffect(() => {
20
+ const item = props.items[index];
21
+ const selected_list = Array.from(selected);
22
+ const list = selected_list.map((index) => props.items[index]);
23
+ props.onSelect(item, list);
24
+ }, [selected]);
25
+ Ink.useInput((_input, key) => {
26
+ if (key.return) {
27
+ return select(index);
28
+ }
29
+ if (key.upArrow) {
30
+ return set_index(index - 1);
31
+ }
32
+ if (key.downArrow) {
33
+ return set_index(index + 1);
34
+ }
35
+ });
36
+ return (React.createElement(Ink.Box, { flexDirection: "column" }, props.items.map((item, i) => {
37
+ const active = i === index;
38
+ return (React.createElement(ItemRow, { key: item.label, label: item.label, active: active, selected: selected.has(i) }));
39
+ })));
40
+ }
41
+ function Radio(props) {
42
+ let display;
43
+ let color;
44
+ if (props.selected) {
45
+ // display = "✓";
46
+ display = "◉";
47
+ color = "green";
48
+ }
49
+ else {
50
+ // display = " ";
51
+ display = "◯";
52
+ color = "";
53
+ }
54
+ return (React.createElement(Ink.Text, { bold: props.selected, color: color }, display));
55
+ }
56
+ function ItemRow(props) {
57
+ let color;
58
+ let underline;
59
+ let dimColor;
60
+ if (props.active) {
61
+ color = "#38bdf8";
62
+ underline = true;
63
+ }
64
+ else if (props.selected) {
65
+ // color = "";
66
+ dimColor = false;
67
+ }
68
+ else {
69
+ // color = "gray";
70
+ dimColor = true;
71
+ }
72
+ return (React.createElement(Ink.Box, { flexDirection: "row", gap: 1 },
73
+ React.createElement(Radio, { selected: props.selected }),
74
+ React.createElement(Ink.Box, null,
75
+ React.createElement(Ink.Text, { bold: props.selected, underline: underline, color: color, dimColor: dimColor, wrap: "truncate-end" }, props.label))));
76
+ }
@@ -0,0 +1,34 @@
1
+ import * as React from "react";
2
+ import fs from "node:fs";
3
+ import * as Ink from "ink";
4
+ export function AutoUpdate(props) {
5
+ const props_ref = React.useRef(props);
6
+ props_ref.current = props;
7
+ React.useEffect(() => {
8
+ async function auto_update() {
9
+ try {
10
+ const npm_res = await fetch(`https://registry.npmjs.org/${props.name}`);
11
+ const npm_json = await npm_res.json();
12
+ const latest = npm_json["dist-tags"].latest;
13
+ console.debug({ latest });
14
+ const script_path = process.argv[1];
15
+ const path_list = [process.argv[1]];
16
+ const real_path_list = path_list.map((p) => fs.realpathSync(p));
17
+ console.debug({ real_path_list, path_list });
18
+ // const winner = await Promise.race([
19
+ // sleep(Math.random() * 5000).then(() => "a"),
20
+ // sleep(Math.random() * 5000).then(() => "b"),
21
+ // ]);
22
+ // console.debug({ winner });
23
+ }
24
+ catch (err) {
25
+ console.debug({ err });
26
+ // handled by catch below
27
+ throw err;
28
+ }
29
+ }
30
+ const onError = props_ref.current.onError || (() => { });
31
+ auto_update().catch(onError);
32
+ }, []);
33
+ return React.createElement(Ink.Text, { color: "yellow" }, "Checking for latest version...");
34
+ }
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ export function Parens(props) {
4
+ const color = "#38bdf8";
5
+ return (React.createElement(Ink.Text, null,
6
+ React.createElement(Ink.Text, { color: color }, "("),
7
+ props.children,
8
+ React.createElement(Ink.Text, { color: color }, ")")));
9
+ }
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ import * as CommitMetadata from "../core/CommitMetadata.js";
4
+ import { invariant } from "../core/invariant.js";
5
+ import { Await } from "./Await.js";
6
+ import { StatusTable } from "./StatusTable.js";
7
+ import { Store } from "./Store.js";
8
+ export function PostRebaseStatus() {
9
+ const argv = Store.useState((state) => state.argv);
10
+ invariant(argv, "argv must exist");
11
+ return React.createElement(Await, { fallback: null, function: run });
12
+ }
13
+ async function run() {
14
+ const actions = Store.getState().actions;
15
+ // reset github pr cache before refreshing via commit range below
16
+ actions.reset_pr();
17
+ const commit_range = await CommitMetadata.range();
18
+ actions.set((state) => {
19
+ state.commit_range = commit_range;
20
+ });
21
+ actions.output(React.createElement(StatusTable, null));
22
+ actions.output(React.createElement(Ink.Text, null, "\u2705 Everything up to date."));
23
+ }
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ import { invariant } from "../core/invariant.js";
3
+ import { Store } from "./Store.js";
4
+ import { YesNoPrompt } from "./YesNoPrompt.js";
5
+ export function PreSelectCommitRanges() {
6
+ const actions = Store.useActions();
7
+ const argv = Store.useState((state) => state.argv);
8
+ invariant(argv, "argv must exist");
9
+ React.useEffect(() => {
10
+ if (argv.force) {
11
+ Store.setState((state) => {
12
+ state.step = "select-commit-ranges";
13
+ });
14
+ }
15
+ }, [argv]);
16
+ return (React.createElement(YesNoPrompt, { message: "Some commits are new or outdated, would you like to select new commit ranges?", onYes: () => {
17
+ actions.set((state) => {
18
+ state.step = "select-commit-ranges";
19
+ });
20
+ }, onNo: () => actions.exit(0) }));
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ import { invariant } from "../core/invariant.js";
4
+ import { Await } from "./Await.js";
5
+ import { StatusTable } from "./StatusTable.js";
6
+ import { Store } from "./Store.js";
7
+ export function Status() {
8
+ const argv = Store.useState((state) => state.argv);
9
+ invariant(argv, "argv must exist");
10
+ return React.createElement(Await, { fallback: null, function: () => run({ argv }) });
11
+ }
12
+ async function run(args) {
13
+ const actions = Store.getState().actions;
14
+ const commit_range = Store.getState().commit_range;
15
+ invariant(commit_range, "commit_range must exist");
16
+ actions.output(React.createElement(StatusTable, null));
17
+ let needs_update = false;
18
+ for (const group of commit_range.group_list) {
19
+ if (group.dirty) {
20
+ needs_update = true;
21
+ break;
22
+ }
23
+ }
24
+ if (args.argv.check) {
25
+ actions.exit(0);
26
+ }
27
+ else if (args.argv.force) {
28
+ Store.setState((state) => {
29
+ state.step = "select-commit-ranges";
30
+ });
31
+ }
32
+ else if (needs_update) {
33
+ Store.setState((state) => {
34
+ state.step = "pre-select-commit-ranges";
35
+ });
36
+ }
37
+ else {
38
+ actions.newline();
39
+ actions.output(React.createElement(Ink.Text, null, "\u2705 Everything up to date."));
40
+ actions.output(React.createElement(Ink.Text, { color: "gray" },
41
+ React.createElement(Ink.Text, null, "Run with"),
42
+ React.createElement(Ink.Text, { bold: true, color: "yellow" }, ` --force `),
43
+ React.createElement(Ink.Text, null, "to force update all pull requests.")));
44
+ actions.exit(0);
45
+ }
46
+ }
package/dist/app/Store.js CHANGED
@@ -10,6 +10,7 @@ const BaseStore = createStore()(immer((set, get) => ({
10
10
  cwd: null,
11
11
  username: null,
12
12
  repo_path: null,
13
+ repo_root: null,
13
14
  master_branch: "master",
14
15
  head: null,
15
16
  merge_base: null,
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ export function Url(props) {
4
+ const text_color = "#38bdf8";
5
+ return React.createElement(Ink.Text, { color: text_color }, props.children);
6
+ }
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import * as Ink from "ink";
3
+ export function YesNoPrompt(props) {
4
+ Ink.useInput((input) => {
5
+ const inputLower = input.toLowerCase();
6
+ switch (inputLower) {
7
+ case "n":
8
+ return props.onNo();
9
+ case "y":
10
+ return props.onYes();
11
+ }
12
+ });
13
+ return (React.createElement(Ink.Box, { flexDirection: "column" },
14
+ React.createElement(Ink.Box, null,
15
+ React.createElement(Ink.Text, { color: "yellow" }, props.message),
16
+ React.createElement(Ink.Text, null, " "),
17
+ React.createElement(Ink.Text, { color: "#06b6d4" },
18
+ "(",
19
+ React.createElement(Ink.Text, { color: "gray" },
20
+ React.createElement(Ink.Text, { color: "#22c55e", dimColor: true }, "Y"),
21
+ "/",
22
+ React.createElement(Ink.Text, { color: "#ef4444", dimColor: true }, "n")),
23
+ ")"))));
24
+ }
package/dist/cli.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import * as React from "react";
3
+ import * as Ink from "ink";
4
+ import { App } from "./app/App.js";
5
+ import { command } from "./command.js";
6
+ const argv = await command();
7
+ const ink = {};
8
+ const app = Ink.render(React.createElement(App, { argv: argv, ink: ink }));
9
+ Object.assign(ink, app);