@solaqua/gji 0.1.0-beta.4 → 0.1.0-beta.6
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/dist/cli.js +3 -1
- package/dist/go.d.ts +0 -1
- package/dist/go.js +8 -53
- package/dist/init.js +53 -5
- package/dist/root.d.ts +1 -0
- package/dist/root.js +8 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -77,6 +77,7 @@ function registerCommands(program) {
|
|
|
77
77
|
program
|
|
78
78
|
.command('root')
|
|
79
79
|
.description('print the main repository root path')
|
|
80
|
+
.option('--print', 'print the resolved repository root path explicitly')
|
|
80
81
|
.action(notImplemented('root'));
|
|
81
82
|
program
|
|
82
83
|
.command('status')
|
|
@@ -165,9 +166,10 @@ function attachCommandActions(program, options) {
|
|
|
165
166
|
});
|
|
166
167
|
program.commands
|
|
167
168
|
.find((command) => command.name() === 'root')
|
|
168
|
-
?.action(async () => {
|
|
169
|
+
?.action(async (commandOptions) => {
|
|
169
170
|
const exitCode = await runRootCommand({
|
|
170
171
|
cwd: options.cwd,
|
|
172
|
+
print: commandOptions.print,
|
|
171
173
|
stdout: options.stdout,
|
|
172
174
|
});
|
|
173
175
|
if (exitCode !== 0) {
|
package/dist/go.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export interface GoCommandOptions {
|
|
|
7
7
|
stdout: (chunk: string) => void;
|
|
8
8
|
}
|
|
9
9
|
export interface GoCommandDependencies {
|
|
10
|
-
promptForCapturedOutputWorktree: (worktrees: WorktreeEntry[]) => Promise<string | null>;
|
|
11
10
|
promptForWorktree: (worktrees: WorktreeEntry[]) => Promise<string | null>;
|
|
12
11
|
}
|
|
13
12
|
export declare function createGoCommand(dependencies?: Partial<GoCommandDependencies>): (options: GoCommandOptions) => Promise<number>;
|
package/dist/go.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { isCancel, select } from '@clack/prompts';
|
|
3
3
|
import { listWorktrees } from './repo.js';
|
|
4
|
-
const
|
|
5
|
-
const GO_TTY_TARGET_PREFIX = '__GJI_TARGET__:';
|
|
4
|
+
const GO_OUTPUT_FILE_ENV = 'GJI_GO_OUTPUT_FILE';
|
|
6
5
|
export function createGoCommand(dependencies = {}) {
|
|
7
|
-
const promptForCapturedOutput = dependencies.promptForCapturedOutputWorktree ?? promptForCapturedOutputWorktree;
|
|
8
6
|
const prompt = dependencies.promptForWorktree ?? promptForWorktree;
|
|
9
7
|
return async function runGoCommand(options) {
|
|
10
8
|
const worktrees = await listWorktrees(options.cwd);
|
|
@@ -17,17 +15,16 @@ export function createGoCommand(dependencies = {}) {
|
|
|
17
15
|
options.stdout(`${worktree.path}\n`);
|
|
18
16
|
return 0;
|
|
19
17
|
}
|
|
20
|
-
const chosenPath =
|
|
21
|
-
? await promptForCapturedOutput(worktrees)
|
|
22
|
-
: await prompt(worktrees);
|
|
18
|
+
const chosenPath = await prompt(worktrees);
|
|
23
19
|
if (!chosenPath) {
|
|
24
20
|
options.stderr('Aborted\n');
|
|
25
21
|
return 1;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
if (process.env[GO_OUTPUT_FILE_ENV]) {
|
|
24
|
+
await writeFile(process.env[GO_OUTPUT_FILE_ENV], `${chosenPath}\n`, 'utf8');
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
options.stdout(`${chosenPath}\n`);
|
|
31
28
|
return 0;
|
|
32
29
|
};
|
|
33
30
|
}
|
|
@@ -46,45 +43,3 @@ async function promptForWorktree(worktrees) {
|
|
|
46
43
|
}
|
|
47
44
|
return choice;
|
|
48
45
|
}
|
|
49
|
-
async function promptForCapturedOutputWorktree(worktrees) {
|
|
50
|
-
const options = worktrees.map((worktree) => ({
|
|
51
|
-
value: worktree.path,
|
|
52
|
-
label: worktree.branch ?? '(detached)',
|
|
53
|
-
hint: worktree.path,
|
|
54
|
-
}));
|
|
55
|
-
const prompt = new SelectPrompt({
|
|
56
|
-
input: process.stdin,
|
|
57
|
-
options,
|
|
58
|
-
output: process.stderr,
|
|
59
|
-
render() {
|
|
60
|
-
const lines = ['Choose a worktree'];
|
|
61
|
-
switch (this.state) {
|
|
62
|
-
case 'submit': {
|
|
63
|
-
const selected = this.options[this.cursor];
|
|
64
|
-
lines.push(`> ${selected.label} (${selected.hint})`);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
case 'cancel':
|
|
68
|
-
lines.push('> canceled');
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
lines.push(...this.options.map((option, index) => {
|
|
72
|
-
const prefix = index === this.cursor ? '> ' : ' ';
|
|
73
|
-
return `${prefix}${option.label} (${option.hint})`;
|
|
74
|
-
}));
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
return `${lines.join('\n')}\n`;
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
const choice = await prompt.prompt();
|
|
81
|
-
if (isCoreCancel(choice)) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return choice;
|
|
85
|
-
}
|
|
86
|
-
function shouldUseCapturedOutputPrompt(options) {
|
|
87
|
-
return (!options.branch &&
|
|
88
|
-
options.print === true &&
|
|
89
|
-
process.env[GO_TTY_PROMPT_ENV] === '1');
|
|
90
|
-
}
|
package/dist/init.js
CHANGED
|
@@ -34,8 +34,37 @@ function gji --wraps gji --description 'gji shell integration'
|
|
|
34
34
|
return $status
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
set -l
|
|
38
|
-
or return
|
|
37
|
+
set -l output_file (mktemp -t gji-go.XXXXXX)
|
|
38
|
+
or return 1
|
|
39
|
+
env GJI_GO_OUTPUT_FILE=$output_file command gji go $argv
|
|
40
|
+
or begin
|
|
41
|
+
set -l status_code $status
|
|
42
|
+
rm -f $output_file
|
|
43
|
+
return $status_code
|
|
44
|
+
end
|
|
45
|
+
set -l target (cat $output_file)
|
|
46
|
+
rm -f $output_file
|
|
47
|
+
cd $target
|
|
48
|
+
return $status
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if test (count $argv) -gt 0; and test $argv[1] = root
|
|
52
|
+
set -e argv[1]
|
|
53
|
+
if test (count $argv) -gt 0; and test $argv[1] = --print
|
|
54
|
+
command gji root $argv
|
|
55
|
+
return $status
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
set -l output_file (mktemp -t gji-root.XXXXXX)
|
|
59
|
+
or return 1
|
|
60
|
+
env GJI_ROOT_OUTPUT_FILE=$output_file command gji root $argv
|
|
61
|
+
or begin
|
|
62
|
+
set -l status_code $status
|
|
63
|
+
rm -f $output_file
|
|
64
|
+
return $status_code
|
|
65
|
+
end
|
|
66
|
+
set -l target (cat $output_file)
|
|
67
|
+
rm -f $output_file
|
|
39
68
|
cd $target
|
|
40
69
|
return $status
|
|
41
70
|
end
|
|
@@ -56,9 +85,28 @@ gji() {
|
|
|
56
85
|
fi
|
|
57
86
|
|
|
58
87
|
local target
|
|
59
|
-
local
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
local output_file
|
|
89
|
+
output_file="$(mktemp -t gji-go.XXXXXX)" || return 1
|
|
90
|
+
GJI_GO_OUTPUT_FILE="$output_file" command gji go "$@" || { local status=$?; rm -f "$output_file"; return $status; }
|
|
91
|
+
target="$(cat "$output_file")"
|
|
92
|
+
rm -f "$output_file"
|
|
93
|
+
cd "$target" || return $?
|
|
94
|
+
return 0
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
if [ "$1" = "root" ]; then
|
|
98
|
+
shift
|
|
99
|
+
if [ "\${1:-}" = "--print" ]; then
|
|
100
|
+
command gji root "$@"
|
|
101
|
+
return $?
|
|
102
|
+
fi
|
|
103
|
+
|
|
104
|
+
local target
|
|
105
|
+
local output_file
|
|
106
|
+
output_file="$(mktemp -t gji-root.XXXXXX)" || return 1
|
|
107
|
+
GJI_ROOT_OUTPUT_FILE="$output_file" command gji root "$@" || { local status=$?; rm -f "$output_file"; return $status; }
|
|
108
|
+
target="$(cat "$output_file")"
|
|
109
|
+
rm -f "$output_file"
|
|
62
110
|
cd "$target" || return $?
|
|
63
111
|
return 0
|
|
64
112
|
fi
|
package/dist/root.d.ts
CHANGED
package/dist/root.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
1
2
|
import { detectRepository } from './repo.js';
|
|
3
|
+
const ROOT_OUTPUT_FILE_ENV = 'GJI_ROOT_OUTPUT_FILE';
|
|
2
4
|
export async function runRootCommand(options) {
|
|
3
5
|
const repository = await detectRepository(options.cwd);
|
|
4
|
-
|
|
6
|
+
const output = `${repository.repoRoot}\n`;
|
|
7
|
+
if (!options.print && process.env[ROOT_OUTPUT_FILE_ENV]) {
|
|
8
|
+
await writeFile(process.env[ROOT_OUTPUT_FILE_ENV], output, 'utf8');
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
options.stdout(output);
|
|
5
12
|
return 0;
|
|
6
13
|
}
|