@joberthel/worktree 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +315 -2
- package/dist/cli-spec.js +138 -0
- package/dist/cli.js +264 -0
- package/dist/completion.js +178 -0
- package/dist/config/load.js +46 -0
- package/dist/config/schema.js +57 -0
- package/dist/docker/compose.js +253 -0
- package/dist/git/repository.js +196 -0
- package/dist/operations/attached.js +294 -0
- package/dist/operations/commands.js +158 -0
- package/dist/operations/confirmation.js +15 -0
- package/dist/operations/copy-paths.js +109 -0
- package/dist/operations/create.js +255 -0
- package/dist/operations/hooks.js +113 -0
- package/dist/operations/manage.js +446 -0
- package/dist/operations/manage.test/fixture.js +67 -0
- package/dist/operations/process.js +122 -0
- package/dist/operations/progress.js +28 -0
- package/dist/state/atomic-file.js +14 -0
- package/dist/state/store.js +162 -0
- package/dist/ui/confirmation-prompt.js +48 -0
- package/dist/ui/environment-info.js +85 -0
- package/dist/ui/environment-table.js +43 -0
- package/dist/ui/format-status.js +29 -0
- package/dist/ui/hook-log-panel.js +57 -0
- package/dist/ui/json-output.js +41 -0
- package/dist/ui/operation-view.js +33 -0
- package/dist/ui/progress-state.js +111 -0
- package/dist/ui/progress.js +16 -0
- package/dist/ui/show-operation.js +56 -0
- package/dist/ui/use-progress.js +34 -0
- package/package.json +72 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { isHookLabel } from './progress-state.js';
|
|
3
|
+
export async function showOperation(label, operation, interrupt) {
|
|
4
|
+
if (!process.stderr.isTTY || !process.stdin.isTTY || !process.stdout.isTTY) {
|
|
5
|
+
return operation((event) => {
|
|
6
|
+
if (event.status === 'log')
|
|
7
|
+
process.stderr.write(event.text);
|
|
8
|
+
else if (event.status === 'started')
|
|
9
|
+
process.stderr.write(`${event.label}\n`);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
// Ink takes ~200 ms to load, so only load it when a terminal UI is drawn.
|
|
13
|
+
const [{ render }, { createElement }, { OperationView }] = await Promise.all([
|
|
14
|
+
import('ink'),
|
|
15
|
+
import('react'),
|
|
16
|
+
import('./operation-view.js'),
|
|
17
|
+
]);
|
|
18
|
+
let instance;
|
|
19
|
+
let props;
|
|
20
|
+
// Hook output stays on screen after the operation; everything else is erased.
|
|
21
|
+
let showsHookOutput = false;
|
|
22
|
+
try {
|
|
23
|
+
return await new Promise((resolve, reject) => {
|
|
24
|
+
props = {
|
|
25
|
+
label,
|
|
26
|
+
interrupt,
|
|
27
|
+
start: (report, confirm) => {
|
|
28
|
+
const track = (event) => {
|
|
29
|
+
showsHookOutput ||= event.status === 'log' || isHookLabel(event.label);
|
|
30
|
+
report(event);
|
|
31
|
+
};
|
|
32
|
+
void operation(track, confirm).then(resolve, reject);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
instance = render(createElement(OperationView, props), {
|
|
36
|
+
stdout: process.stderr,
|
|
37
|
+
stdin: process.stdin,
|
|
38
|
+
stderr: process.stderr,
|
|
39
|
+
exitOnCtrlC: false,
|
|
40
|
+
patchConsole: false,
|
|
41
|
+
});
|
|
42
|
+
void instance.waitUntilExit().catch(reject);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
if (instance && props) {
|
|
47
|
+
// Draw a last frame without the spinner. Finished steps stay on screen.
|
|
48
|
+
// Without hook output that frame is empty, so erase it to leave no blank line.
|
|
49
|
+
instance.rerender(createElement(OperationView, { ...props, finished: true }));
|
|
50
|
+
await instance.waitUntilRenderFlush();
|
|
51
|
+
if (!showsHookOutput)
|
|
52
|
+
instance.clear();
|
|
53
|
+
instance.unmount();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { emptyHook, updateProgress } from './progress-state.js';
|
|
3
|
+
export function useProgress() {
|
|
4
|
+
const [progress, setProgress] = React.useState({ steps: [], hook: emptyHook });
|
|
5
|
+
const pendingLogsRef = React.useRef([]);
|
|
6
|
+
const logTimerRef = React.useRef(undefined);
|
|
7
|
+
const flushLogs = React.useCallback(() => {
|
|
8
|
+
if (logTimerRef.current !== undefined) {
|
|
9
|
+
clearTimeout(logTimerRef.current);
|
|
10
|
+
logTimerRef.current = undefined;
|
|
11
|
+
}
|
|
12
|
+
const events = pendingLogsRef.current;
|
|
13
|
+
pendingLogsRef.current = [];
|
|
14
|
+
if (events.length > 0) {
|
|
15
|
+
setProgress(previous => events.reduce(updateProgress, previous));
|
|
16
|
+
}
|
|
17
|
+
}, []);
|
|
18
|
+
React.useEffect(() => () => {
|
|
19
|
+
if (logTimerRef.current !== undefined)
|
|
20
|
+
clearTimeout(logTimerRef.current);
|
|
21
|
+
}, []);
|
|
22
|
+
const report = React.useCallback((event) => {
|
|
23
|
+
if (event.status === 'log') {
|
|
24
|
+
pendingLogsRef.current.push(event);
|
|
25
|
+
if (logTimerRef.current === undefined) {
|
|
26
|
+
logTimerRef.current = setTimeout(flushLogs, 80);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
flushLogs();
|
|
31
|
+
setProgress(previous => updateProgress(previous, event));
|
|
32
|
+
}, [flushLogs]);
|
|
33
|
+
return { progress, report };
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joberthel/worktree",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Isolated development environments from Git worktrees, each with its own Docker Compose project and cloned volumes.",
|
|
6
|
+
"author": "Johannes Berthel",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/joberthel/worktree#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/joberthel/worktree.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/joberthel/worktree/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"git",
|
|
18
|
+
"worktree",
|
|
19
|
+
"docker",
|
|
20
|
+
"docker-compose",
|
|
21
|
+
"cli",
|
|
22
|
+
"development-environment"
|
|
23
|
+
],
|
|
24
|
+
"bin": {
|
|
25
|
+
"wt": "./dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@inkjs/ui": "^2.0.0",
|
|
35
|
+
"ink": "^8.0.0",
|
|
36
|
+
"react": "^19.3.1",
|
|
37
|
+
"yaml": "^2.9.1",
|
|
38
|
+
"zod": "^4.6.7"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@antfu/eslint-config": "^10.0.0",
|
|
42
|
+
"@commitlint/cli": "^21.2.4",
|
|
43
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
44
|
+
"@commitlint/types": "^21.2.3",
|
|
45
|
+
"@eslint-react/eslint-plugin": "^5.30.5",
|
|
46
|
+
"@types/node": "^26.6.11",
|
|
47
|
+
"@types/react": "^19.3.3",
|
|
48
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
49
|
+
"eslint": "^10.14.0",
|
|
50
|
+
"eslint-plugin-react-refresh": "^0.5.8",
|
|
51
|
+
"husky": "^9.1.7",
|
|
52
|
+
"jiti": "^2.7.0",
|
|
53
|
+
"typescript": "^6.0.3",
|
|
54
|
+
"vitest": "^5.1.2"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"os": [
|
|
60
|
+
"darwin",
|
|
61
|
+
"linux"
|
|
62
|
+
],
|
|
63
|
+
"scripts": {
|
|
64
|
+
"clean": "rm -rf coverage dist",
|
|
65
|
+
"build": "pnpm clean && tsc",
|
|
66
|
+
"test": "pnpm test:unit",
|
|
67
|
+
"test:unit": "vitest run --exclude 'e2e/**/*.e2e.test.ts'",
|
|
68
|
+
"test:coverage": "pnpm test:unit --coverage",
|
|
69
|
+
"test:e2e": "pnpm build && vitest run e2e",
|
|
70
|
+
"lint": "eslint . --max-warnings 0",
|
|
71
|
+
"lint:fix": "eslint . --fix",
|
|
72
|
+
"commitlint": "commitlint",
|
|
73
|
+
"typecheck": "tsc -p tsconfig.eslint.json --noEmit"
|
|
74
|
+
}
|
|
6
75
|
}
|