@kaynooo/cli-wt 0.1.6 → 0.1.8
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/README.md +17 -10
- package/dist/cli-02xxc9xk.js +67 -0
- package/dist/cli-5khwxy5g.js +36 -0
- package/dist/cli-6k7xzgw2.js +519 -0
- package/dist/cli-96wy1q8e.js +97 -0
- package/dist/cli-9m1jyyrf.js +69 -0
- package/dist/cli-fa4fh6ex.js +37 -0
- package/dist/cli-fdwwsds1.js +153 -0
- package/dist/cli-jb9a8d46.js +674 -0
- package/dist/cli-k4471y24.js +779 -0
- package/dist/cli-kt6d30zz.js +106 -0
- package/dist/cli-q7e6gegw.js +105 -0
- package/dist/cli-qwe5ykfs.js +313 -0
- package/dist/cli-tp4q5w5x.js +251 -0
- package/dist/cli.js +228 -2809
- package/dist/commands-jqr92tk6.js +222 -0
- package/dist/init-0ws4c883.js +166 -0
- package/dist/list-83vq4jng.js +88 -0
- package/dist/print-d4aq2eqw.js +77 -0
- package/dist/prompt-y71tp3f5.js +436 -0
- package/dist/prune-7ex1qyd3.js +17 -0
- package/dist/run-jrmm9gg8.js +18 -0
- package/dist/shell-1smv2vf9.js +55 -0
- package/dist/stack-2zj6r6py.js +20 -0
- package/dist/tools-c4m5037s.js +13 -0
- package/package.json +4 -4
- package/src/cli.ts +250 -69
- package/src/commands.ts +51 -38
- package/src/compose.ts +37 -14
- package/src/config.ts +8 -1
- package/src/errors.ts +16 -6
- package/src/files.ts +14 -15
- package/src/git.ts +53 -7
- package/src/index.ts +2 -1
- package/src/init.ts +56 -10
- package/src/jobs.ts +54 -15
- package/src/list.ts +26 -13
- package/src/print.ts +76 -0
- package/src/project.ts +129 -28
- package/src/proxy.ts +5 -5
- package/src/prune.ts +149 -0
- package/src/queue.ts +27 -3
- package/src/run.ts +82 -23
- package/src/shell.ts +34 -7
- package/src/stack.ts +10 -12
- package/src/sync.ts +28 -3
- package/src/tools.ts +91 -0
package/README.md
CHANGED
|
@@ -12,24 +12,30 @@ bun install -g @kaynooo/cli-wt
|
|
|
12
12
|
|
|
13
13
|
| Command | What it does |
|
|
14
14
|
| --- | --- |
|
|
15
|
-
| `wt add <task> [branch]` | creates the worktree on `branch` (`wt/<task>`), copies and clones from main, routes its subdomains |
|
|
15
|
+
| `wt add <task> [branch] [--from <ref>] [--up]` | creates the worktree on `branch` (`wt/<task>`), a new one forked from main's current commit or `--from`, copies and clones from main, routes its subdomains; `--up` starts it too |
|
|
16
16
|
| `wt sync [task]` | provisions it again after a manifest change |
|
|
17
|
-
| `wt up [task]` / `wt down [task]` | starts or stops its stack |
|
|
18
|
-
| `wt rm <task>` | stops the stack, deletes the checkouts, volumes, certificates and override, keeps the branches; refuses uncommitted changes or commits on no branch unless `--force` |
|
|
19
|
-
| `wt
|
|
17
|
+
| `wt up [task]` / `wt down [task]` | starts or stops its stack, `--all` every worktree's in turn; `down` also stops a stack whose folder is gone |
|
|
18
|
+
| `wt rm <task>` | stops the stack, deletes the checkouts, volumes, certificates and override, keeps the branches; refuses uncommitted changes or commits on no branch unless `--force`; gitignored files (a copied `.env.local` edited since, uploads) go with the folder unchecked |
|
|
19
|
+
| `wt open [task]` | opens its main URL in the browser |
|
|
20
|
+
| `wt logs [task] [-f]` | prints the log of its last `--bg` job, or with `-f` follows its stack's compose logs |
|
|
21
|
+
| `wt prune [-a] [-y]` | lists what worktrees deleted by hand left behind (files, job records, volumes, git registrations) and removes it once confirmed |
|
|
22
|
+
| `wt ls` | main and the worktrees of the current project (`-a` every project), with their last job and changed files |
|
|
23
|
+
| `wt cd [task]` | goes to a worktree, or main, through the shell function of `wt shell` |
|
|
20
24
|
| `wt path [task]` | the directory of a worktree, or of main |
|
|
25
|
+
| `wt url [task]` / `wt tasks` | its URLs; the worktree names of the project, one per line |
|
|
26
|
+
| `wt doctor` | lists the programs wt runs (git, docker, compose, mkcert, devproxy, notify-send), where each is or how to get it; `wt add` refuses before changing anything when one it needs is missing |
|
|
21
27
|
| `wt init [dir]` | drafts a manifest from the compose project in `dir` into the manifests folder (`--print` to stdout) |
|
|
22
28
|
| `wt run <task> -- <cmd>` | runs a command in a throwaway container of the manifest's `run.service`, against a test database of the worktree's own |
|
|
23
29
|
| `wt heavy -- <cmd>` | runs a command once the heavy ones queued before it, from any session, are done |
|
|
24
|
-
| `wt shell fish` | the shell function giving `wt cd <task>`, and `wt rm` leaving the folder it removed |
|
|
30
|
+
| `wt shell fish\|bash\|zsh` | the shell function giving `wt cd <task>`, and `wt rm` leaving the folder it removed, with the completion |
|
|
25
31
|
|
|
26
32
|
A task defaults to the worktree the current directory is in, and `-p <name>` picks the project when the current directory is in none. `add`, `rm`, `up` and `down` take `--bg` to run detached, ending with a desktop notification. One action runs per stack at a time: a second one is refused, naming what holds it.
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
For `wt cd`, save the wrapper where the shell reads it at start, so no process runs then (again after upgrading wt): `wt shell fish > ~/.config/fish/conf.d/wt.fish`, or `wt shell bash > ~/.local/share/wt/wt.bash` sourced from `~/.bashrc` (zsh likewise, after `compinit`).
|
|
29
35
|
|
|
30
36
|
## Manifests
|
|
31
37
|
|
|
32
|
-
One file per project in `~/.config/wt/projects/<name>.ts`, `wt init` writing a first draft:
|
|
38
|
+
One file per project in `~/.config/wt/projects/<name>.ts`, `wt init` writing a first draft, and a `tsconfig.json` beside it pointing `@kaynooo/cli-wt` at the installed wt so an editor type-checks the manifests (delete it to have the next `wt init` write it again after moving wt):
|
|
33
39
|
|
|
34
40
|
```ts
|
|
35
41
|
import type { ProjectConfig } from '@kaynooo/cli-wt'
|
|
@@ -51,17 +57,18 @@ export default {
|
|
|
51
57
|
| Key | |
|
|
52
58
|
| --- | --- |
|
|
53
59
|
| `root` | the main checkout |
|
|
54
|
-
| `repos` | nested repos put on the task branch;
|
|
60
|
+
| `repos` | nested repos put on the task branch; none when the root itself is the repo |
|
|
55
61
|
| `copy` | gitignored files and folders copied from main, hosts rewritten in the `.env*` ones |
|
|
56
62
|
| `clone` | data each worktree gets its own copy of: a path under root or a named volume's key |
|
|
57
63
|
| `link` | paths shared with main through a symlink |
|
|
58
64
|
| `skip` | services left out of a worktree's stack |
|
|
59
65
|
| `routeHosts` | services that dial the stack's own hosts from inside a container, given the worktree's in `/etc/hosts` |
|
|
60
66
|
| `env` | values forced into copied env files, per file; `{task}` and `{port}` (the dev server's) filled in |
|
|
67
|
+
| `ports` | a worktree's dev server port by task, from 1024 to 65535, for one whose port, hashed from its name, is taken: `wt add` warns when something listens on it, `wt sync` when another worktree has it |
|
|
61
68
|
| `certs` | where the stack's nginx reads certificates, required by passthrough routes |
|
|
62
69
|
| `setup` | `sh -c` commands run in the worktree the first time its stack comes up |
|
|
63
70
|
| `run` | `wt run`'s `service`, `dir`, `provision` commands, optional `dns` and `env` |
|
|
64
|
-
| `routes` | `host` main answers on, `to` `client` (the dev server on the host) or `<service>:<port>`, `passthrough` to leave TLS to the stack |
|
|
71
|
+
| `routes` | none leaves the worktree unrouted; `host` main answers on, `to` `client` (the dev server on the host) or `<service>:<port>`, `passthrough` to leave TLS to the stack |
|
|
65
72
|
|
|
66
73
|
## Config
|
|
67
74
|
|
|
@@ -83,7 +90,7 @@ export default {
|
|
|
83
90
|
| `state` | `~/.cache/wt` | setup markers, clone progress, queues |
|
|
84
91
|
| `jobs` | `<state>/jobs` | job records and per-stack locks; a tool pointing at the same folder shares the locks |
|
|
85
92
|
| `proxyNetwork` | `proxy` | the network devproxy reaches the stacks on |
|
|
86
|
-
| `runner` | | `up`, `down` and `removed` argv replacing `docker compose up -d --build`, `docker compose down` and nothing; `{project}`, `{task}`, `{dir}` and `{id}` filled in |
|
|
93
|
+
| `runner` | | `up`, `down` and `removed` argv replacing `docker compose up -d --build`, `docker compose down` and nothing; `{project}`, `{task}`, `{dir}` and `{id}` filled in; a worktree whose folder is gone skips `down`, `{dir}` having gone with it, for `docker compose -p <id> down` |
|
|
87
94
|
|
|
88
95
|
Without a runner, `wt up` brings devproxy up first when it is installed (on PATH or as this package's dependency), then compose, then the manifest's `setup` once. A runner command that itself runs wt, or another tool sharing the `jobs` folder, works inside the job that started it instead of being refused by its lock.
|
|
89
96
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
table
|
|
4
|
+
} from "./cli-k4471y24.js";
|
|
5
|
+
import {
|
|
6
|
+
WtError
|
|
7
|
+
} from "./cli-6k7xzgw2.js";
|
|
8
|
+
import {
|
|
9
|
+
devproxyArgv
|
|
10
|
+
} from "./cli-fa4fh6ex.js";
|
|
11
|
+
|
|
12
|
+
// src/tools.ts
|
|
13
|
+
var {$ } = globalThis.Bun;
|
|
14
|
+
function findDevproxy() {
|
|
15
|
+
return devproxyArgv().at(-1);
|
|
16
|
+
}
|
|
17
|
+
async function findCompose() {
|
|
18
|
+
const docker = Bun.which("docker");
|
|
19
|
+
if (docker === null)
|
|
20
|
+
return;
|
|
21
|
+
const version = await $`${docker} compose version --short`.quiet().nothrow();
|
|
22
|
+
return version.exitCode === 0 ? `${docker} compose ${version.text().trim()}` : undefined;
|
|
23
|
+
}
|
|
24
|
+
var TOOLS = [
|
|
25
|
+
{ name: "git", for: "checks the worktrees out", get: "the git package of the system", needs: "always" },
|
|
26
|
+
{ name: "docker", for: "reads the compose project, clones its volumes and runs the stacks", get: "https://docs.docker.com/engine/install/", needs: "always" },
|
|
27
|
+
{ name: "docker compose", for: "runs the stacks", get: "the docker compose plugin, https://docs.docker.com/compose/install/linux/", needs: "always", find: findCompose },
|
|
28
|
+
{ name: "mkcert", for: "issues the certificates of a project with `certs`", get: "https://github.com/FiloSottile/mkcert, then `mkcert -install`", needs: (project) => project.certs !== undefined },
|
|
29
|
+
{ name: "devproxy", for: "routes the subdomains", get: "installed with wt, else `bun add -g @kaynooo/devproxy`", needs: "optional", find: findDevproxy },
|
|
30
|
+
{ name: "notify-send", for: "tells a --bg job is over", get: "the libnotify package of the system", needs: "optional" }
|
|
31
|
+
];
|
|
32
|
+
function neededBy(tool, project) {
|
|
33
|
+
return typeof tool.needs === "function" ? tool.needs(project) : tool.needs === "always";
|
|
34
|
+
}
|
|
35
|
+
async function locateTool(tool) {
|
|
36
|
+
return tool.find ? tool.find() : Bun.which(tool.name) ?? undefined;
|
|
37
|
+
}
|
|
38
|
+
async function assertTools2(project) {
|
|
39
|
+
const needed = TOOLS.filter((tool) => neededBy(tool, project));
|
|
40
|
+
const found = await Promise.all(needed.map(locateTool));
|
|
41
|
+
const missing = needed.filter((_, index) => found[index] === undefined);
|
|
42
|
+
if (missing.length)
|
|
43
|
+
throw new WtError(`${missing.map((tool) => `${tool.name} is not on PATH, ${tool.get}`).join(`
|
|
44
|
+
`)}
|
|
45
|
+
wt needs it for ${project.name}`, "`wt doctor` lists every program");
|
|
46
|
+
}
|
|
47
|
+
async function doctor2(projects) {
|
|
48
|
+
const found = await Promise.all(TOOLS.map(locateTool));
|
|
49
|
+
let code = 0;
|
|
50
|
+
const rows = TOOLS.map((tool, index) => {
|
|
51
|
+
const at = found[index];
|
|
52
|
+
const by = projects.filter((project) => neededBy(tool, project)).map((project) => project.name);
|
|
53
|
+
const required = tool.needs === "always" || by.length > 0;
|
|
54
|
+
let use = tool.for;
|
|
55
|
+
if (typeof tool.needs === "function")
|
|
56
|
+
use += by.length ? ` (${by.join(", ")})` : ", no project has them";
|
|
57
|
+
if (at !== undefined)
|
|
58
|
+
return ["ok", tool.name, at, use];
|
|
59
|
+
if (required)
|
|
60
|
+
code = 1;
|
|
61
|
+
return [required ? "missing" : "absent", tool.name, tool.get, use];
|
|
62
|
+
});
|
|
63
|
+
console.log(table([["", "program", "where", "for"], ...rows], { header: true }));
|
|
64
|
+
return code;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { assertTools2, doctor2 };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
WtError,
|
|
4
|
+
worktreeHost
|
|
5
|
+
} from "./cli-6k7xzgw2.js";
|
|
6
|
+
|
|
7
|
+
// src/routes.ts
|
|
8
|
+
import { existsSync, mkdirSync } from "fs";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
var {$ } = globalThis.Bun;
|
|
11
|
+
var LEADING_STAR = /^\*/;
|
|
12
|
+
async function mkcert(certFile, keyFile, hosts) {
|
|
13
|
+
const result = await $`mkcert -cert-file ${certFile} -key-file ${keyFile} ${hosts}`.quiet().nothrow();
|
|
14
|
+
if (result.exitCode !== 0)
|
|
15
|
+
throw new WtError(`mkcert failed for ${hosts.join(" ")}:
|
|
16
|
+
${result.stderr.toString()}`);
|
|
17
|
+
}
|
|
18
|
+
async function writeStackCerts(worktree) {
|
|
19
|
+
const { project } = worktree;
|
|
20
|
+
if (project.certs === undefined)
|
|
21
|
+
return;
|
|
22
|
+
const dir = join(worktree.dir, project.certs);
|
|
23
|
+
mkdirSync(dir, { recursive: true });
|
|
24
|
+
await Promise.all(project.routes.map(async (route) => {
|
|
25
|
+
const served = worktreeHost(route.host, worktree.task);
|
|
26
|
+
const name = served.replace(LEADING_STAR, "_wildcard");
|
|
27
|
+
const cert = join(dir, `${name}.pem`);
|
|
28
|
+
const key = join(dir, `${name}-key.pem`);
|
|
29
|
+
return existsSync(cert) && existsSync(key) ? undefined : mkcert(cert, key, [served]);
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
function urlsOf(worktree) {
|
|
33
|
+
return worktree.project.routes.filter((route) => !route.host.startsWith("*.")).map((route) => `https://${worktreeHost(route.host, worktree.task)}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { writeStackCerts, urlsOf };
|