repown 0.2.0 → 0.3.0
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 +21 -1
- package/README.md +9 -4
- package/dist/cli.js +7 -15
- package/dist/commands/scan.js +13 -6
- package/dist/commands/start.js +28 -10
- package/dist/program.js +13 -0
- package/dist/ui/dispatch.js +12 -4
- package/dist/ui/help.js +4 -3
- package/dist/wizard/clack.js +30 -15
- package/dist/wizard/home-context.js +101 -0
- package/dist/wizard/home-flow.js +90 -0
- package/dist/wizard/home-run.js +148 -0
- package/dist/wizard/home-text.js +50 -0
- package/dist/wizard/plain.js +13 -2
- package/dist/wizard/setup-flow.js +8 -3
- package/dist/wizard/setup-run.js +21 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-09-29
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- In a terminal, bare `repown` outside a clone, or in a bare repository, opens a
|
|
15
|
+
start screen. It shows the accounts on this machine, whether gh serves git's
|
|
16
|
+
credentials, and the clones found up to 2 levels below, then offers the next
|
|
17
|
+
command. Nothing changes until you pick one. Quit exits 0; Esc or Ctrl-C exits
|
|
18
|
+
130. With stdout redirected, a clone still prints status, and outside a clone it
|
|
19
|
+
still prints help (exit 0). Without a terminal on stdin or stderr, it is still
|
|
20
|
+
status.
|
|
21
|
+
- The start screen draws its summary inside its frame, and closes that frame with
|
|
22
|
+
the command it is about to run. Show help closes with `> repown --help`, then
|
|
23
|
+
prints the help. Inside a clone, bare `repown` draws its opening sentence inside
|
|
24
|
+
setup's frame. Typing `<` at Record an account's login question returns to the menu.
|
|
25
|
+
- The start screen looks inside a directory whose `.git` git refuses, with the levels
|
|
26
|
+
it has left, and does not search a bare repository for clones. Account names, and
|
|
27
|
+
the folder in the title, show control characters as escapes.
|
|
28
|
+
|
|
10
29
|
## [0.2.0] - 2026-09-28
|
|
11
30
|
|
|
12
31
|
### Added
|
|
@@ -86,7 +105,8 @@ commands. How a release is cut: [docs/RELEASING.md](docs/RELEASING.md).
|
|
|
86
105
|
contract for scripts.
|
|
87
106
|
- Runs on Node 20+ on Windows, macOS and Linux, with zero runtime dependencies.
|
|
88
107
|
|
|
89
|
-
[Unreleased]: https://github.com/makubexD/repown/compare/v0.
|
|
108
|
+
[Unreleased]: https://github.com/makubexD/repown/compare/v0.3.0...HEAD
|
|
109
|
+
[0.3.0]: https://github.com/makubexD/repown/compare/v0.2.0...v0.3.0
|
|
90
110
|
[0.2.0]: https://github.com/makubexD/repown/compare/v0.1.1...v0.2.0
|
|
91
111
|
[0.1.1]: https://github.com/makubexD/repown/compare/v0.1.0...v0.1.1
|
|
92
112
|
[0.1.0]: https://github.com/makubexD/repown/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ npm install -g repown
|
|
|
84
84
|
- **Update** with `npm install -g repown@latest`; guarded clones keep working
|
|
85
85
|
([ADR-003](docs/decisions/ADR-003-hook-calls-installed-cli.md)).
|
|
86
86
|
- **What gets installed:** one optional dependency, for the arrow-key prompts (without it,
|
|
87
|
-
`setup`
|
|
87
|
+
`repown setup` and the start screen ask with numbered choices), pinned exactly
|
|
88
88
|
([ADR-016](docs/decisions/ADR-016-clack-for-the-setup-wizard.md)). The package is
|
|
89
89
|
published from CI with provenance ([how](SECURITY.md#how-the-package-is-published)).
|
|
90
90
|
|
|
@@ -223,9 +223,14 @@ then commit and push.
|
|
|
223
223
|
|
|
224
224
|
| Where | What it does |
|
|
225
225
|
| --- | --- |
|
|
226
|
-
| A terminal, inside a clone (pinned or not) | Starts `repown setup
|
|
227
|
-
| A terminal, outside a clone |
|
|
228
|
-
|
|
|
226
|
+
| A terminal, inside a clone (pinned or not) | Starts `repown setup`. A line inside that screen says the clone isn't set up yet, or that a pinned clone is being checked ([card 5](docs/HOW-IT-WORKS.md#5-check-where-you-are)) |
|
|
227
|
+
| A terminal, outside a clone or in a bare repository | Opens the start screen ([card 14](docs/HOW-IT-WORKS.md#14-outside-a-clone)) |
|
|
228
|
+
| stdout redirected (stdin and stderr still terminals) | Status inside a clone. The top help outside a clone, exit 0 |
|
|
229
|
+
| No terminal (stdin or stderr is not one) | Status. Exit 1 outside a clone |
|
|
230
|
+
|
|
231
|
+
The start screen lists the accounts on this machine and the clones it found, then offers
|
|
232
|
+
the next command. The summary is in the frame. Picking a command closes the frame with
|
|
233
|
+
that command. Nothing changes until you pick one.
|
|
229
234
|
|
|
230
235
|
**Who is this clone?** `repown status` prints:
|
|
231
236
|
|
package/dist/cli.js
CHANGED
|
@@ -6,28 +6,20 @@
|
|
|
6
6
|
// type as `gh auth switch`, or it will not be typed. Everything longer than a
|
|
7
7
|
// word is a command you run once per clone or once per machine.
|
|
8
8
|
//
|
|
9
|
-
// This file only DECLARES the program: its
|
|
10
|
-
//
|
|
11
|
-
//
|
|
9
|
+
// This file only DECLARES the program: its version and its top help. The command
|
|
10
|
+
// table lives in program.ts, so the start screen can print that help without
|
|
11
|
+
// importing this file -- importing this module runs repown. With no arguments,
|
|
12
|
+
// `chooseDefault` loads commands/start.ts and picks setup, the start screen,
|
|
13
|
+
// status or the top help; any argument skips that. Dispatch itself --
|
|
12
14
|
// resolving a command, intercepting `--help`/`-h`/`help` before a command's
|
|
13
15
|
// own `run()` ever sees the arguments, and exiting 2 on a usage error -- lives
|
|
14
16
|
// in ui/dispatch.ts. Parsing the arguments lives in ui/args.ts, which a command
|
|
15
|
-
// can import without pulling in this file
|
|
17
|
+
// can import without pulling in this file.
|
|
16
18
|
import { readFileSync } from 'node:fs';
|
|
17
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { COMMANDS } from "./program.js";
|
|
18
21
|
import { renderTopHelp } from "./ui/help.js";
|
|
19
22
|
import { start } from "./ui/dispatch.js";
|
|
20
|
-
const COMMANDS = {
|
|
21
|
-
status: async () => (await import("./commands/status.js")).default,
|
|
22
|
-
use: async () => (await import("./commands/use.js")).default,
|
|
23
|
-
off: async () => (await import("./commands/off.js")).default,
|
|
24
|
-
doctor: async () => (await import("./commands/doctor.js")).default,
|
|
25
|
-
fix: async () => (await import("./commands/fix.js")).default,
|
|
26
|
-
guard: async () => (await import("./commands/guard.js")).default,
|
|
27
|
-
accounts: async () => (await import("./commands/accounts.js")).default,
|
|
28
|
-
scan: async () => (await import("./commands/scan.js")).default,
|
|
29
|
-
setup: async () => (await import("./commands/setup.js")).default,
|
|
30
|
-
};
|
|
31
23
|
function version() {
|
|
32
24
|
const path = fileURLToPath(new URL('../package.json', import.meta.url));
|
|
33
25
|
return JSON.parse(readFileSync(path, 'utf8')).version;
|
package/dist/commands/scan.js
CHANGED
|
@@ -65,8 +65,8 @@ export default {
|
|
|
65
65
|
* clones launched a thousand; calls then hit exec's timeout, and a killed
|
|
66
66
|
* `git config --get` reads as "not set" -- rows that looked unpinned but weren't.
|
|
67
67
|
*/
|
|
68
|
-
const CONCURRENCY = 6;
|
|
69
|
-
async function mapLimited(items, limit, work) {
|
|
68
|
+
export const CONCURRENCY = 6;
|
|
69
|
+
export async function mapLimited(items, limit, work) {
|
|
70
70
|
const results = new Array(items.length);
|
|
71
71
|
let next = 0;
|
|
72
72
|
const worker = async () => {
|
|
@@ -96,8 +96,12 @@ function invalidRoot(root) {
|
|
|
96
96
|
return 'not a directory: ' + root;
|
|
97
97
|
return null;
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
|
|
99
|
+
/**
|
|
100
|
+
* A directory that cannot be listed is reported, never silently left out of the audit.
|
|
101
|
+
* `skip`, when given, drops those child names before they are entered. Scan does not pass one,
|
|
102
|
+
* so its walk is unchanged; the start screen passes the extra names it ignores.
|
|
103
|
+
*/
|
|
104
|
+
export async function discover(at, depth, unreadable, skip) {
|
|
101
105
|
if (depth < 0 || !existsSync(at.path))
|
|
102
106
|
return [];
|
|
103
107
|
if (existsSync(join(at.path, '.git')))
|
|
@@ -111,11 +115,14 @@ async function discover(at, depth, unreadable) {
|
|
|
111
115
|
return [];
|
|
112
116
|
}
|
|
113
117
|
const directories = entries
|
|
114
|
-
.filter((entry) => entry.isDirectory() && entry.name !== 'node_modules')
|
|
118
|
+
.filter((entry) => entry.isDirectory() && entry.name !== 'node_modules' && !skip?.(entry.name))
|
|
115
119
|
.map((entry) => join(at.path, entry.name));
|
|
116
|
-
const nested = await Promise.all(directories.map((child) => discover(
|
|
120
|
+
const nested = await Promise.all(directories.map((child) => discover(childAt(at.root, child), depth - 1, unreadable, skip)));
|
|
117
121
|
return nested.flat();
|
|
118
122
|
}
|
|
123
|
+
function childAt(root, path) {
|
|
124
|
+
return { root, path };
|
|
125
|
+
}
|
|
119
126
|
/**
|
|
120
127
|
* A mirror branch, where configured, is someone else's history passing through
|
|
121
128
|
* this clone. Counting it reports their contributors, not this clone's
|
package/dist/commands/start.js
CHANGED
|
@@ -2,37 +2,55 @@
|
|
|
2
2
|
// arguments were typed, so `repown guard check` never imports it.
|
|
3
3
|
//
|
|
4
4
|
// Setup starts when stdin, stderr and stdout are all terminals, in any clone,
|
|
5
|
-
// pinned or not.
|
|
6
|
-
//
|
|
5
|
+
// pinned or not. It is a runner, so setup loads only then, and the lead line
|
|
6
|
+
// is drawn inside setup's frame rather than before it. Those same terminals
|
|
7
|
+
// outside a clone, including a bare repository, open the start screen: a
|
|
8
|
+
// runner too. With stdout redirected outside a clone, the top help.
|
|
9
|
+
// Everything else is status.
|
|
7
10
|
import { Git } from "../core/git.js";
|
|
8
11
|
import { inspectRepo } from "../core/inspect.js";
|
|
9
12
|
import { identityProblems } from "./status.js";
|
|
10
|
-
import * as out from "../ui/format.js";
|
|
11
13
|
import { interactive } from "../ui/prompt.js";
|
|
12
|
-
const SETUP_NOTE = 'This clone isn\'t set up yet, so repown is starting setup (repown status shows its settings).';
|
|
13
|
-
const PINNED_NOTE = 'Starting setup to check this clone (repown status shows its settings without asking anything).';
|
|
14
|
-
/** Setup, status, or the top help. No output
|
|
14
|
+
export const SETUP_NOTE = 'This clone isn\'t set up yet, so repown is starting setup (repown status shows its settings).';
|
|
15
|
+
export const PINNED_NOTE = 'Starting setup to check this clone (repown status shows its settings without asking anything).';
|
|
16
|
+
/** Setup, status, the start screen, or the top help. No output. */
|
|
15
17
|
export async function chooseStart(deps) {
|
|
16
18
|
return (await pickStart(deps)).choice;
|
|
17
19
|
}
|
|
18
|
-
/** Real deps for this process
|
|
20
|
+
/** Real deps for this process. Setup and the start screen are runners: nothing is printed until they are called. */
|
|
19
21
|
export async function startDefault(deps = realDeps()) {
|
|
20
22
|
const pick = await pickStart(deps);
|
|
21
23
|
if (pick.choice === 'setup')
|
|
22
|
-
|
|
24
|
+
return () => startSetup(pick.pinned);
|
|
25
|
+
if (pick.choice === 'home')
|
|
26
|
+
return startHome;
|
|
23
27
|
return pick.choice;
|
|
24
28
|
}
|
|
29
|
+
function startHome() {
|
|
30
|
+
return import("../wizard/home-run.js").then((mod) => mod.runHome());
|
|
31
|
+
}
|
|
32
|
+
function startSetup(pinned) {
|
|
33
|
+
const lead = pinned ? PINNED_NOTE : SETUP_NOTE;
|
|
34
|
+
return import("../wizard/setup-run.js").then((mod) => mod.runSetup(bareArgs(), { interactive: true, lead }));
|
|
35
|
+
}
|
|
36
|
+
function bareArgs() {
|
|
37
|
+
return { positional: [], flags: new Map() };
|
|
38
|
+
}
|
|
25
39
|
async function pickStart(deps) {
|
|
26
40
|
if (!deps.interactive)
|
|
27
41
|
return { choice: 'status', pinned: false };
|
|
28
42
|
if (await deps.git.isBare())
|
|
29
|
-
return { choice:
|
|
43
|
+
return { choice: outsideClone(deps.stdoutIsTerminal), pinned: false };
|
|
30
44
|
const repo = await inspectRepo(deps.git);
|
|
31
45
|
if (!repo.isRepo)
|
|
32
|
-
return { choice:
|
|
46
|
+
return { choice: outsideClone(deps.stdoutIsTerminal), pinned: false };
|
|
33
47
|
const pinned = identityProblems(repo).length === 0;
|
|
34
48
|
return { choice: deps.stdoutIsTerminal ? 'setup' : 'status', pinned };
|
|
35
49
|
}
|
|
50
|
+
/** A terminal outside a clone opens the start screen. Redirected stdout still prints the top help. */
|
|
51
|
+
function outsideClone(stdoutIsTerminal) {
|
|
52
|
+
return stdoutIsTerminal ? 'home' : 'help';
|
|
53
|
+
}
|
|
36
54
|
function realDeps() {
|
|
37
55
|
return { interactive: interactive(), stdoutIsTerminal: process.stdout.isTTY === true, git: new Git(process.cwd()) };
|
|
38
56
|
}
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The command table. cli.ts starts the program; the start screen's Show help
|
|
2
|
+
// loads this same table. Importing this file does not run repown.
|
|
3
|
+
export const COMMANDS = {
|
|
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
|
+
guard: async () => (await import("./commands/guard.js")).default,
|
|
10
|
+
accounts: async () => (await import("./commands/accounts.js")).default,
|
|
11
|
+
scan: async () => (await import("./commands/scan.js")).default,
|
|
12
|
+
setup: async () => (await import("./commands/setup.js")).default,
|
|
13
|
+
};
|
package/dist/ui/dispatch.js
CHANGED
|
@@ -11,10 +11,14 @@ import { renderHelpFor } from "./help.js";
|
|
|
11
11
|
import { suggest } from "./suggest.js";
|
|
12
12
|
import { ok, err } from "../core/result.js";
|
|
13
13
|
import * as out from "./format.js";
|
|
14
|
+
/** Every command the program declares, in declaration order. Help uses this, and so can a runner. */
|
|
15
|
+
export async function loadEntries(commands) {
|
|
16
|
+
const names = Object.keys(commands);
|
|
17
|
+
const loaded = await Promise.all(names.map((name) => commands[name]()));
|
|
18
|
+
return new Map(names.map((name, index) => [name, loaded[index]]));
|
|
19
|
+
}
|
|
14
20
|
async function loadAll(program) {
|
|
15
|
-
|
|
16
|
-
const entries = await Promise.all(names.map((name) => program.commands[name]()));
|
|
17
|
-
return new Map(names.map((name, index) => [name, entries[index]]));
|
|
21
|
+
return loadEntries(program.commands);
|
|
18
22
|
}
|
|
19
23
|
function reportUsageError(tag, message) {
|
|
20
24
|
const [first, ...rest] = message.split('\n');
|
|
@@ -122,6 +126,8 @@ export async function runProgram(program, argv) {
|
|
|
122
126
|
if (argv[0] === 'help')
|
|
123
127
|
return runHelp(program, argv.slice(1));
|
|
124
128
|
const words = await bareArgv(program, argv);
|
|
129
|
+
if (typeof words === 'function')
|
|
130
|
+
return words();
|
|
125
131
|
if (words === 'help')
|
|
126
132
|
return runHelp(program, []);
|
|
127
133
|
if (words.length === 0 && program.defaultCommand === undefined)
|
|
@@ -133,11 +139,13 @@ export async function runProgram(program, argv) {
|
|
|
133
139
|
}
|
|
134
140
|
return dispatch(program, top.value);
|
|
135
141
|
}
|
|
136
|
-
/** Empty argv with a chooser becomes that command,
|
|
142
|
+
/** Empty argv with a chooser becomes that command, `'help'` for the top help, or a runner. */
|
|
137
143
|
async function bareArgv(program, argv) {
|
|
138
144
|
if (argv.length > 0 || program.chooseDefault === undefined)
|
|
139
145
|
return argv;
|
|
140
146
|
const chosen = await program.chooseDefault();
|
|
147
|
+
if (typeof chosen === 'function')
|
|
148
|
+
return chosen;
|
|
141
149
|
return chosen === 'help' ? 'help' : [chosen];
|
|
142
150
|
}
|
|
143
151
|
/** The whole life of the process: run, set the exit code, and report a crash as a failure. */
|
package/dist/ui/help.js
CHANGED
|
@@ -20,9 +20,10 @@ function topHeader(entries) {
|
|
|
20
20
|
const lines = ['', ' repown <command> [options]', ''];
|
|
21
21
|
for (const [name, entry] of entries)
|
|
22
22
|
lines.push(' ' + name.padEnd(10) + entry.summary);
|
|
23
|
-
lines.push('', ' Bare `repown`,
|
|
24
|
-
lines.push('
|
|
25
|
-
lines.push('
|
|
23
|
+
lines.push('', ' Bare `repown`, with stdin, stdout and stderr all terminals: `repown setup` in a');
|
|
24
|
+
lines.push(' clone, and a start screen outside a clone or in a bare repository. With only');
|
|
25
|
+
lines.push(' stdout redirected: status in a clone, and this help outside one (exit 0). With');
|
|
26
|
+
lines.push(' no terminal on stdin or stderr, it is status (exit 1 outside a clone).');
|
|
26
27
|
lines.push(' Run `repown help <command>` for its options.', '');
|
|
27
28
|
return lines;
|
|
28
29
|
}
|
package/dist/wizard/clack.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The wizard drawn with @clack/prompts: arrow-key choices with a hint each, defaults,
|
|
2
2
|
// a line while state is read, the review in a box. The ONLY file that imports the
|
|
3
|
-
// library, and it is loaded with a dynamic import()
|
|
3
|
+
// library, and it is loaded with a dynamic import() from choosePrompter (ADR-016),
|
|
4
4
|
// so no other command -- and never the pre-push hook -- depends on it.
|
|
5
5
|
//
|
|
6
6
|
// Everything is drawn on the stream it's given (stderr), so stdout keeps carrying only
|
|
@@ -16,20 +16,12 @@ 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) =>
|
|
20
|
-
if (asked.detail)
|
|
21
|
-
p.log.info(wrap(asked.detail, widthOf(io, GUTTER)).join('\n'), io);
|
|
22
|
-
return askStep(step, asked, io);
|
|
23
|
-
},
|
|
19
|
+
ask: (step, asked) => askDrawn(step, asked, io),
|
|
24
20
|
review: (review) => showReview(review, io),
|
|
25
|
-
pickStep:
|
|
26
|
-
|
|
27
|
-
options: [...steps.map((step) => ({ value: step.id, label: step.message })), { value: GO_BACK, label: '← ' + BACK_TO_REVIEW }] });
|
|
28
|
-
if (p.isCancel(id))
|
|
29
|
-
return CANCEL;
|
|
30
|
-
return id === GO_BACK ? BACK : id;
|
|
31
|
-
},
|
|
21
|
+
pickStep: (steps) => pickClack(steps, io),
|
|
22
|
+
choose: (message, options) => chooseClack(message, options, io),
|
|
32
23
|
note: (message) => p.log.warn(wrap(message, widthOf(io, GUTTER)).join('\n'), io),
|
|
24
|
+
show: (lines) => logLines(io, lines),
|
|
33
25
|
confirmStep: (confirm) => showStep(confirm, io),
|
|
34
26
|
close: () => { },
|
|
35
27
|
intro: (title) => p.intro(title, io),
|
|
@@ -40,6 +32,27 @@ export function clackPrompter(streams) {
|
|
|
40
32
|
busy: (message) => p.log.step(message, io),
|
|
41
33
|
};
|
|
42
34
|
}
|
|
35
|
+
function askDrawn(step, asked, io) {
|
|
36
|
+
if (asked.detail)
|
|
37
|
+
p.log.info(wrap(asked.detail, widthOf(io, GUTTER)).join('\n'), io);
|
|
38
|
+
return askStep(step, asked, io);
|
|
39
|
+
}
|
|
40
|
+
async function pickClack(steps, io) {
|
|
41
|
+
const id = await p.select({ ...io, message: PICK_QUESTION, options: pickOptions(steps) });
|
|
42
|
+
if (p.isCancel(id))
|
|
43
|
+
return CANCEL;
|
|
44
|
+
return id === GO_BACK ? BACK : id;
|
|
45
|
+
}
|
|
46
|
+
function pickOptions(steps) {
|
|
47
|
+
return [...steps.map((step) => ({ value: step.id, label: step.message })), { value: GO_BACK, label: '← ' + BACK_TO_REVIEW }];
|
|
48
|
+
}
|
|
49
|
+
async function chooseClack(message, options, io) {
|
|
50
|
+
const value = await p.select({ ...io, message, options: options.map(choiceOption) });
|
|
51
|
+
return p.isCancel(value) ? CANCEL : value;
|
|
52
|
+
}
|
|
53
|
+
function choiceOption(option) {
|
|
54
|
+
return option.hint === undefined ? { value: option.value, label: option.label } : option;
|
|
55
|
+
}
|
|
43
56
|
/**
|
|
44
57
|
* Columns to leave free. clack wraps a list question 13 columns short of the window and
|
|
45
58
|
* a box's text 6 short, but never a text question's hint or a log line; wrapping every
|
|
@@ -101,10 +114,12 @@ function messageOf(step, io, extra) {
|
|
|
101
114
|
return [step.message, ...(hint ? wrap(hint, widthOf(io, GUTTER)) : [])].join('\n' + gutter);
|
|
102
115
|
}
|
|
103
116
|
async function showStep(confirm, io) {
|
|
104
|
-
|
|
105
|
-
p.log.message(lines.join('\n'), io);
|
|
117
|
+
logLines(io, stepConfirmLines(confirm));
|
|
106
118
|
return chosen(confirm, io);
|
|
107
119
|
}
|
|
120
|
+
function logLines(io, lines) {
|
|
121
|
+
p.log.message(lines.flatMap((text) => wrap(text, widthOf(io, GUTTER))).join('\n'), io);
|
|
122
|
+
}
|
|
108
123
|
async function chosen(confirm, io) {
|
|
109
124
|
const choice = await p.select({ ...io, message: RUN_THIS_STEP, options: stepOptions(), initialValue: confirm.initial });
|
|
110
125
|
return p.isCancel(choice) ? CANCEL : choice;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// What the start screen reads before it asks: the registry, whether gh is git's
|
|
2
|
+
// credential helper, and the clones below this folder. Read-only. A directory
|
|
3
|
+
// it cannot list is skipped; `repown scan` is the command that reports those.
|
|
4
|
+
import { readdir } from 'node:fs/promises';
|
|
5
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
6
|
+
import { Git } from "../core/git.js";
|
|
7
|
+
import { inspectRepo } from "../core/inspect.js";
|
|
8
|
+
import { planRepair } from "../core/credential/repair.js";
|
|
9
|
+
import { loadRegistry } from "../core/registry.js";
|
|
10
|
+
import { identityProblems } from "../commands/status.js";
|
|
11
|
+
import { CONCURRENCY, discover, mapLimited } from "../commands/scan.js";
|
|
12
|
+
/** How many levels below this folder the start screen looks. `repown scan` looks further. */
|
|
13
|
+
export const HOME_DEPTH = 2;
|
|
14
|
+
export async function readHome(cwd, deps = {}) {
|
|
15
|
+
const [registry, ghIsHelper, clones] = await Promise.all([
|
|
16
|
+
registryOf(deps), helperOf(cwd, deps), clonesOf(cwd, deps),
|
|
17
|
+
]);
|
|
18
|
+
return { cwd: resolve(cwd), registry, ghIsHelper, clones };
|
|
19
|
+
}
|
|
20
|
+
function registryOf(deps) {
|
|
21
|
+
return deps.registry ? deps.registry() : loadRegistry();
|
|
22
|
+
}
|
|
23
|
+
/** The same question `repown fix` previews: gh's helper entries are there to remove. */
|
|
24
|
+
function helperOf(cwd, deps) {
|
|
25
|
+
return deps.ghIsHelper ? deps.ghIsHelper(cwd) : ghHelper(cwd);
|
|
26
|
+
}
|
|
27
|
+
async function ghHelper(cwd) {
|
|
28
|
+
return (await planRepair(new Git(cwd))).length > 0;
|
|
29
|
+
}
|
|
30
|
+
async function clonesOf(cwd, deps) {
|
|
31
|
+
const found = await findClones(cwd, deps);
|
|
32
|
+
const described = await mapLimited(found, CONCURRENCY, (dir) => describeClone(dir, deps));
|
|
33
|
+
return described.filter(isClone);
|
|
34
|
+
}
|
|
35
|
+
async function findClones(cwd, deps) {
|
|
36
|
+
if (deps.findClones)
|
|
37
|
+
return deps.findClones(cwd);
|
|
38
|
+
if (await new Git(cwd).isBare())
|
|
39
|
+
return [];
|
|
40
|
+
return clonesWithin(cwd, HOME_DEPTH);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Repositories at most `depth` levels down, counting a repository at `dir`.
|
|
44
|
+
* Git accepting a directory stops the walk. Git refusing one is not a clone;
|
|
45
|
+
* the levels still left are searched inside it. This folder is that rule at depth 0.
|
|
46
|
+
*/
|
|
47
|
+
async function clonesWithin(dir, depth) {
|
|
48
|
+
if (depth < 0)
|
|
49
|
+
return [];
|
|
50
|
+
const found = await search(dir, depth);
|
|
51
|
+
const parts = await mapLimited(found, CONCURRENCY, (path) => keepOrEnter(dir, path, depth));
|
|
52
|
+
return parts.flat();
|
|
53
|
+
}
|
|
54
|
+
async function keepOrEnter(searched, path, budget) {
|
|
55
|
+
if (await new Git(path).isRepo())
|
|
56
|
+
return [path];
|
|
57
|
+
return enterRefused(path, budget - levelsBelow(searched, path));
|
|
58
|
+
}
|
|
59
|
+
/** One of `remaining` is spent stepping into `dir`; what is left is searched below it. */
|
|
60
|
+
async function enterRefused(dir, remaining) {
|
|
61
|
+
if (remaining <= 0)
|
|
62
|
+
return [];
|
|
63
|
+
const names = await childNames(dir);
|
|
64
|
+
const nested = await mapLimited(names, CONCURRENCY, (name) => clonesWithin(join(dir, name), remaining - 1));
|
|
65
|
+
return nested.flat();
|
|
66
|
+
}
|
|
67
|
+
function levelsBelow(root, path) {
|
|
68
|
+
const rel = relative(resolve(root), resolve(path));
|
|
69
|
+
return rel === '' ? 0 : rel.split(sep).length;
|
|
70
|
+
}
|
|
71
|
+
async function search(dir, depth) {
|
|
72
|
+
const unreadable = [];
|
|
73
|
+
const found = await discover({ root: dir, path: dir }, depth, unreadable, skipHomeEntry);
|
|
74
|
+
return found.map((entry) => entry.path);
|
|
75
|
+
}
|
|
76
|
+
/** Child directories the start screen would enter. An unlistable folder is skipped. */
|
|
77
|
+
async function childNames(cwd) {
|
|
78
|
+
try {
|
|
79
|
+
const entries = await readdir(cwd, { withFileTypes: true });
|
|
80
|
+
return entries.filter((entry) => entry.isDirectory() && !skipHomeEntry(entry.name)).map((entry) => entry.name);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function describeClone(dir, deps) {
|
|
87
|
+
const inspect = deps.inspect ?? inspectRepo;
|
|
88
|
+
const repo = await inspect(new Git(dir));
|
|
89
|
+
if (!repo.isRepo)
|
|
90
|
+
return null;
|
|
91
|
+
return { path: resolve(dir), setUp: identityProblems(repo).length === 0 };
|
|
92
|
+
}
|
|
93
|
+
function isClone(clone) {
|
|
94
|
+
return clone !== null;
|
|
95
|
+
}
|
|
96
|
+
/** Dot-directories, node_modules, and on Windows AppData. Only the start screen passes this. */
|
|
97
|
+
function skipHomeEntry(name) {
|
|
98
|
+
if (name.startsWith('.') || name === 'node_modules')
|
|
99
|
+
return true;
|
|
100
|
+
return process.platform === 'win32' && name.toLowerCase() === 'appdata';
|
|
101
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Pure: the summary, the menu and the clone list, and the command an action
|
|
2
|
+
// stands for. Drawing and running live in home-run.ts.
|
|
3
|
+
import { relative } from 'node:path';
|
|
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, NONE_RECORDED, NOT_SET_UP, QUIT, RECORD_ACCOUNT, SET_UP, SETUP_CLONE, SHOW_HELP, STOP_GH, clonesNone, clonesSome, couldNotRead, moreClones, recordedLine, setupHint, unreadableLine, } from "./home-text.js";
|
|
7
|
+
import { printable } from "./setup-flow.js";
|
|
8
|
+
/** Shown choices. `back` returns to the menu; the others run a command or leave. */
|
|
9
|
+
export const MENU = {
|
|
10
|
+
setup: 'setup', fix: 'fix', account: 'account', doctor: 'doctor', help: 'help', quit: 'quit',
|
|
11
|
+
};
|
|
12
|
+
export const BACK = 'back';
|
|
13
|
+
const LIST_CAP = 20;
|
|
14
|
+
export function summaryLines(home) {
|
|
15
|
+
const lines = [row('Accounts', accountsText(home.registry)), row('Clones', clonesText(home.clones))];
|
|
16
|
+
if (home.ghIsHelper)
|
|
17
|
+
lines.splice(1, 0, row('Helper', HELPER_LINE));
|
|
18
|
+
return lines;
|
|
19
|
+
}
|
|
20
|
+
export function homeNote(home) {
|
|
21
|
+
return home.clones.length === 0 ? CD_NOTE : null;
|
|
22
|
+
}
|
|
23
|
+
export function menuItems(home) {
|
|
24
|
+
return [...setupItem(home), ...fixItem(home), ...STANDING];
|
|
25
|
+
}
|
|
26
|
+
export function listedClones(home) {
|
|
27
|
+
const ordered = orderClones(home);
|
|
28
|
+
const shown = ordered.slice(0, LIST_CAP);
|
|
29
|
+
const rest = ordered.length - shown.length;
|
|
30
|
+
return { clones: shown.map((clone) => cloneChoice(home.cwd, clone)), more: rest > 0 ? moreClones(rest) : null };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The command the action stands for. `--cwd=<path>` is how setup's own plans spell
|
|
34
|
+
* it. `accounts add` puts `--` before the login, as that plan does, so a login
|
|
35
|
+
* that starts with a dash stays the account.
|
|
36
|
+
*/
|
|
37
|
+
export function commandFor(action) {
|
|
38
|
+
if (action.kind === 'setup')
|
|
39
|
+
return ['setup', '--cwd=' + action.path];
|
|
40
|
+
if (action.kind === 'fix')
|
|
41
|
+
return ['fix'];
|
|
42
|
+
if (action.kind === 'account')
|
|
43
|
+
return ['accounts', 'add', '--', action.login];
|
|
44
|
+
return ['doctor'];
|
|
45
|
+
}
|
|
46
|
+
function accountsText(registry) {
|
|
47
|
+
if (!registry.ok)
|
|
48
|
+
return couldNotRead(registryPath());
|
|
49
|
+
return accountsSummary(registry.value);
|
|
50
|
+
}
|
|
51
|
+
function accountsSummary(registry) {
|
|
52
|
+
const names = Object.keys(registry.accounts).sort();
|
|
53
|
+
const unread = registry.unreadable.length;
|
|
54
|
+
if (unread > 0)
|
|
55
|
+
return unreadableLine(names.length, unread, registryPath());
|
|
56
|
+
return names.length === 0 ? NONE_RECORDED : recordedLine(names.map(printable));
|
|
57
|
+
}
|
|
58
|
+
function clonesText(clones) {
|
|
59
|
+
if (clones.length === 0)
|
|
60
|
+
return clonesNone(HOME_DEPTH);
|
|
61
|
+
const pending = clones.filter((clone) => !clone.setUp).length;
|
|
62
|
+
return clonesSome(clones.length, pending, clones.length - pending);
|
|
63
|
+
}
|
|
64
|
+
function setupItem(home) {
|
|
65
|
+
if (home.clones.length === 0)
|
|
66
|
+
return [];
|
|
67
|
+
const pending = home.clones.filter((clone) => !clone.setUp).length;
|
|
68
|
+
return [{ value: MENU.setup, label: SETUP_CLONE, hint: setupHint(pending, home.clones.length) }];
|
|
69
|
+
}
|
|
70
|
+
function fixItem(home) {
|
|
71
|
+
if (!home.ghIsHelper)
|
|
72
|
+
return [];
|
|
73
|
+
return [{ value: MENU.fix, label: STOP_GH, hint: HINT_FIX }];
|
|
74
|
+
}
|
|
75
|
+
const STANDING = [
|
|
76
|
+
{ value: MENU.account, label: RECORD_ACCOUNT, hint: HINT_ACCOUNT },
|
|
77
|
+
{ value: MENU.doctor, label: CHECK_MACHINE, hint: HINT_DOCTOR },
|
|
78
|
+
{ value: MENU.help, label: SHOW_HELP },
|
|
79
|
+
{ value: MENU.quit, label: QUIT },
|
|
80
|
+
];
|
|
81
|
+
function orderClones(home) {
|
|
82
|
+
const rank = (clone) => (clone.setUp ? '1' : '0') + relative(home.cwd, clone.path);
|
|
83
|
+
return [...home.clones].sort((a, b) => rank(a).localeCompare(rank(b)));
|
|
84
|
+
}
|
|
85
|
+
function cloneChoice(cwd, clone) {
|
|
86
|
+
return { value: clone.path, label: printable(relative(cwd, clone.path)), hint: clone.setUp ? SET_UP : NOT_SET_UP };
|
|
87
|
+
}
|
|
88
|
+
function row(label, value) {
|
|
89
|
+
return label.padEnd(10) + ' ' + value;
|
|
90
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// The start screen: a summary of this folder, then one menu. Each action prints
|
|
2
|
+
// the command it stands for and runs that command's own run(). Loaded only
|
|
3
|
+
// through the runner start.ts returns, so a typed command never imports it.
|
|
4
|
+
//
|
|
5
|
+
// Quit exits 0. Esc and Ctrl-C exit 130, the same cancel setup uses. Neither writes.
|
|
6
|
+
import fixCommand from "../commands/fix.js";
|
|
7
|
+
import doctorCommand from "../commands/doctor.js";
|
|
8
|
+
import accountsGroup from "../commands/accounts.js";
|
|
9
|
+
import { COMMANDS } from "../program.js";
|
|
10
|
+
import { parseArgs } from "../ui/args.js";
|
|
11
|
+
import { specFor } from "../ui/command.js";
|
|
12
|
+
import { loadEntries } from "../ui/dispatch.js";
|
|
13
|
+
import * as out from "../ui/format.js";
|
|
14
|
+
import { renderTopHelp } from "../ui/help.js";
|
|
15
|
+
import { BACK, CANCEL } from "./engine.js";
|
|
16
|
+
import { readHome } from "./home-context.js";
|
|
17
|
+
import { BACK as HOME_BACK, MENU, commandFor, homeNote, listedClones, menuItems, summaryLines } from "./home-flow.js";
|
|
18
|
+
import { BACK_LABEL, BUSY, CANCELLED, LOGIN_HINT, LOGIN_MESSAGE, QUIT, WHAT_NEXT, WHICH_CLONE, homeTitle } from "./home-text.js";
|
|
19
|
+
import { formatCommand, loginProblem, printable } from "./setup-flow.js";
|
|
20
|
+
import { choosePrompter, runSetup } from "./setup-run.js";
|
|
21
|
+
const CANCELLED_CODE = 130;
|
|
22
|
+
const LOGIN_STEP = {
|
|
23
|
+
id: 'login', kind: 'text', message: LOGIN_MESSAGE, hint: LOGIN_HINT, flag: '<account>',
|
|
24
|
+
validate: (value) => loginProblem(String(value)),
|
|
25
|
+
};
|
|
26
|
+
const LOGIN_ASKED = { initial: undefined, choices: [], detail: undefined, canGoBack: true };
|
|
27
|
+
export async function runHome(deps = {}) {
|
|
28
|
+
const prompter = deps.prompter ?? await choosePrompter();
|
|
29
|
+
try {
|
|
30
|
+
return await openHome(prompter, deps);
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
prompter.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function openHome(prompter, deps) {
|
|
37
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
38
|
+
prompter.intro?.(homeTitle(printable(cwd)));
|
|
39
|
+
prompter.busy?.(BUSY);
|
|
40
|
+
const home = await (deps.read ?? readHome)(cwd);
|
|
41
|
+
showLines(prompter, summaryLines(home));
|
|
42
|
+
const note = homeNote(home);
|
|
43
|
+
if (note)
|
|
44
|
+
prompter.note(note);
|
|
45
|
+
return chooseNext(prompter, home);
|
|
46
|
+
}
|
|
47
|
+
async function chooseNext(prompter, home) {
|
|
48
|
+
for (;;) {
|
|
49
|
+
const picked = await prompter.choose(WHAT_NEXT, menuItems(home));
|
|
50
|
+
if (picked === CANCEL)
|
|
51
|
+
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
52
|
+
const code = await dispatchChoice(picked, prompter, home);
|
|
53
|
+
if (code !== null)
|
|
54
|
+
return code;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function dispatchChoice(picked, prompter, home) {
|
|
58
|
+
if (picked === MENU.quit)
|
|
59
|
+
return finish(prompter, QUIT, 0);
|
|
60
|
+
if (picked === MENU.help)
|
|
61
|
+
return showTopHelp(prompter);
|
|
62
|
+
if (picked === MENU.setup)
|
|
63
|
+
return pickClone(prompter, home);
|
|
64
|
+
if (picked === MENU.fix)
|
|
65
|
+
return runOwn(prompter, fixCommand, [], commandFor({ kind: 'fix' }));
|
|
66
|
+
if (picked === MENU.doctor)
|
|
67
|
+
return runOwn(prompter, doctorCommand, [], commandFor({ kind: 'doctor' }));
|
|
68
|
+
if (picked === MENU.account)
|
|
69
|
+
return recordAccount(prompter);
|
|
70
|
+
return finish(prompter, QUIT, 0);
|
|
71
|
+
}
|
|
72
|
+
async function pickClone(prompter, home) {
|
|
73
|
+
const list = listedClones(home);
|
|
74
|
+
if (list.more)
|
|
75
|
+
showLines(prompter, [list.more]);
|
|
76
|
+
const options = [...list.clones, { value: HOME_BACK, label: BACK_LABEL }];
|
|
77
|
+
const picked = await prompter.choose(WHICH_CLONE, options);
|
|
78
|
+
if (picked === CANCEL)
|
|
79
|
+
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
80
|
+
if (picked === HOME_BACK)
|
|
81
|
+
return null;
|
|
82
|
+
return runInClone(prompter, picked);
|
|
83
|
+
}
|
|
84
|
+
async function runInClone(prompter, cwd) {
|
|
85
|
+
const argv = commandFor({ kind: 'setup', path: cwd });
|
|
86
|
+
handOver(prompter, argv);
|
|
87
|
+
return runSetup(setupArgs(cwd), { interactive: true, prompter });
|
|
88
|
+
}
|
|
89
|
+
async function recordAccount(prompter) {
|
|
90
|
+
const login = await askLogin(prompter);
|
|
91
|
+
if (login === CANCEL)
|
|
92
|
+
return finish(prompter, CANCELLED, CANCELLED_CODE);
|
|
93
|
+
if (login === BACK)
|
|
94
|
+
return null;
|
|
95
|
+
const argv = commandFor({ kind: 'account', login });
|
|
96
|
+
return runOwn(prompter, accountsGroup.actions['add'], ['--', login], argv);
|
|
97
|
+
}
|
|
98
|
+
async function askLogin(prompter) {
|
|
99
|
+
for (;;) {
|
|
100
|
+
const reply = await prompter.ask(LOGIN_STEP, LOGIN_ASKED);
|
|
101
|
+
if (reply === CANCEL || reply === BACK)
|
|
102
|
+
return reply;
|
|
103
|
+
const problem = loginProblem(String(reply));
|
|
104
|
+
if (!problem)
|
|
105
|
+
return String(reply).trim();
|
|
106
|
+
prompter.note(problem);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function runOwn(prompter, command, tokens, argv) {
|
|
110
|
+
handOver(prompter, argv);
|
|
111
|
+
prompter.suspend?.();
|
|
112
|
+
const parsed = parseArgs(tokens, specFor(command));
|
|
113
|
+
if (!parsed.ok) {
|
|
114
|
+
out.fail('repown', parsed.error);
|
|
115
|
+
return 2;
|
|
116
|
+
}
|
|
117
|
+
return command.run(parsed.value);
|
|
118
|
+
}
|
|
119
|
+
function setupArgs(cwd) {
|
|
120
|
+
return { positional: [], flags: new Map([['cwd', cwd]]) };
|
|
121
|
+
}
|
|
122
|
+
function finish(prompter, message, code) {
|
|
123
|
+
prompter.outro?.(message, code === CANCELLED_CODE);
|
|
124
|
+
return code;
|
|
125
|
+
}
|
|
126
|
+
function showLines(prompter, lines) {
|
|
127
|
+
if (prompter.show) {
|
|
128
|
+
prompter.show(lines);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
for (const line of lines)
|
|
132
|
+
out.line(' ' + line);
|
|
133
|
+
}
|
|
134
|
+
/** Closes the start screen's frame on the command it hands over to. */
|
|
135
|
+
function handOver(prompter, argv) {
|
|
136
|
+
const line = '> ' + formatCommand(argv);
|
|
137
|
+
if (prompter.outro)
|
|
138
|
+
prompter.outro(line);
|
|
139
|
+
else
|
|
140
|
+
out.detail(line);
|
|
141
|
+
}
|
|
142
|
+
async function showTopHelp(prompter) {
|
|
143
|
+
handOver(prompter, ['--help']);
|
|
144
|
+
const entries = await loadEntries(COMMANDS);
|
|
145
|
+
for (const line of renderTopHelp(entries))
|
|
146
|
+
out.line(line);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The words on the start screen, in one place, so the summary and both prompters
|
|
2
|
+
// say the same thing. What is shown when comes from home-flow.ts.
|
|
3
|
+
import { displayPath } from "../ui/format.js";
|
|
4
|
+
export const WHAT_NEXT = 'What next?';
|
|
5
|
+
export const WHICH_CLONE = 'Which clone?';
|
|
6
|
+
export const SETUP_CLONE = 'Set up a clone found here';
|
|
7
|
+
export const STOP_GH = 'Stop gh serving credentials';
|
|
8
|
+
export const RECORD_ACCOUNT = 'Record an account';
|
|
9
|
+
export const CHECK_MACHINE = 'Check this machine';
|
|
10
|
+
export const SHOW_HELP = 'Show help';
|
|
11
|
+
export const QUIT = 'Quit';
|
|
12
|
+
export const BACK_LABEL = '← Back';
|
|
13
|
+
export const BUSY = 'Reading this folder';
|
|
14
|
+
export const CD_NOTE = 'cd into a clone (or git clone one), then run repown';
|
|
15
|
+
export const NONE_RECORDED = 'none recorded';
|
|
16
|
+
export const HELPER_LINE = 'gh serves git\'s credentials: run repown fix';
|
|
17
|
+
export const HINT_FIX = 'repown fix';
|
|
18
|
+
export const HINT_ACCOUNT = 'repown accounts add';
|
|
19
|
+
export const HINT_DOCTOR = 'repown doctor';
|
|
20
|
+
export const NOT_SET_UP = 'not set up';
|
|
21
|
+
export const SET_UP = 'set up';
|
|
22
|
+
export const LOGIN_MESSAGE = 'The account\'s user name (login)';
|
|
23
|
+
export const LOGIN_HINT = 'the name you sign in with, e.g. octocat; not your email address';
|
|
24
|
+
export const CANCELLED = 'Cancelled: nothing was changed.';
|
|
25
|
+
export function homeTitle(cwd) {
|
|
26
|
+
return 'repown · not a clone: ' + displayPath(cwd);
|
|
27
|
+
}
|
|
28
|
+
export function recordedLine(names) {
|
|
29
|
+
return names.length + ' recorded: ' + names.join(', ');
|
|
30
|
+
}
|
|
31
|
+
/** Entries the registry file has, but that could not be read as accounts. */
|
|
32
|
+
export function unreadableLine(recorded, unreadable, path) {
|
|
33
|
+
const tail = unreadable + ' unreadable in ' + path + ': run repown accounts list';
|
|
34
|
+
return recorded === 0 ? tail : recorded + ' recorded, ' + tail;
|
|
35
|
+
}
|
|
36
|
+
export function couldNotRead(path) {
|
|
37
|
+
return 'could not read ' + path;
|
|
38
|
+
}
|
|
39
|
+
export function clonesNone(depth) {
|
|
40
|
+
return 'none below this folder (' + depth + ' levels)';
|
|
41
|
+
}
|
|
42
|
+
export function clonesSome(total, pending, ready) {
|
|
43
|
+
return total + ' below this folder: ' + pending + ' not set up, ' + ready + ' set up';
|
|
44
|
+
}
|
|
45
|
+
export function setupHint(pending, total) {
|
|
46
|
+
return pending > 0 ? pending + ' not set up' : total + ' set up';
|
|
47
|
+
}
|
|
48
|
+
export function moreClones(count) {
|
|
49
|
+
return 'and ' + count + ' more: repown scan';
|
|
50
|
+
}
|
package/dist/wizard/plain.js
CHANGED
|
@@ -20,8 +20,9 @@ export function plainPrompter(streams) {
|
|
|
20
20
|
ask: (step, asked) => askStep(wide(), step, asked),
|
|
21
21
|
review: (review) => showReview(session.io(), review, width),
|
|
22
22
|
pickStep: (steps) => pickPlain(session.io(), steps),
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
choose: (message, options) => choosePlain(session.io(), message, options),
|
|
24
|
+
note: (message) => sayIndented(session.io(), wrap(message, width)),
|
|
25
|
+
show: (lines) => sayIndented(session.io(), lines.flatMap((text) => wrap(text, width))),
|
|
25
26
|
close: () => session.close(),
|
|
26
27
|
outro: (message) => session.io().say(message),
|
|
27
28
|
confirmStep: (confirm) => askStepConfirm(wide(), confirm),
|
|
@@ -50,6 +51,10 @@ function plainSession(streams) {
|
|
|
50
51
|
function openReadline(streams, terminal) {
|
|
51
52
|
return createInterface({ input: streams.input, output: streams.output, terminal });
|
|
52
53
|
}
|
|
54
|
+
function sayIndented(io, lines) {
|
|
55
|
+
for (const line of lines)
|
|
56
|
+
io.say(' ' + line);
|
|
57
|
+
}
|
|
53
58
|
/** On a terminal, readline shows the prompt, so it can redraw it while the line is edited. */
|
|
54
59
|
function ioFor(rl, output, terminal) {
|
|
55
60
|
const lines = queue(rl);
|
|
@@ -107,6 +112,12 @@ async function askStep(io, step, asked) {
|
|
|
107
112
|
return BACK;
|
|
108
113
|
return line || (typeof initial === 'string' ? initial : '');
|
|
109
114
|
}
|
|
115
|
+
async function choosePlain(io, message, options) {
|
|
116
|
+
io.say(message);
|
|
117
|
+
const labels = options.map((option) => option.label + (option.hint ? ' -- ' + option.hint : ''));
|
|
118
|
+
const index = await pickNumber(io, labels, 1);
|
|
119
|
+
return index === CANCEL ? CANCEL : options[index].value;
|
|
120
|
+
}
|
|
110
121
|
async function pickPlain(io, steps) {
|
|
111
122
|
io.say(PICK_QUESTION);
|
|
112
123
|
const index = await pickNumber(io, [...steps.map((step) => step.message), BACK_TO_REVIEW], 1);
|
|
@@ -329,11 +329,16 @@ function required(value) {
|
|
|
329
329
|
}
|
|
330
330
|
/** A login as hosts spell them: it also becomes part of a profile lookup's URL. */
|
|
331
331
|
const LOGIN = /^[\w.@-]+$/;
|
|
332
|
-
|
|
332
|
+
/** Empty, or not spelled as a login. The start screen asks for a login by this rule too. */
|
|
333
|
+
export function loginProblem(value) {
|
|
333
334
|
if (!value.trim())
|
|
334
335
|
return 'a value is required';
|
|
335
|
-
|
|
336
|
-
|
|
336
|
+
return LOGIN.test(value) ? null : 'use letters, digits and . _ @ - only';
|
|
337
|
+
}
|
|
338
|
+
function newAccountProblem(value, ctx) {
|
|
339
|
+
const problem = loginProblem(value);
|
|
340
|
+
if (problem)
|
|
341
|
+
return problem;
|
|
337
342
|
const clash = Object.keys(ctx.recorded).find((account) => lower(account) === lower(value));
|
|
338
343
|
return clash ? '"' + clash + '" is already recorded on this machine: use it by that name' : null;
|
|
339
344
|
}
|
package/dist/wizard/setup-run.js
CHANGED
|
@@ -35,24 +35,28 @@ export async function runSetup(args, deps) {
|
|
|
35
35
|
if (!deps.interactive && !unattended)
|
|
36
36
|
return needsTerminal(given.value, registry.value.accounts);
|
|
37
37
|
const git = gitFor(args);
|
|
38
|
-
if (!(await git.isRepo()))
|
|
39
|
-
|
|
40
|
-
out.detail('run it inside a clone: cd path/to/repo, then repown setup');
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
38
|
+
if (!(await git.isRepo()))
|
|
39
|
+
return notARepo(git);
|
|
43
40
|
const prompter = unattended ? null : deps.prompter ?? await choosePrompter();
|
|
44
41
|
try {
|
|
45
42
|
return await continueSetup({
|
|
46
43
|
args, git, given: given.value, prompter, accountKind: deps.accountKind, readAuth: deps.auth ?? inspectAuth,
|
|
47
44
|
...(deps.preview ? { preview: deps.preview } : {}),
|
|
45
|
+
...(deps.lead === undefined ? {} : { lead: deps.lead }),
|
|
48
46
|
});
|
|
49
47
|
}
|
|
50
48
|
finally {
|
|
51
49
|
prompter?.close();
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
|
|
52
|
+
function notARepo(git) {
|
|
53
|
+
out.fail('setup', 'Not a git repository: ' + git.cwd);
|
|
54
|
+
out.detail('run it inside a clone: cd path/to/repo, then repown setup');
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
async function continueSetup({ args, git, given, prompter, accountKind, readAuth, preview, lead }) {
|
|
55
58
|
prompter?.intro?.('repown setup');
|
|
59
|
+
drawLead(prompter, lead);
|
|
56
60
|
prompter?.busy?.('Reading this clone and this machine');
|
|
57
61
|
const ctx = await readContext(git, flagString(args, 'cwd'), contextOptions(prompter, accountKind, preview));
|
|
58
62
|
if (!ctx.ok) {
|
|
@@ -66,6 +70,15 @@ async function continueSetup({ args, git, given, prompter, accountKind, readAuth
|
|
|
66
70
|
return runUnattended(answers.value, ctx.value, git, readAuth);
|
|
67
71
|
return runGuided(answers.value, ctx.value, { git, prompter, readAuth });
|
|
68
72
|
}
|
|
73
|
+
/** The bare-repown sentence, inside the frame when the prompter can draw it. */
|
|
74
|
+
function drawLead(prompter, lead) {
|
|
75
|
+
if (lead === undefined)
|
|
76
|
+
return;
|
|
77
|
+
if (prompter?.show)
|
|
78
|
+
prompter.show([lead]);
|
|
79
|
+
else
|
|
80
|
+
out.note(lead);
|
|
81
|
+
}
|
|
69
82
|
function contextOptions(prompter, accountKind, preview) {
|
|
70
83
|
const classifyOwner = prompter !== null;
|
|
71
84
|
const auth = preview ? { auth: preview } : {};
|
|
@@ -211,8 +224,9 @@ function stoppedBefore(status, prompter) {
|
|
|
211
224
|
* @clack/prompts when colour is on for stderr and the terminal can draw it; the plain
|
|
212
225
|
* prompter otherwise, and whenever the optional dependency is absent or fails to load
|
|
213
226
|
* (an older Node skips installing it, ADR-016) -- said once, then carried on.
|
|
227
|
+
* Setup and the start screen both ask through this, so clack loads in only one place.
|
|
214
228
|
*/
|
|
215
|
-
async function choosePrompter() {
|
|
229
|
+
export async function choosePrompter() {
|
|
216
230
|
const streams = { input: process.stdin, output: process.stderr };
|
|
217
231
|
if (!useColour(process.stderr) || process.env['TERM'] === 'dumb')
|
|
218
232
|
return plainPrompter(streams);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "repown",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.3.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"bin": {
|
|
12
12
|
"repown": "dist/cli.js"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Use several git accounts on one machine: each repo owns its identity, so you move between repos with no switch command and never push the wrong one.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|