git-stack-cli 0.8.7 → 1.0.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.
Files changed (105) hide show
  1. package/README.md +32 -3
  2. package/dist/cjs/index.cjs +34770 -0
  3. package/package.json +21 -7
  4. package/dist/__fixtures__/metadata.js +0 -666
  5. package/dist/__fixtures__/metadata.json +0 -186
  6. package/dist/app/App copy.js +0 -30
  7. package/dist/app/App.js +0 -42
  8. package/dist/app/ArgCheck.js +0 -21
  9. package/dist/app/AutoUpdate.js +0 -128
  10. package/dist/app/Await.js +0 -45
  11. package/dist/app/Brackets copy.js +0 -10
  12. package/dist/app/Brackets.js +0 -11
  13. package/dist/app/Command.js +0 -7
  14. package/dist/app/Counter.js +0 -19
  15. package/dist/app/Debug.js +0 -33
  16. package/dist/app/DependencyCheck.js +0 -89
  17. package/dist/app/Exit.js +0 -14
  18. package/dist/app/FormatText.js +0 -9
  19. package/dist/app/GatherMetadata copy.js +0 -91
  20. package/dist/app/GatherMetadata.js +0 -100
  21. package/dist/app/GithubApiError.js +0 -50
  22. package/dist/app/InitMetadata.js +0 -14
  23. package/dist/app/Input.js +0 -15
  24. package/dist/app/KeepAlive.js +0 -11
  25. package/dist/app/LocalCommitStatus.js +0 -43
  26. package/dist/app/LocalMergeRebase.js +0 -157
  27. package/dist/app/Main copy.js +0 -200
  28. package/dist/app/ManualRebase copy.js +0 -127
  29. package/dist/app/ManualRebase.js +0 -220
  30. package/dist/app/MultiSelect copy.js +0 -76
  31. package/dist/app/MultiSelect.js +0 -143
  32. package/dist/app/NPMAutoUpdate.js +0 -34
  33. package/dist/app/Output.js +0 -19
  34. package/dist/app/Parens copy.js +0 -9
  35. package/dist/app/Parens.js +0 -10
  36. package/dist/app/PostRebaseStatus copy.js +0 -23
  37. package/dist/app/PostRebaseStatus.js +0 -23
  38. package/dist/app/PreLocalMergeRebase.js +0 -21
  39. package/dist/app/PreSelectCommitRanges copy.js +0 -21
  40. package/dist/app/PreSelectCommitRanges.js +0 -21
  41. package/dist/app/Providers.js +0 -5
  42. package/dist/app/RebaseCheck.js +0 -56
  43. package/dist/app/SelectCommitRange.js +0 -1
  44. package/dist/app/SelectCommitRanges.js +0 -207
  45. package/dist/app/Status copy.js +0 -46
  46. package/dist/app/Status.js +0 -61
  47. package/dist/app/StatusTable.js +0 -115
  48. package/dist/app/Store.js +0 -136
  49. package/dist/app/Table.js +0 -65
  50. package/dist/app/TextInput.js +0 -51
  51. package/dist/app/Url copy.js +0 -6
  52. package/dist/app/Url.js +0 -6
  53. package/dist/app/Waterfall.js +0 -20
  54. package/dist/app/YesNoPrompt copy.js +0 -24
  55. package/dist/app/YesNoPrompt.js +0 -40
  56. package/dist/app/main.js +0 -39
  57. package/dist/cli.js +0 -9
  58. package/dist/command.js +0 -60
  59. package/dist/core/CommitMetadata.js +0 -159
  60. package/dist/core/Metadata copy.js +0 -37
  61. package/dist/core/Metadata.js +0 -36
  62. package/dist/core/Metadata.test.js +0 -34
  63. package/dist/core/StackSummaryTable.js +0 -86
  64. package/dist/core/StackSummaryTable.test.js +0 -134
  65. package/dist/core/StackTable.js +0 -38
  66. package/dist/core/SummaryTable.js +0 -38
  67. package/dist/core/ZustandStore.js +0 -23
  68. package/dist/core/assertNever.js +0 -4
  69. package/dist/core/cache.js +0 -39
  70. package/dist/core/capitalize.js +0 -5
  71. package/dist/core/chalk.js +0 -83
  72. package/dist/core/clamp.js +0 -6
  73. package/dist/core/cli copy.js +0 -44
  74. package/dist/core/cli.js +0 -86
  75. package/dist/core/color.js +0 -83
  76. package/dist/core/colors.js +0 -15
  77. package/dist/core/date.js +0 -18
  78. package/dist/core/dependency_check.js +0 -27
  79. package/dist/core/env.js +0 -4
  80. package/dist/core/exit.js +0 -4
  81. package/dist/core/fetch_json.js +0 -24
  82. package/dist/core/get_commit_metadata.js +0 -61
  83. package/dist/core/github.js +0 -118
  84. package/dist/core/id.js +0 -61
  85. package/dist/core/invariant copy.js +0 -5
  86. package/dist/core/invariant.js +0 -5
  87. package/dist/core/isFiniteValue.js +0 -3
  88. package/dist/core/is_command_available.js +0 -15
  89. package/dist/core/is_dev.js +0 -1
  90. package/dist/core/is_finite_value.js +0 -3
  91. package/dist/core/json.js +0 -35
  92. package/dist/core/match_group.js +0 -9
  93. package/dist/core/readJson.js +0 -3
  94. package/dist/core/read_json.js +0 -12
  95. package/dist/core/safe_quote.js +0 -9
  96. package/dist/core/semver_compare.js +0 -26
  97. package/dist/core/serialize_json.js +0 -17
  98. package/dist/core/short_id.js +0 -60
  99. package/dist/core/sleep copy.js +0 -3
  100. package/dist/core/sleep.js +0 -3
  101. package/dist/core/wrap_index.js +0 -10
  102. package/dist/index.js +0 -13
  103. package/dist/main copy.js +0 -266
  104. package/dist/main.backup.js +0 -266
  105. package/dist/main.js +0 -265
@@ -1,159 +0,0 @@
1
- import { Store } from "../app/Store.js";
2
- import * as Metadata from "./Metadata.js";
3
- import { cli } from "./cli.js";
4
- import * as github from "./github.js";
5
- export async function range(commit_group_map) {
6
- const master_branch = Store.getState().master_branch;
7
- // gather all open prs in repo first
8
- // cheaper query to populate cache
9
- await github.pr_list();
10
- const commit_list = await get_commit_list();
11
- const pr_lookup = {};
12
- let invalid = false;
13
- const group_map = new Map();
14
- for (const commit of commit_list) {
15
- let id = commit.branch_id;
16
- let title = id;
17
- // use commit map if provided (via select commit ranges)
18
- if (commit_group_map) {
19
- const group = commit_group_map[commit.sha];
20
- if (group) {
21
- id = group.id;
22
- title = group.title;
23
- }
24
- }
25
- if (!id) {
26
- // console.debug("INVALID", "MISSING ID", commit.message);
27
- invalid = true;
28
- }
29
- if (id) {
30
- const group_key_list = Array.from(group_map.keys());
31
- const last_key = group_key_list[group_key_list.length - 1];
32
- if (group_map.has(id) && last_key !== id) {
33
- // if we've seen this id before and it's not
34
- // the last added key then we are out of order
35
- // console.debug("INVALID", "OUT OF ORDER", commit.message, id);
36
- invalid = true;
37
- }
38
- }
39
- else {
40
- // console.debug("INVALID", "NEW COMMIT", { commit });
41
- invalid = true;
42
- id = UNASSIGNED;
43
- }
44
- if (!title) {
45
- title = id;
46
- }
47
- const group = group_map.get(id) || {
48
- id,
49
- title,
50
- pr: null,
51
- base: null,
52
- dirty: false,
53
- commits: [],
54
- };
55
- group.commits.push(commit);
56
- group_map.set(id, group);
57
- }
58
- // check each group for dirty state and base
59
- const group_value_list = Array.from(group_map.values());
60
- const group_list = [];
61
- let unassigned_group;
62
- for (let i = 0; i < group_value_list.length; i++) {
63
- const group = group_value_list[i];
64
- if (group.id !== UNASSIGNED) {
65
- const pr_result = await github.pr_status(group.id);
66
- if (pr_result && pr_result.state !== "CLOSED") {
67
- group.pr = pr_result;
68
- pr_lookup[group.id] = pr_result;
69
- }
70
- }
71
- // console.debug("group", group.pr?.title.substring(0, 40));
72
- // console.debug(" ", "id", group.id);
73
- if (group.id === UNASSIGNED) {
74
- unassigned_group = group;
75
- }
76
- else {
77
- group_list.push(group);
78
- }
79
- if (i === 0) {
80
- group.base = master_branch;
81
- }
82
- else {
83
- const last_group = group_value_list[i - 1];
84
- // console.debug(" ", "last_group", last_group.pr?.title.substring(0, 40));
85
- // console.debug(" ", "last_group.id", last_group.id);
86
- // null out base when unassigned and after unassigned
87
- if (group.id === UNASSIGNED) {
88
- group.base = null;
89
- }
90
- else if (last_group.base === null) {
91
- group.base = null;
92
- }
93
- else {
94
- group.base = last_group.id;
95
- }
96
- // console.debug(" ", "group.base", group.base);
97
- }
98
- if (!group.pr) {
99
- group.dirty = true;
100
- }
101
- else if (group.pr.commits.length !== group.commits.length) {
102
- group.dirty = true;
103
- }
104
- else if (group.pr.baseRefName !== group.base) {
105
- group.dirty = true;
106
- }
107
- else {
108
- for (let i = 0; i < group.pr.commits.length; i++) {
109
- const pr_commit = group.pr.commits[i];
110
- const local_commit = group.commits[i];
111
- if (pr_commit.oid !== local_commit.sha) {
112
- group.dirty = true;
113
- }
114
- }
115
- }
116
- // console.debug(" ", "group.dirty", group.dirty);
117
- }
118
- // reverse group_list to match git log
119
- group_list.reverse();
120
- // insert unassigned group at front
121
- if (unassigned_group) {
122
- group_list.unshift(unassigned_group);
123
- }
124
- return { invalid, group_list, commit_list, pr_lookup, UNASSIGNED };
125
- }
126
- async function get_commit_list() {
127
- const log_result = await cli(`git log master..HEAD --oneline --format=%H --color=never`);
128
- if (!log_result.stdout) {
129
- return [];
130
- }
131
- const sha_list = lines(log_result.stdout).reverse();
132
- const commit_metadata_list = [];
133
- for (let i = 0; i < sha_list.length; i++) {
134
- const sha = sha_list[i];
135
- const commit_metadata = await commit(sha);
136
- commit_metadata_list.push(commit_metadata);
137
- }
138
- return commit_metadata_list;
139
- }
140
- export async function commit(sha) {
141
- const full_message = (await cli(`git show -s --format=%B ${sha}`)).stdout;
142
- const branch_id = await Metadata.read(full_message);
143
- const subject_line = get_subject_line(full_message);
144
- return {
145
- sha,
146
- full_message,
147
- subject_line,
148
- branch_id,
149
- };
150
- }
151
- function get_subject_line(message) {
152
- const line_list = lines(message);
153
- const first_line = line_list[0];
154
- return Metadata.remove(first_line);
155
- }
156
- function lines(value) {
157
- return value.split("\n");
158
- }
159
- const UNASSIGNED = "unassigned";
@@ -1,37 +0,0 @@
1
- import { invariant } from "../core/invariant.js";
2
- import { safe_quote } from "../core/safe_quote.js";
3
- export function write(message, branch_id) {
4
- let result = message;
5
- // escape double-quote for cli
6
- result = safe_quote(result);
7
- // remove any previous metadata lines
8
- result = remove(result);
9
- const line_list = [result, "", TEMPLATE.branch_id(branch_id)];
10
- const new_message = line_list.join("\n");
11
- return new_message;
12
- }
13
- export function read(message) {
14
- const match = message.match(RE.branch_id);
15
- if (!match?.groups) {
16
- return null;
17
- }
18
- const id = match.groups["id"];
19
- invariant(id, "id must exist");
20
- return id;
21
- }
22
- export function remove(message) {
23
- let result = message;
24
- // remove metadata
25
- result = result.replace(new RegExp(RE.branch_id, "g"), "");
26
- result = result.trimEnd();
27
- return result;
28
- }
29
- const TEMPLATE = {
30
- branch_id(id) {
31
- return `git-stack-id: ${id}`;
32
- },
33
- };
34
- const RE = {
35
- all_double_quote: /"/g,
36
- branch_id: new RegExp(TEMPLATE.branch_id("(?<id>[a-z0-9-+]+)"), "i"),
37
- };
@@ -1,36 +0,0 @@
1
- import { invariant } from "../core/invariant.js";
2
- import { safe_quote } from "../core/safe_quote.js";
3
- export function write(message, stack_id) {
4
- let result = message;
5
- // escape double-quote for cli
6
- result = safe_quote(result);
7
- // remove any previous metadata lines
8
- result = remove(result);
9
- const line_list = [result, "", TEMPLATE.stack_id(stack_id)];
10
- const new_message = line_list.join("\n");
11
- return new_message;
12
- }
13
- export function read(message) {
14
- const match = message.match(RE.stack_id);
15
- if (!match?.groups) {
16
- return null;
17
- }
18
- const id = match.groups["id"];
19
- invariant(id, "id must exist");
20
- return id;
21
- }
22
- export function remove(message) {
23
- let result = message;
24
- // remove metadata
25
- result = result.replace(new RegExp(RE.stack_id, "gmi"), "");
26
- result = result.trimEnd();
27
- return result;
28
- }
29
- const TEMPLATE = {
30
- stack_id(id) {
31
- return `git-stack-id: ${id}`;
32
- },
33
- };
34
- const RE = {
35
- stack_id: new RegExp(TEMPLATE.stack_id("(?<id>[a-z0-9-+=]+)"), "i"),
36
- };
@@ -1,34 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import * as Metadata from "./Metadata.js";
3
- test("read handles bulleted lists", () => {
4
- const body = [
5
- "[feat] implement various features",
6
- "",
7
- "- keyboard modality escape key",
8
- "- centralize settings",
9
- "- move logic inside if branch",
10
- "",
11
- "git-stack-id: DdKIFyufW",
12
- ].join("\n");
13
- expect(Metadata.read(body)).toEqual("DdKIFyufW");
14
- });
15
- test("write handles bulleted lists", () => {
16
- const body = [
17
- "[feat] implement various features",
18
- "",
19
- "- keyboard modality escape key",
20
- "- centralize settings",
21
- "- move logic inside if branch",
22
- "",
23
- "git-stack-id: DdKIFyufW",
24
- ].join("\n");
25
- expect(Metadata.write(body, "abcd1234")).toEqual([
26
- "[feat] implement various features",
27
- "",
28
- "- keyboard modality escape key",
29
- "- centralize settings",
30
- "- move logic inside if branch",
31
- "",
32
- "git-stack-id: abcd1234",
33
- ].join("\n"));
34
- });
@@ -1,86 +0,0 @@
1
- export function write(args) {
2
- const stack_table = table(args);
3
- let result = args.body;
4
- if (RE.stack_table.test(result)) {
5
- // replace stack table
6
- result = result.replace(RE.stack_table, stack_table);
7
- }
8
- else {
9
- // append stack table
10
- result = `${result}\n\n${stack_table}`;
11
- }
12
- result = result.trimEnd();
13
- return result;
14
- }
15
- export function table(args) {
16
- const stack_pr_url_list = [...args.pr_url_list];
17
- const old_stack = parse(args.body);
18
- // remove existing stack pr urls from the old stack pr urls
19
- for (const pr_url of stack_pr_url_list) {
20
- old_stack.delete(pr_url);
21
- }
22
- // add remaining old stack pr urls to the front of stack pr url list
23
- for (const pr_url of old_stack.keys()) {
24
- stack_pr_url_list.unshift(pr_url);
25
- }
26
- const stack_list = [];
27
- const num_digits = String(stack_pr_url_list.length).length;
28
- for (let i = 0; i < stack_pr_url_list.length; i++) {
29
- const pr_url = stack_pr_url_list[i];
30
- const selected = args.selected_url === pr_url;
31
- let icon;
32
- if (old_stack.has(pr_url)) {
33
- icon = "✅";
34
- }
35
- else if (selected) {
36
- icon = "👉";
37
- }
38
- else {
39
- icon = "⏳";
40
- }
41
- const num = String(i + 1).padStart(num_digits, "0");
42
- stack_list.push(TEMPLATE.row({ icon, num, pr_url }));
43
- }
44
- if (!stack_list.length) {
45
- return "";
46
- }
47
- // reverse order of pr list to match the order of git stack
48
- stack_list.reverse();
49
- return TEMPLATE.stack_table(["", ...stack_list, "", ""].join("\n"));
50
- }
51
- export function parse(body) {
52
- const stack_table_match = body.match(RE.stack_table);
53
- if (!stack_table_match?.groups) {
54
- return new Map();
55
- }
56
- const rows_string = stack_table_match.groups["rows"];
57
- const row_list = rows_string.split("\n");
58
- const result = new Map();
59
- for (const row of row_list) {
60
- const row_match = row.match(RE.row);
61
- const parsed_row = row_match?.groups;
62
- if (!parsed_row) {
63
- // skip invalid row
64
- continue;
65
- }
66
- result.set(parsed_row.pr_url, parsed_row);
67
- }
68
- return result;
69
- }
70
- const TEMPLATE = {
71
- stack_table(rows) {
72
- return `#### git stack${rows}`;
73
- },
74
- row(args) {
75
- return `- ${args.icon} \`${args.num}\` ${args.pr_url}`;
76
- },
77
- };
78
- const RE = {
79
- // https://regex101.com/r/kqB9Ft/1
80
- stack_table: new RegExp(TEMPLATE.stack_table("\\s+(?<rows>(?:- [^\r^\n]*(?:[\r\n]+)?)+)")),
81
- row: new RegExp(TEMPLATE.row({
82
- icon: "(?<icon>.+)",
83
- num: "(?<num>\\d+)",
84
- pr_url: "(?<pr_url>.+)",
85
- })),
86
- };
@@ -1,134 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import * as StackSummaryTable from "./StackSummaryTable.js";
3
- test("blank", () => {
4
- const output = StackSummaryTable.write({
5
- body: "",
6
- pr_url_list: [],
7
- selected_url: "",
8
- });
9
- expect(output).toBe("");
10
- });
11
- test("no prs does not modify body", () => {
12
- const args = {
13
- body: [
14
- "## Problem,",
15
- "",
16
- ",Description of the problem,",
17
- "",
18
- ",## Solution,",
19
- "",
20
- ",Solved problem by doing x, y, z.",
21
- ].join("\n"),
22
- pr_url_list: [],
23
- selected_url: "",
24
- };
25
- const output = StackSummaryTable.write(args);
26
- expect(output).toBe(args.body);
27
- });
28
- test("handles bulleted lists", () => {
29
- const body = [
30
- "## Problem",
31
- "",
32
- "Description of the problem",
33
- "",
34
- "## Solution",
35
- "",
36
- "- keyboard modality escape key",
37
- "- centralize settings",
38
- "- move logic inside if branch",
39
- ].join("\n");
40
- const args = {
41
- body,
42
- pr_url_list: [],
43
- selected_url: "",
44
- };
45
- const output = StackSummaryTable.write(args);
46
- expect(output).toBe(args.body);
47
- });
48
- test("builds list of prs with selected emoji", () => {
49
- const args = {
50
- body: [
51
- "## Problem,",
52
- "",
53
- ",Description of the problem,",
54
- "",
55
- ",## Solution,",
56
- "",
57
- ",Solved problem by doing x, y, z.",
58
- ].join("\n"),
59
- pr_url_list: [
60
- "https://github.com/magus/git-multi-diff-playground/pull/43",
61
- "https://github.com/magus/git-multi-diff-playground/pull/47",
62
- ],
63
- selected_url: "https://github.com/magus/git-multi-diff-playground/pull/43",
64
- };
65
- const output = StackSummaryTable.write(args);
66
- expect(output.split("\n")).toEqual([
67
- ...args.body.split("\n"),
68
- "",
69
- "#### git stack",
70
- "- ⏳ `2` https://github.com/magus/git-multi-diff-playground/pull/47",
71
- "- 👉 `1` https://github.com/magus/git-multi-diff-playground/pull/43",
72
- ]);
73
- });
74
- test("can parse stack table from body", () => {
75
- const body_line_list = [
76
- "",
77
- "",
78
- "#### git stack",
79
- "- invalid line that will be dropped",
80
- "- ⏳ `2` https://github.com/magus/git-multi-diff-playground/pull/47",
81
- "- 👉 `1` https://github.com/magus/git-multi-diff-playground/pull/43",
82
- ];
83
- const parsed = StackSummaryTable.parse(body_line_list.join("\n"));
84
- expect(Array.from(parsed.entries())).toEqual([
85
- [
86
- "https://github.com/magus/git-multi-diff-playground/pull/47",
87
- {
88
- icon: "⏳",
89
- num: "2",
90
- pr_url: "https://github.com/magus/git-multi-diff-playground/pull/47",
91
- },
92
- ],
93
- [
94
- "https://github.com/magus/git-multi-diff-playground/pull/43",
95
- {
96
- icon: "👉",
97
- num: "1",
98
- pr_url: "https://github.com/magus/git-multi-diff-playground/pull/43",
99
- },
100
- ],
101
- ]);
102
- });
103
- test("persists removed pr urls from previous stack table", () => {
104
- const args = {
105
- body: [
106
- "Summary of problem",
107
- "",
108
- "#### git stack",
109
- "- 👉 `3` https://github.com/magus/git-multi-diff-playground/pull/47",
110
- "- ⏳ `2` https://github.com/magus/git-multi-diff-playground/pull/44",
111
- "- ⏳ `1` https://github.com/magus/git-multi-diff-playground/pull/43",
112
- ].join("\n"),
113
- pr_url_list: [
114
- "https://github.com/magus/git-multi-diff-playground/pull/47",
115
- "https://github.com/magus/git-multi-diff-playground/pull/54",
116
- "https://github.com/magus/git-multi-diff-playground/pull/61",
117
- ],
118
- selected_url: "https://github.com/magus/git-multi-diff-playground/pull/47",
119
- };
120
- const output = StackSummaryTable.write(args);
121
- expect(output.split("\n")).toEqual([
122
- "Summary of problem",
123
- "",
124
- "#### git stack",
125
- "- ⏳ `5` https://github.com/magus/git-multi-diff-playground/pull/61",
126
- "- ⏳ `4` https://github.com/magus/git-multi-diff-playground/pull/54",
127
- "- 👉 `3` https://github.com/magus/git-multi-diff-playground/pull/47",
128
- "- ✅ `2` https://github.com/magus/git-multi-diff-playground/pull/44",
129
- "- ✅ `1` https://github.com/magus/git-multi-diff-playground/pull/43",
130
- ]);
131
- // run again on the output to make sure it doesn't change
132
- const rerun_output = StackSummaryTable.write({ ...args, body: output });
133
- expect(rerun_output).toBe(output);
134
- });
@@ -1,38 +0,0 @@
1
- import { invariant } from "./invariant.js";
2
- import { safe_quote } from "./safe_quote.js";
3
- export function write(message, branch_id) {
4
- let result = message;
5
- // escape double-quote for cli
6
- result = safe_quote(result);
7
- // remove any previous metadata lines
8
- result = remove(result);
9
- const line_list = [result, "", TEMPLATE.branch_id(branch_id)];
10
- const new_message = line_list.join("\n");
11
- return new_message;
12
- }
13
- export function read(message) {
14
- const match = message.match(RE.branch_id);
15
- if (!match?.groups) {
16
- return null;
17
- }
18
- const id = match.groups["id"];
19
- invariant(id, "id must exist");
20
- return id;
21
- }
22
- export function remove(message) {
23
- let result = message;
24
- // remove metadata
25
- result = result.replace(new RegExp(RE.branch_id, "g"), "");
26
- result = result.trimEnd();
27
- return result;
28
- }
29
- const TEMPLATE = {
30
- stack_table(rows) {
31
- return `"#### git stack\n${rows}"`;
32
- },
33
- };
34
- const RE = {
35
- all_double_quote: /"/g,
36
- // https://regex101.com/r/kqB9Ft/1
37
- stack_table: new RegExp(TEMPLATE.branch_id("(?<id>[a-z0-9-+]+)"), "i"),
38
- };
@@ -1,38 +0,0 @@
1
- import { invariant } from "./invariant.js";
2
- import { safe_quote } from "./safe_quote.js";
3
- export function write(message, branch_id) {
4
- let result = message;
5
- // escape double-quote for cli
6
- result = safe_quote(result);
7
- // remove any previous metadata lines
8
- result = remove(result);
9
- const line_list = [result, "", TEMPLATE.branch_id(branch_id)];
10
- const new_message = line_list.join("\n");
11
- return new_message;
12
- }
13
- export function read(message) {
14
- const match = message.match(RE.branch_id);
15
- if (!match?.groups) {
16
- return null;
17
- }
18
- const id = match.groups["id"];
19
- invariant(id, "id must exist");
20
- return id;
21
- }
22
- export function remove(message) {
23
- let result = message;
24
- // remove metadata
25
- result = result.replace(new RegExp(RE.branch_id, "g"), "");
26
- result = result.trimEnd();
27
- return result;
28
- }
29
- const TEMPLATE = {
30
- stack_table(rows) {
31
- return `"#### git stack\n${rows}"`;
32
- },
33
- };
34
- const RE = {
35
- all_double_quote: /"/g,
36
- // https://regex101.com/r/kqB9Ft/1
37
- stack_table: new RegExp(TEMPLATE.branch_id("(?<id>[a-z0-9-+]+)"), "i"),
38
- };
@@ -1,23 +0,0 @@
1
- import { createStore, useStore } from "zustand";
2
- import { immer } from "zustand/middleware/immer";
3
- function ZustandStore() {
4
- const BaseStore = createStore()(immer((set, get) => ({
5
- actions: {
6
- set(setter) {
7
- set((state) => {
8
- setter(state);
9
- });
10
- },
11
- },
12
- })));
13
- function useState(selector) {
14
- return useStore(BaseStore, selector);
15
- }
16
- function useActions() {
17
- return useState((state) => state.actions);
18
- }
19
- const getState = BaseStore.getState;
20
- const setState = BaseStore.setState;
21
- const subscribe = BaseStore.subscribe;
22
- return { useActions, useState, getState, setState, subscribe };
23
- }
@@ -1,4 +0,0 @@
1
- export function assertNever(value) {
2
- // eslint-disable-next-line no-console
3
- console.error("[assertNever]", { value });
4
- }
@@ -1,39 +0,0 @@
1
- export function cache(cacheable) {
2
- let status = "pending";
3
- let response;
4
- let suspender;
5
- function reset() {
6
- status = "pending";
7
- response = undefined;
8
- suspender = undefined;
9
- }
10
- function check() {
11
- return status;
12
- }
13
- function read() {
14
- // cacheable is a function to allow deferred reads
15
- // this will call cacheable to kickoff async promise
16
- if (!suspender) {
17
- suspender = Promise.resolve().then(() => {
18
- cacheable()
19
- .then((res) => {
20
- status = "success";
21
- response = res;
22
- })
23
- .catch((err) => {
24
- status = "error";
25
- response = err;
26
- });
27
- });
28
- }
29
- switch (status) {
30
- case "pending":
31
- throw suspender;
32
- case "error":
33
- throw response;
34
- default:
35
- return response;
36
- }
37
- }
38
- return { reset, check, read };
39
- }
@@ -1,5 +0,0 @@
1
- export function capitalize(value) {
2
- const first_char = value.substring(0, 1).toLocaleUpperCase();
3
- const rest_char = value.substring(1, value.length);
4
- return first_char + rest_char;
5
- }