repown 0.4.0 → 0.5.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.
- package/CHANGELOG.md +99 -1
- package/README.md +4 -1
- package/dist/cli.js +4 -4
- package/dist/commands/accounts.js +20 -14
- package/dist/commands/doctor.js +7 -5
- package/dist/commands/fix.js +5 -5
- package/dist/commands/guard.js +7 -5
- package/dist/commands/off.js +4 -4
- package/dist/commands/reauthor.js +5 -5
- package/dist/commands/scan.js +9 -7
- package/dist/commands/setup.js +3 -3
- package/dist/commands/start.js +6 -6
- package/dist/commands/status.js +20 -16
- package/dist/commands/use.js +18 -14
- package/dist/core/blockers.js +8 -7
- package/dist/core/config-snapshot.js +97 -0
- package/dist/core/credential/gcm.js +3 -3
- package/dist/core/credential/gh.js +14 -6
- package/dist/core/credential/repair.js +1 -1
- package/dist/core/git.js +27 -4
- package/dist/core/guard/check.js +44 -8
- package/dist/core/guard/hook.js +1 -1
- package/dist/core/hosts/github.js +43 -12
- package/dist/core/hosts/index.js +21 -3
- package/dist/core/identity.js +1 -1
- package/dist/core/inspect.js +19 -8
- package/dist/core/push-destination.js +1 -1
- package/dist/core/push-state.js +12 -8
- package/dist/core/reauthor.js +3 -3
- package/dist/core/registry.js +12 -5
- package/dist/core/unpushed.js +10 -9
- package/dist/program.js +10 -10
- package/dist/ui/args.js +3 -3
- package/dist/ui/command.js +1 -1
- package/dist/ui/dispatch.js +6 -6
- package/dist/ui/format.js +31 -0
- package/dist/ui/help.js +2 -2
- package/dist/ui/prompt.js +1 -1
- package/dist/wizard/clack.js +56 -21
- package/dist/wizard/engine.js +1 -1
- package/dist/wizard/home-context.js +23 -10
- package/dist/wizard/home-flow.js +33 -11
- package/dist/wizard/home-run.js +92 -44
- package/dist/wizard/home-text.js +18 -3
- package/dist/wizard/plain.js +2 -2
- package/dist/wizard/review-text.js +19 -4
- package/dist/wizard/setup-changes.js +2 -2
- package/dist/wizard/setup-context.js +22 -18
- package/dist/wizard/setup-flow.js +115 -35
- package/dist/wizard/setup-run.js +31 -28
- package/npm-shrinkwrap.json +378 -17
- package/package.json +3 -3
package/dist/program.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// The command table. cli.ts starts the program; the start screen's Show help
|
|
2
2
|
// loads this same table. Importing this file does not run repown.
|
|
3
3
|
export const COMMANDS = {
|
|
4
|
-
status: async () => (await import(
|
|
5
|
-
use: async () => (await import(
|
|
6
|
-
off: async () => (await import(
|
|
7
|
-
doctor: async () => (await import(
|
|
8
|
-
fix: async () => (await import(
|
|
9
|
-
reauthor: async () => (await import(
|
|
10
|
-
guard: async () => (await import(
|
|
11
|
-
accounts: async () => (await import(
|
|
12
|
-
scan: async () => (await import(
|
|
13
|
-
setup: async () => (await import(
|
|
4
|
+
status: async () => (await import('./commands/status.js')).default,
|
|
5
|
+
use: async () => (await import('./commands/use.js')).default,
|
|
6
|
+
off: async () => (await import('./commands/off.js')).default,
|
|
7
|
+
doctor: async () => (await import('./commands/doctor.js')).default,
|
|
8
|
+
fix: async () => (await import('./commands/fix.js')).default,
|
|
9
|
+
reauthor: async () => (await import('./commands/reauthor.js')).default,
|
|
10
|
+
guard: async () => (await import('./commands/guard.js')).default,
|
|
11
|
+
accounts: async () => (await import('./commands/accounts.js')).default,
|
|
12
|
+
scan: async () => (await import('./commands/scan.js')).default,
|
|
13
|
+
setup: async () => (await import('./commands/setup.js')).default,
|
|
14
14
|
};
|
package/dist/ui/args.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
// earlier bug: `repown use --gh octocat` read "octocat" as --gh's value and left
|
|
10
10
|
// no account), an unknown option is refused rather than silently dropped, and
|
|
11
11
|
// so is an extra positional.
|
|
12
|
-
import { Git } from
|
|
13
|
-
import { ok, err } from
|
|
14
|
-
import { suggest } from
|
|
12
|
+
import { Git } from '../core/git.js';
|
|
13
|
+
import { ok, err } from '../core/result.js';
|
|
14
|
+
import { suggest } from './suggest.js';
|
|
15
15
|
export const NO_POSITIONALS = { min: 0, max: 0 };
|
|
16
16
|
/** For commands whose payload a script may read. Only `json` is a stable contract (ADR-014). */
|
|
17
17
|
export const FORMAT_OPTION = {
|
package/dist/ui/command.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// the same way, and one renderer (ui/help.ts) generate help for all of them
|
|
6
6
|
// from the same declarations, so help can never drift from what the parser
|
|
7
7
|
// actually accepts.
|
|
8
|
-
import { NO_POSITIONALS } from
|
|
8
|
+
import { NO_POSITIONALS } from './args.js';
|
|
9
9
|
export function isGroup(entry) {
|
|
10
10
|
return 'actions' in entry;
|
|
11
11
|
}
|
package/dist/ui/dispatch.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
//
|
|
6
6
|
// Kept apart from src/cli.ts so a second program (the release tool in scripts/)
|
|
7
7
|
// gets the same grammar without importing cli.ts, which runs repown.
|
|
8
|
-
import { parseArgs, hasHelpFlag } from
|
|
9
|
-
import { isGroup, resolveAlias, specFor } from
|
|
10
|
-
import { renderHelpFor } from
|
|
11
|
-
import { suggest } from
|
|
12
|
-
import { ok, err } from
|
|
13
|
-
import * as out from
|
|
8
|
+
import { parseArgs, hasHelpFlag } from './args.js';
|
|
9
|
+
import { isGroup, resolveAlias, specFor } from './command.js';
|
|
10
|
+
import { renderHelpFor } from './help.js';
|
|
11
|
+
import { suggest } from './suggest.js';
|
|
12
|
+
import { ok, err } from '../core/result.js';
|
|
13
|
+
import * as out from './format.js';
|
|
14
14
|
/** Every command the program declares, in declaration order. Help uses this, and so can a runner. */
|
|
15
15
|
export async function loadEntries(commands) {
|
|
16
16
|
const names = Object.keys(commands);
|
package/dist/ui/format.js
CHANGED
|
@@ -8,6 +8,7 @@ const COLOURS = {
|
|
|
8
8
|
green: '\x1b[32m',
|
|
9
9
|
yellow: '\x1b[33m',
|
|
10
10
|
red: '\x1b[31m',
|
|
11
|
+
cyan: '\x1b[36m',
|
|
11
12
|
dim: '\x1b[2m',
|
|
12
13
|
reset: '\x1b[0m',
|
|
13
14
|
};
|
|
@@ -33,6 +34,36 @@ export function useColour(stream) {
|
|
|
33
34
|
function paint(stream, colour, text) {
|
|
34
35
|
return useColour(stream) ? COLOURS[colour] + text + COLOURS.reset : text;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether the terminal draws symbols beyond ASCII: the signals @clack/prompts draws its own
|
|
39
|
+
* frame by, so a mark and the frame around it never disagree. Windows' legacy console does
|
|
40
|
+
* not; Windows Terminal, VS Code and mintty (TERM=xterm-256color) do (ADR-027).
|
|
41
|
+
*/
|
|
42
|
+
export function unicodeTerminal(env = process.env, platform = process.platform) {
|
|
43
|
+
if (platform !== 'win32')
|
|
44
|
+
return env['TERM'] !== 'linux';
|
|
45
|
+
return Boolean(env['CI'] || env['WT_SESSION'] || env['TERMINUS_SUBLIME'])
|
|
46
|
+
|| env['ConEmuTask'] === '{cmd::Cmder}'
|
|
47
|
+
|| ['Terminus-Sublime', 'vscode'].includes(env['TERM_PROGRAM'] ?? '')
|
|
48
|
+
|| ['xterm-256color', 'alacritty'].includes(env['TERM'] ?? '')
|
|
49
|
+
|| env['TERMINAL_EMULATOR'] === 'JetBrains-JediTerm';
|
|
50
|
+
}
|
|
51
|
+
/** Each mark's colour, its symbol, and the ASCII stand-in where Unicode can't be drawn. */
|
|
52
|
+
const MARKS = {
|
|
53
|
+
ok: { colour: 'green', unicode: '✔', ascii: '+' },
|
|
54
|
+
warn: { colour: 'yellow', unicode: '▲', ascii: '!' },
|
|
55
|
+
};
|
|
56
|
+
/** `text` led by a coloured mark where `stream` has colour; exactly `text` where it has none. */
|
|
57
|
+
export function marked(kind, stream, text) {
|
|
58
|
+
if (!useColour(stream))
|
|
59
|
+
return text;
|
|
60
|
+
const mark = MARKS[kind];
|
|
61
|
+
return paint(stream, mark.colour, unicodeTerminal() ? mark.unicode : mark.ascii) + ' ' + text;
|
|
62
|
+
}
|
|
63
|
+
/** A command, cyan where `stream` has colour. */
|
|
64
|
+
export function accent(stream, text) {
|
|
65
|
+
return paint(stream, 'cyan', text);
|
|
66
|
+
}
|
|
36
67
|
function status(level, tag, message) {
|
|
37
68
|
const word = paint(level.stream, level.colour, level.word.padEnd(5));
|
|
38
69
|
level.stream.write(word + ' ' + tag.padEnd(10) + ' ' + message + '\n');
|
package/dist/ui/help.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// `out.line` calls, and nothing here is reachable except by an explicit
|
|
6
6
|
// `--help`/`-h`/`help` request. A command's `run()` never sees a help request --
|
|
7
7
|
// cli.ts intercepts it before parsing the command's own arguments.
|
|
8
|
-
import { GLOBAL_OPTIONS } from
|
|
9
|
-
import { isGroup, optionsOf } from
|
|
8
|
+
import { GLOBAL_OPTIONS } from './args.js';
|
|
9
|
+
import { isGroup, optionsOf } from './command.js';
|
|
10
10
|
export function renderTopHelp(entries) {
|
|
11
11
|
return [
|
|
12
12
|
...topHeader(entries),
|
package/dist/ui/prompt.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// whatever a command actually produces, so `repown accounts add x | tee log` does
|
|
11
11
|
// not interleave a prompt into the log.
|
|
12
12
|
import { createInterface } from 'node:readline/promises';
|
|
13
|
-
import { ok, err } from
|
|
13
|
+
import { ok, err } from '../core/result.js';
|
|
14
14
|
export function interactive() {
|
|
15
15
|
return process.stdin.isTTY === true && process.stderr.isTTY === true;
|
|
16
16
|
}
|
package/dist/wizard/clack.js
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
// text question, offered from the second question on. Esc and Ctrl-C cancel.
|
|
9
9
|
import { styleText } from 'node:util';
|
|
10
10
|
import * as p from '@clack/prompts';
|
|
11
|
-
import { BACK, CANCEL } from
|
|
12
|
-
import { BACK_WORD } from
|
|
13
|
-
import { BACK_TO_REVIEW, PICK_QUESTION, RUN_THIS_STEP, reviewDefault, reviewLines, reviewOptions, reviewQuestion, stepConfirmLines, stepOptions, textWidth, wrap } from
|
|
11
|
+
import { BACK, CANCEL } from './engine.js';
|
|
12
|
+
import { BACK_WORD } from './plain.js';
|
|
13
|
+
import { BACK_TO_REVIEW, COMMAND_MARK, PICK_QUESTION, RUN_THIS_STEP, labelOf, reviewDefault, reviewLines, reviewOptions, reviewQuestion, stepConfirmLines, stepOptions, textWidth, wrap } from './review-text.js';
|
|
14
14
|
/** A value no real choice can have. */
|
|
15
15
|
const GO_BACK = '\u0000back';
|
|
16
16
|
export function clackPrompter(streams) {
|
|
17
17
|
const io = { input: streams.input, output: streams.output };
|
|
18
18
|
return {
|
|
19
|
-
ask: (step, asked) =>
|
|
19
|
+
ask: (step, asked) => askStep(step, asked, io),
|
|
20
20
|
review: (review) => showReview(review, io),
|
|
21
21
|
pickStep: (steps) => pickClack(steps, io),
|
|
22
22
|
choose: (message, options) => chooseClack(message, options, io),
|
|
@@ -24,18 +24,23 @@ export function clackPrompter(streams) {
|
|
|
24
24
|
show: (lines) => logLines(io, lines),
|
|
25
25
|
confirmStep: (confirm) => showStep(confirm, io),
|
|
26
26
|
close: () => { },
|
|
27
|
-
intro: (title) => p.intro(title, io),
|
|
27
|
+
intro: (title) => p.intro(badge(title), io),
|
|
28
28
|
// After a cancel, clack has already drawn the gutter's last line.
|
|
29
|
-
outro: (message, cancelled) => (cancelled ? p.cancel(message, io) : p.outro(message, io)),
|
|
29
|
+
outro: (message, cancelled) => (cancelled ? p.cancel(message, io) : p.outro(commandOr(message), io)),
|
|
30
30
|
// A line, not clack's spinner: the spinner takes over Ctrl-C and exits 0, where a
|
|
31
31
|
// cancel must exit 130.
|
|
32
32
|
busy: (message) => p.log.step(message, io),
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
/** The title black on cyan. Its padding only comes with the colour, so a plain title is unchanged. */
|
|
36
|
+
function badge(title) {
|
|
37
|
+
const padded = ' ' + title + ' ';
|
|
38
|
+
const styled = styleText(['bgCyan', 'black'], padded);
|
|
39
|
+
return styled === padded ? title : styled;
|
|
40
|
+
}
|
|
41
|
+
/** A `$ command` hand-over line cyan; any other closing line as it is. */
|
|
42
|
+
function commandOr(message) {
|
|
43
|
+
return message.startsWith(COMMAND_MARK) ? styleText('cyan', message) : message;
|
|
39
44
|
}
|
|
40
45
|
async function pickClack(steps, io) {
|
|
41
46
|
const id = await p.select({ ...io, message: PICK_QUESTION, options: pickOptions(steps) });
|
|
@@ -77,13 +82,13 @@ function backOption(asked) {
|
|
|
77
82
|
async function askSelect(step, asked, io) {
|
|
78
83
|
const options = [...asked.choices.map((choice) => ({ ...choice })), ...backOption(asked)];
|
|
79
84
|
const preset = typeof asked.initial === 'string' ? { initialValue: asked.initial } : {};
|
|
80
|
-
const value = await p.select({ ...io, ...preset, message: messageOf(step, io), options });
|
|
85
|
+
const value = await p.select({ ...io, ...preset, message: messageOf(step, io, asked.detail), options });
|
|
81
86
|
if (p.isCancel(value))
|
|
82
87
|
return CANCEL;
|
|
83
88
|
return value === GO_BACK ? BACK : value;
|
|
84
89
|
}
|
|
85
90
|
async function askConfirm(step, asked, io) {
|
|
86
|
-
const value = await p.select({ ...io, message: messageOf(step, io), initialValue: asked.initial === true ? 'yes' : 'no',
|
|
91
|
+
const value = await p.select({ ...io, message: messageOf(step, io, asked.detail), initialValue: asked.initial === true ? 'yes' : 'no',
|
|
87
92
|
options: [{ value: 'yes', label: 'Yes' }, { value: 'no', label: 'No' }, ...backOption(asked)] });
|
|
88
93
|
if (p.isCancel(value))
|
|
89
94
|
return CANCEL;
|
|
@@ -92,7 +97,7 @@ async function askConfirm(step, asked, io) {
|
|
|
92
97
|
async function askText(step, asked, io) {
|
|
93
98
|
const preset = typeof asked.initial === 'string' ? { initialValue: asked.initial } : {};
|
|
94
99
|
const extra = asked.canGoBack ? 'type ' + BACK_WORD + ' to go back' : undefined;
|
|
95
|
-
const value = await p.text({ ...io, ...preset, message: messageOf(step, io, extra),
|
|
100
|
+
const value = await p.text({ ...io, ...preset, message: messageOf(step, io, asked.detail, extra),
|
|
96
101
|
validate: (typed) => (isBack(typed, asked) ? undefined : step.validate?.((typed ?? '').trim()) ?? undefined) });
|
|
97
102
|
if (p.isCancel(value))
|
|
98
103
|
return CANCEL;
|
|
@@ -104,28 +109,58 @@ function isBack(typed, asked) {
|
|
|
104
109
|
}
|
|
105
110
|
/**
|
|
106
111
|
* clack draws its gutter in front of a select's second line but not a text prompt's,
|
|
107
|
-
* so a text question draws it itself.
|
|
112
|
+
* so a text question draws it itself, with clack's own bar (`|` where Unicode isn't drawn).
|
|
113
|
+
*/
|
|
114
|
+
const TEXT_GUTTER = styleText('gray', p.S_BAR) + ' ';
|
|
115
|
+
/**
|
|
116
|
+
* The question, and under it the hint and the step's detail, wrapped in the gutter --
|
|
117
|
+
* visible whatever the answer shows. The detail sits in the question's own block, as the
|
|
118
|
+
* plain prompter draws it, never as a line above that reads as the previous answer's.
|
|
108
119
|
*/
|
|
109
|
-
|
|
110
|
-
/** The question, and under it the hint, wrapped in the gutter -- visible whatever the answer shows. */
|
|
111
|
-
function messageOf(step, io, extra) {
|
|
112
|
-
const hint = [step.hint, extra].filter((part) => part).join(' · ');
|
|
120
|
+
function messageOf(step, io, detail, extra) {
|
|
113
121
|
const gutter = step.kind === 'text' ? TEXT_GUTTER : '';
|
|
114
|
-
|
|
122
|
+
const width = widthOf(io, GUTTER);
|
|
123
|
+
const notes = [step.hint, detail].flatMap((text) => (text ? wrap(text, width) : []));
|
|
124
|
+
return [step.message, ...hintRows(notes, extra, width)].join('\n' + gutter);
|
|
125
|
+
}
|
|
126
|
+
/** The hint rows, then the extra ("type < to go back") on the last row if it fits whole, else on its own. */
|
|
127
|
+
function hintRows(rows, extra, width) {
|
|
128
|
+
if (!extra)
|
|
129
|
+
return [...rows];
|
|
130
|
+
const joined = rows.length > 0 ? rows[rows.length - 1] + ' · ' + extra : extra;
|
|
131
|
+
if (joined.length <= width)
|
|
132
|
+
return [...rows.slice(0, -1), joined];
|
|
133
|
+
return [...rows, ...wrap(extra, width)];
|
|
115
134
|
}
|
|
116
135
|
async function showStep(confirm, io) {
|
|
117
136
|
logLines(io, stepConfirmLines(confirm));
|
|
118
137
|
return chosen(confirm, io);
|
|
119
138
|
}
|
|
120
139
|
function logLines(io, lines) {
|
|
121
|
-
p.log.message(lines.flatMap((text) =>
|
|
140
|
+
p.log.message(lines.flatMap((text) => accented(text, widthOf(io, GUTTER))).join('\n'), io);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* One shown line, wrapped, then styled: a label's value bold cyan, a `$ command` cyan.
|
|
144
|
+
* Styling after wrapping keeps every line as wide as it is without colour (ADR-027).
|
|
145
|
+
*/
|
|
146
|
+
function accented(text, width) {
|
|
147
|
+
const rows = wrap(text, width);
|
|
148
|
+
if (text.startsWith(COMMAND_MARK))
|
|
149
|
+
return rows.map((row) => styleText('cyan', row));
|
|
150
|
+
const label = labelOf(text);
|
|
151
|
+
return rows.map((row, index) => accentLine(row, index === 0 ? label : ' '.repeat(label.length)));
|
|
152
|
+
}
|
|
153
|
+
function accentLine(line, label) {
|
|
154
|
+
if (!label || !line.startsWith(label))
|
|
155
|
+
return line;
|
|
156
|
+
return label + styleText(['bold', 'cyan'], line.slice(label.length));
|
|
122
157
|
}
|
|
123
158
|
async function chosen(confirm, io) {
|
|
124
159
|
const choice = await p.select({ ...io, message: RUN_THIS_STEP, options: stepOptions(), initialValue: confirm.initial });
|
|
125
160
|
return p.isCancel(choice) ? CANCEL : choice;
|
|
126
161
|
}
|
|
127
162
|
async function showReview(review, io) {
|
|
128
|
-
p.note(reviewLines(review, widthOf(io, BOX), (text) => styleText('
|
|
163
|
+
p.note(reviewLines(review, widthOf(io, BOX), (text) => styleText('cyan', text)).join('\n'), review.title, io);
|
|
129
164
|
const choice = await p.select({ ...io, message: reviewQuestion(review), options: reviewOptions(review),
|
|
130
165
|
initialValue: reviewDefault(review) });
|
|
131
166
|
return p.isCancel(choice) ? CANCEL : choice;
|
package/dist/wizard/engine.js
CHANGED
|
@@ -73,7 +73,7 @@ async function ask(step, at, context, prompter) {
|
|
|
73
73
|
const { answers, canGoBack } = at;
|
|
74
74
|
const initial = answers[step.id] ?? await step.initial?.(answers, context);
|
|
75
75
|
const choices = step.choices?.(answers, context) ?? [];
|
|
76
|
-
const detail = step.detail?.(answers, context);
|
|
76
|
+
const detail = await step.detail?.(answers, context);
|
|
77
77
|
return prompter.ask(drawn(step, answers, context), { initial, choices, detail, canGoBack });
|
|
78
78
|
}
|
|
79
79
|
function drawn(step, answers, context) {
|
|
@@ -3,19 +3,27 @@
|
|
|
3
3
|
// it cannot list is skipped; `repown scan` is the command that reports those.
|
|
4
4
|
import { readdir } from 'node:fs/promises';
|
|
5
5
|
import { join, relative, resolve, sep } from 'node:path';
|
|
6
|
-
import { Git } from
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
6
|
+
import { Git } from '../core/git.js';
|
|
7
|
+
import { snapshotOf } from '../core/config-snapshot.js';
|
|
8
|
+
import { inspectAuth, inspectRepo } from '../core/inspect.js';
|
|
9
|
+
import { planRepair } from '../core/credential/repair.js';
|
|
10
|
+
import { loadRegistry } from '../core/registry.js';
|
|
11
|
+
import { identityProblems } from '../commands/status.js';
|
|
12
|
+
import { CONCURRENCY, discover, mapLimited } from '../commands/scan.js';
|
|
13
|
+
import { signedInLogins } from './setup-flow.js';
|
|
12
14
|
/** How many levels below this folder the start screen looks. `repown scan` looks further. */
|
|
13
15
|
export const HOME_DEPTH = 2;
|
|
14
16
|
export async function readHome(cwd, deps = {}) {
|
|
15
|
-
const [registry, ghIsHelper, clones] = await Promise.all([
|
|
16
|
-
registryOf(deps), helperOf(cwd, deps), clonesOf(cwd, deps),
|
|
17
|
+
const [registry, ghIsHelper, clones, identity] = await Promise.all([
|
|
18
|
+
registryOf(deps), helperOf(cwd, deps), clonesOf(cwd, deps), (deps.identity ?? identityOf)(cwd),
|
|
17
19
|
]);
|
|
18
|
-
return { cwd: resolve(cwd), registry, ghIsHelper, clones };
|
|
20
|
+
return { cwd: resolve(cwd), registry, ghIsHelper, clones, identity };
|
|
21
|
+
}
|
|
22
|
+
/** Outside a clone, git's own lookup is the global (or system) value. */
|
|
23
|
+
async function identityOf(cwd) {
|
|
24
|
+
const git = new Git(cwd);
|
|
25
|
+
const [name, email] = await Promise.all([git.getConfig('user.name'), git.getConfig('user.email')]);
|
|
26
|
+
return { name, email };
|
|
19
27
|
}
|
|
20
28
|
function registryOf(deps) {
|
|
21
29
|
return deps.registry ? deps.registry() : loadRegistry();
|
|
@@ -85,7 +93,7 @@ async function childNames(cwd) {
|
|
|
85
93
|
}
|
|
86
94
|
async function describeClone(dir, deps) {
|
|
87
95
|
const inspect = deps.inspect ?? inspectRepo;
|
|
88
|
-
const repo = await inspect(new Git(dir));
|
|
96
|
+
const repo = await inspect(snapshotOf(new Git(dir)));
|
|
89
97
|
if (!repo.isRepo)
|
|
90
98
|
return null;
|
|
91
99
|
return { path: resolve(dir), setUp: identityProblems(repo).length === 0 };
|
|
@@ -99,3 +107,8 @@ function skipHomeEntry(name) {
|
|
|
99
107
|
return true;
|
|
100
108
|
return process.platform === 'win32' && name.toLowerCase() === 'appdata';
|
|
101
109
|
}
|
|
110
|
+
/** The github.com logins gh and Git Credential Manager are signed in as; read only when Record an account asks. */
|
|
111
|
+
export async function readSignedIn(cwd) {
|
|
112
|
+
const auth = await inspectAuth(new Git(cwd));
|
|
113
|
+
return signedInLogins(auth.ghPresent ? auth.gh : null, auth.stored);
|
|
114
|
+
}
|
package/dist/wizard/home-flow.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Pure: the summary, the menu and the clone list, and the command an action
|
|
2
2
|
// stands for. Drawing and running live in home-run.ts.
|
|
3
3
|
import { relative } from 'node:path';
|
|
4
|
-
import { registryPath } from
|
|
5
|
-
import { HOME_DEPTH } from
|
|
6
|
-
import { CD_NOTE, CHECK_MACHINE, HELPER_LINE, HINT_ACCOUNT, HINT_DOCTOR, HINT_FIX, NONE_RECORDED, NOT_SET_UP, QUIT, RECORD_ACCOUNT, SET_UP, SETUP_CLONE, SHOW_HELP, STOP_GH, clonesNone, clonesSome, couldNotRead, moreClones, recordedLine, setupHint, unreadableLine, } from
|
|
7
|
-
import { printable } from
|
|
4
|
+
import { registryPath } from '../core/registry.js';
|
|
5
|
+
import { HOME_DEPTH } from './home-context.js';
|
|
6
|
+
import { CD_NOTE, CHECK_MACHINE, HELPER_LINE, HINT_ACCOUNT, HINT_DOCTOR, HINT_FIX, HINT_REMOVE, NONE_RECORDED, NOT_SET_UP, QUIT, RECORD_ACCOUNT, REMOVE_ACCOUNT, SET_UP, SETUP_CLONE, SHOW_HELP, STOP_GH, clonesNone, clonesSome, couldNotRead, moreClones, recordedLine, setupHint, unreadableLine, } from './home-text.js';
|
|
7
|
+
import { addAccountArgv, printable } from './setup-flow.js';
|
|
8
8
|
/** Shown choices. `back` returns to the menu; the others run a command or leave. */
|
|
9
9
|
export const MENU = {
|
|
10
|
-
setup: 'setup', fix: 'fix', account: 'account', doctor: 'doctor', help: 'help', quit: 'quit',
|
|
10
|
+
setup: 'setup', fix: 'fix', account: 'account', remove: 'remove', doctor: 'doctor', help: 'help', quit: 'quit',
|
|
11
11
|
};
|
|
12
12
|
export const BACK = 'back';
|
|
13
13
|
const LIST_CAP = 20;
|
|
@@ -21,7 +21,21 @@ export function homeNote(home) {
|
|
|
21
21
|
return home.clones.length === 0 ? CD_NOTE : null;
|
|
22
22
|
}
|
|
23
23
|
export function menuItems(home) {
|
|
24
|
-
return [...setupItem(home), ...fixItem(home), ...
|
|
24
|
+
return [...setupItem(home), ...fixItem(home), RECORD, ...removeItem(home), ...AFTER_REMOVE];
|
|
25
|
+
}
|
|
26
|
+
/** A recorded account's choice value; prefixed so no login (`back`, say) is ever another choice. */
|
|
27
|
+
const ACCOUNT_VALUE = 'account:';
|
|
28
|
+
export function accountOfChoice(value) {
|
|
29
|
+
return value.startsWith(ACCOUNT_VALUE) ? value.slice(ACCOUNT_VALUE.length) : null;
|
|
30
|
+
}
|
|
31
|
+
/** The recorded accounts, each with the name and email it commits as. */
|
|
32
|
+
export function accountChoices(home) {
|
|
33
|
+
if (!home.registry.ok)
|
|
34
|
+
return [];
|
|
35
|
+
const accounts = home.registry.value.accounts;
|
|
36
|
+
return Object.keys(accounts).sort().map((login) => ({
|
|
37
|
+
value: ACCOUNT_VALUE + login, label: printable(login), hint: printable(accounts[login].name + ' <' + accounts[login].email + '>'),
|
|
38
|
+
}));
|
|
25
39
|
}
|
|
26
40
|
export function listedClones(home) {
|
|
27
41
|
const ordered = orderClones(home);
|
|
@@ -31,8 +45,8 @@ export function listedClones(home) {
|
|
|
31
45
|
}
|
|
32
46
|
/**
|
|
33
47
|
* The command the action stands for. `--cwd=<path>` is how setup's own plans spell
|
|
34
|
-
* it. `accounts add`
|
|
35
|
-
* that starts with a dash stays the account.
|
|
48
|
+
* it. `accounts add` is the very command setup runs for a new account: every answer
|
|
49
|
+
* as a flag, and `--` before the login, so a login that starts with a dash stays the account.
|
|
36
50
|
*/
|
|
37
51
|
export function commandFor(action) {
|
|
38
52
|
if (action.kind === 'setup')
|
|
@@ -40,7 +54,9 @@ export function commandFor(action) {
|
|
|
40
54
|
if (action.kind === 'fix')
|
|
41
55
|
return ['fix'];
|
|
42
56
|
if (action.kind === 'account')
|
|
43
|
-
return
|
|
57
|
+
return addAccountArgv(action);
|
|
58
|
+
if (action.kind === 'remove')
|
|
59
|
+
return ['accounts', 'remove', '--', action.login];
|
|
44
60
|
return ['doctor'];
|
|
45
61
|
}
|
|
46
62
|
function accountsText(registry) {
|
|
@@ -67,13 +83,19 @@ function setupItem(home) {
|
|
|
67
83
|
const pending = home.clones.filter((clone) => !clone.setUp).length;
|
|
68
84
|
return [{ value: MENU.setup, label: SETUP_CLONE, hint: setupHint(pending, home.clones.length) }];
|
|
69
85
|
}
|
|
86
|
+
/** Only when every entry reads: accounts remove refuses to rewrite a file it can't fully read. */
|
|
87
|
+
function removeItem(home) {
|
|
88
|
+
if (!home.registry.ok || home.registry.value.unreadable.length > 0)
|
|
89
|
+
return [];
|
|
90
|
+
return accountChoices(home).length > 0 ? [{ value: MENU.remove, label: REMOVE_ACCOUNT, hint: HINT_REMOVE }] : [];
|
|
91
|
+
}
|
|
70
92
|
function fixItem(home) {
|
|
71
93
|
if (!home.ghIsHelper)
|
|
72
94
|
return [];
|
|
73
95
|
return [{ value: MENU.fix, label: STOP_GH, hint: HINT_FIX }];
|
|
74
96
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
97
|
+
const RECORD = { value: MENU.account, label: RECORD_ACCOUNT, hint: HINT_ACCOUNT };
|
|
98
|
+
const AFTER_REMOVE = [
|
|
77
99
|
{ value: MENU.doctor, label: CHECK_MACHINE, hint: HINT_DOCTOR },
|
|
78
100
|
{ value: MENU.help, label: SHOW_HELP },
|
|
79
101
|
{ value: MENU.quit, label: QUIT },
|
package/dist/wizard/home-run.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
// The start screen: a summary of this folder, then one menu. Each action prints
|
|
2
2
|
// the command it stands for and runs that command's own run(). Loaded only
|
|
3
3
|
// through the runner start.ts returns, so a typed command never imports it.
|
|
4
|
+
// Once fix, doctor, accounts add or accounts remove has run, failed or not, the screen opens again (ADR-028).
|
|
4
5
|
//
|
|
5
6
|
// Quit exits 0. Esc and Ctrl-C exit 130, the same cancel setup uses. Neither writes.
|
|
6
|
-
import fixCommand from
|
|
7
|
-
import doctorCommand from
|
|
8
|
-
import accountsGroup from
|
|
9
|
-
import { COMMANDS } from
|
|
10
|
-
import { parseArgs } from
|
|
11
|
-
import { specFor } from
|
|
12
|
-
import { loadEntries } from
|
|
13
|
-
import * as out from
|
|
14
|
-
import { renderTopHelp } from
|
|
15
|
-
import {
|
|
16
|
-
import { readHome } from
|
|
17
|
-
import { BACK as HOME_BACK, MENU, commandFor, homeNote, listedClones, menuItems, summaryLines } from
|
|
18
|
-
import { BACK_LABEL, BUSY, CANCELLED,
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
7
|
+
import fixCommand from '../commands/fix.js';
|
|
8
|
+
import doctorCommand from '../commands/doctor.js';
|
|
9
|
+
import accountsGroup from '../commands/accounts.js';
|
|
10
|
+
import { COMMANDS } from '../program.js';
|
|
11
|
+
import { parseArgs } from '../ui/args.js';
|
|
12
|
+
import { specFor } from '../ui/command.js';
|
|
13
|
+
import { loadEntries } from '../ui/dispatch.js';
|
|
14
|
+
import * as out from '../ui/format.js';
|
|
15
|
+
import { renderTopHelp } from '../ui/help.js';
|
|
16
|
+
import { CANCEL, runFlow } from './engine.js';
|
|
17
|
+
import { readHome, readSignedIn } from './home-context.js';
|
|
18
|
+
import { BACK as HOME_BACK, MENU, accountChoices, accountOfChoice, commandFor, homeNote, listedClones, menuItems, summaryLines } from './home-flow.js';
|
|
19
|
+
import { BACK_LABEL, BUSY, CANCELLED, QUIT, WHAT_NEXT, WHICH_ACCOUNT, WHICH_CLONE, homeTitle, recordBlocked, removeLabel, removeNote, removeQuestion } from './home-text.js';
|
|
20
|
+
import { writeProblem } from '../core/registry.js';
|
|
21
|
+
import { formatCommand, loginStep, newAccountOf, printable, profileSteps } from './setup-flow.js';
|
|
22
|
+
import { COMMAND_MARK } from './review-text.js';
|
|
23
|
+
import { suggester } from './setup-context.js';
|
|
24
|
+
import { choosePrompter, runSetup } from './setup-run.js';
|
|
21
25
|
const CANCELLED_CODE = 130;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
validate: (value) => loginProblem(String(value)),
|
|
25
|
-
};
|
|
26
|
-
const LOGIN_ASKED = { initial: undefined, choices: [], detail: undefined, canGoBack: true };
|
|
26
|
+
/** The account questions from the top. Back from the login returns to the menu, as `opening`. */
|
|
27
|
+
const FIRST_PASS = { answers: {}, start: 0, given: new Set(), history: [], toOpening: true, showOpening: false };
|
|
27
28
|
export async function runHome(deps = {}) {
|
|
28
29
|
const prompter = deps.prompter ?? await choosePrompter();
|
|
29
30
|
try {
|
|
@@ -33,7 +34,16 @@ export async function runHome(deps = {}) {
|
|
|
33
34
|
prompter.close();
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
/** A machine-level action ran: open the start screen again, read afresh (ADR-028). */
|
|
38
|
+
const AGAIN = Symbol('again');
|
|
36
39
|
async function openHome(prompter, deps) {
|
|
40
|
+
for (;;) {
|
|
41
|
+
const code = await homeRound(prompter, deps);
|
|
42
|
+
if (code !== AGAIN)
|
|
43
|
+
return code;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function homeRound(prompter, deps) {
|
|
37
47
|
const cwd = deps.cwd ?? process.cwd();
|
|
38
48
|
prompter.intro?.(homeTitle(printable(cwd)));
|
|
39
49
|
prompter.busy?.(BUSY);
|
|
@@ -42,19 +52,20 @@ async function openHome(prompter, deps) {
|
|
|
42
52
|
const note = homeNote(home);
|
|
43
53
|
if (note)
|
|
44
54
|
prompter.note(note);
|
|
45
|
-
return chooseNext(prompter, home);
|
|
55
|
+
return chooseNext(prompter, home, deps);
|
|
46
56
|
}
|
|
47
|
-
async function chooseNext(prompter, home) {
|
|
57
|
+
async function chooseNext(prompter, home, deps) {
|
|
48
58
|
for (;;) {
|
|
49
59
|
const picked = await prompter.choose(WHAT_NEXT, menuItems(home));
|
|
50
60
|
if (picked === CANCEL)
|
|
51
61
|
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
52
|
-
const code = await dispatchChoice(picked, prompter, home);
|
|
62
|
+
const code = await dispatchChoice(picked, prompter, home, deps);
|
|
53
63
|
if (code !== null)
|
|
54
64
|
return code;
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
|
-
|
|
67
|
+
/** Setup, help and Quit end the screen; once fix, doctor, accounts add or remove has run, it comes back. */
|
|
68
|
+
async function dispatchChoice(picked, prompter, home, deps) {
|
|
58
69
|
if (picked === MENU.quit)
|
|
59
70
|
return finish(prompter, QUIT, 0);
|
|
60
71
|
if (picked === MENU.help)
|
|
@@ -62,11 +73,13 @@ async function dispatchChoice(picked, prompter, home) {
|
|
|
62
73
|
if (picked === MENU.setup)
|
|
63
74
|
return pickClone(prompter, home);
|
|
64
75
|
if (picked === MENU.fix)
|
|
65
|
-
return runOwn(prompter, fixCommand, [], commandFor({ kind: 'fix' }));
|
|
76
|
+
return again(runOwn(prompter, fixCommand, [], commandFor({ kind: 'fix' })));
|
|
66
77
|
if (picked === MENU.doctor)
|
|
67
|
-
return runOwn(prompter, doctorCommand, [], commandFor({ kind: 'doctor' }));
|
|
78
|
+
return again(runOwn(prompter, doctorCommand, [], commandFor({ kind: 'doctor' })));
|
|
68
79
|
if (picked === MENU.account)
|
|
69
|
-
return recordAccount(prompter);
|
|
80
|
+
return recordAccount(prompter, home, deps);
|
|
81
|
+
if (picked === MENU.remove)
|
|
82
|
+
return removeAccount(prompter, home);
|
|
70
83
|
return finish(prompter, QUIT, 0);
|
|
71
84
|
}
|
|
72
85
|
async function pickClone(prompter, home) {
|
|
@@ -86,25 +99,60 @@ async function runInClone(prompter, cwd) {
|
|
|
86
99
|
handOver(prompter, argv);
|
|
87
100
|
return runSetup(setupArgs(cwd), { interactive: true, prompter });
|
|
88
101
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Setup's own questions for a new account (login, host, name, email) in this frame,
|
|
104
|
+
* then `accounts add` with every answer as a flag, so it has nothing left to ask.
|
|
105
|
+
*/
|
|
106
|
+
async function recordAccount(prompter, home, deps) {
|
|
107
|
+
// The same reasons accounts add would give on save, before anyone answers four questions for nothing.
|
|
108
|
+
const blocked = writeProblem(home.registry);
|
|
109
|
+
if (blocked) {
|
|
110
|
+
prompter.note(recordBlocked(printable(blocked)));
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const ctx = accountContext(home, deps);
|
|
114
|
+
const walk = await runFlow({ steps: [loginStep(ctx), ...profileSteps(ctx)] }, ctx, FIRST_PASS, prompter);
|
|
115
|
+
if (walk.status === 'cancelled')
|
|
92
116
|
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
93
|
-
if (
|
|
117
|
+
if (walk.status === 'opening')
|
|
94
118
|
return null;
|
|
95
|
-
const argv = commandFor({ kind: 'account',
|
|
96
|
-
return runOwn(prompter, accountsGroup.actions['add'],
|
|
119
|
+
const argv = commandFor({ kind: 'account', ...newAccountOf(walk.answers, ctx) });
|
|
120
|
+
return again(runOwn(prompter, accountsGroup.actions['add'], argv.slice(2), argv));
|
|
97
121
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
/** Which account, then a confirm that says what stays; Back from either returns to the menu. */
|
|
123
|
+
async function removeAccount(prompter, home) {
|
|
124
|
+
const picked = await prompter.choose(WHICH_ACCOUNT, [...accountChoices(home), { value: HOME_BACK, label: BACK_LABEL }]);
|
|
125
|
+
if (picked === CANCEL)
|
|
126
|
+
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
127
|
+
const login = accountOfChoice(picked);
|
|
128
|
+
if (login === null)
|
|
129
|
+
return null;
|
|
130
|
+
const shown = printable(login);
|
|
131
|
+
showLines(prompter, [removeNote(shown)]);
|
|
132
|
+
// Back first: Enter twice in a row must not remove anything.
|
|
133
|
+
const sure = await prompter.choose(removeQuestion(shown), [{ value: HOME_BACK, label: BACK_LABEL }, { value: MENU.remove, label: removeLabel(shown) }]);
|
|
134
|
+
if (sure === CANCEL)
|
|
135
|
+
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
136
|
+
if (sure === HOME_BACK)
|
|
137
|
+
return null;
|
|
138
|
+
const argv = commandFor({ kind: 'remove', login });
|
|
139
|
+
return again(runOwn(prompter, accountsGroup.actions['remove'], argv.slice(2), argv));
|
|
140
|
+
}
|
|
141
|
+
/** The command has said how it went, in its own output; the start screen opens again. */
|
|
142
|
+
async function again(ran) {
|
|
143
|
+
await ran;
|
|
144
|
+
return AGAIN;
|
|
145
|
+
}
|
|
146
|
+
function accountContext(home, deps) {
|
|
147
|
+
const recorded = home.registry.ok ? home.registry.value.accounts : {};
|
|
148
|
+
return {
|
|
149
|
+
recorded, host: 'github', machineIdentity: home.identity,
|
|
150
|
+
suggest: deps.suggest ?? suggester(), signedIn: deps.signedIn ?? once(() => readSignedIn(home.cwd)),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function once(read) {
|
|
154
|
+
let kept;
|
|
155
|
+
return () => (kept ??= read());
|
|
108
156
|
}
|
|
109
157
|
async function runOwn(prompter, command, tokens, argv) {
|
|
110
158
|
handOver(prompter, argv);
|
|
@@ -133,7 +181,7 @@ function showLines(prompter, lines) {
|
|
|
133
181
|
}
|
|
134
182
|
/** Closes the start screen's frame on the command it hands over to. */
|
|
135
183
|
function handOver(prompter, argv) {
|
|
136
|
-
const line =
|
|
184
|
+
const line = COMMAND_MARK + formatCommand(argv);
|
|
137
185
|
if (prompter.outro)
|
|
138
186
|
prompter.outro(line);
|
|
139
187
|
else
|