@able-autonomy/able 0.2.1 → 0.2.2
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/package.json +1 -1
- package/src/ui.ts +1 -0
- package/src/workspaces/ls.ts +42 -17
package/package.json
CHANGED
package/src/ui.ts
CHANGED
|
@@ -14,6 +14,7 @@ export const bold = paint(1)
|
|
|
14
14
|
export const red = paint(31)
|
|
15
15
|
export const green = paint(32)
|
|
16
16
|
export const yellow = paint(33)
|
|
17
|
+
export const cyan = paint(36)
|
|
17
18
|
|
|
18
19
|
/** A moment as the CLI prints it: `19 Nov 2026, 13:37`. */
|
|
19
20
|
export const when = (at: Date | string) => new Date(at).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' })
|
package/src/workspaces/ls.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { resolve } from 'node:path'
|
|
|
13
13
|
import { loadConfig, urlOf } from '../../config.ts'
|
|
14
14
|
import { dirtyCount, lastFetched, mainRoot, unpushedCount } from '../git.ts'
|
|
15
15
|
import { shellFor, type Place } from '../run.ts'
|
|
16
|
-
import { bold, dim, red, when, yellow } from '../ui.ts'
|
|
16
|
+
import { bold, cyan, dim, red, when, yellow } from '../ui.ts'
|
|
17
17
|
import { overlapUnavailable, overlaps } from './overlap.ts'
|
|
18
18
|
import { answers } from './services.ts'
|
|
19
19
|
import { byAge, holderOf, openOf, PREVIEW, readState, running, workspaces } from './state.ts'
|
|
@@ -41,7 +41,11 @@ if (process.argv.includes('--json')) {
|
|
|
41
41
|
console.log(JSON.stringify(all.map((w) => ({ ...w, ...facts(w), ...url(w), ...build(w), overlap: overlap[w.slug] ?? [] }))))
|
|
42
42
|
process.exit(0)
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
// The table: the main checkout, then the preview right under it (both shared, neither a workspace of its own), then
|
|
45
|
+
// the workspaces, oldest first, below a rule.
|
|
46
|
+
const place = (w: (typeof all)[number]): Place => ({ slug: w.slug, path: w.path, portOffset: w.portOffset, main })
|
|
47
|
+
const shared = all.filter((w) => w.kind).map(place)
|
|
48
|
+
const rows: Place[] = [{ slug: 'main', path: main, portOffset: 0, main }, ...shared, ...all.filter((w) => !w.kind).map(place)]
|
|
45
49
|
const { services = {}, resources = {} } = config.workspaces ?? {}
|
|
46
50
|
const home = rows[0]
|
|
47
51
|
|
|
@@ -72,25 +76,46 @@ const upCount = async (w: Place) => {
|
|
|
72
76
|
}
|
|
73
77
|
const ups = await Promise.all(rows.map(upCount))
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
// Every column padded to its widest cell, before it is coloured, so each starts at the same place on every row.
|
|
80
|
+
type Cell = [text: string, paint: (s: string) => string]
|
|
81
|
+
const plain = (s: string) => s
|
|
82
|
+
const cells = rows.map((w, i): Cell[] => {
|
|
78
83
|
const up = ups[i] ?? 0
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const name: Cell = [w.slug, w.slug === PREVIEW ? (s) => cyan(bold(s)) : plain]
|
|
85
|
+
const services: Cell = up ? [`${up} running`, plain] : ['stopped', dim]
|
|
86
|
+
if (!existsSync(w.path)) return [name, [String(w.portOffset), plain], services, ['directory missing', yellow], ['', plain]]
|
|
87
|
+
const dirty = dirtyCount(w.path)
|
|
88
|
+
const ahead = unpushedCount(w.path)
|
|
89
|
+
const built = w.slug === PREVIEW ? state.workspaces[PREVIEW]?.build : undefined
|
|
90
|
+
const origin: Cell = built
|
|
91
|
+
? [`preview of ${built.included.map((i) => i.slug).join(', ') || `${base} alone`}, built ${when(built.at)}`, dim]
|
|
92
|
+
: ahead
|
|
93
|
+
? [`${ahead} unpushed`, yellow]
|
|
94
|
+
: ['0 unpushed', dim]
|
|
95
|
+
return [name, [String(w.portOffset), plain], services, dirty ? [`${dirty} dirty`, yellow] : ['clean', dim], origin]
|
|
96
|
+
})
|
|
97
|
+
const heads = ['CHECKOUT', 'OFFSET', 'SERVICES', 'TREE', '']
|
|
98
|
+
const widths = heads.map((h, c) => Math.max(h.length, ...cells.map((row) => row[c]![0].length)))
|
|
99
|
+
const line = (row: Cell[]) =>
|
|
100
|
+
row
|
|
101
|
+
.map(([text, paint], c) => (c === row.length - 1 ? paint(text) : paint(text.padEnd(widths[c]!))))
|
|
102
|
+
.join(' ')
|
|
103
|
+
.trimEnd()
|
|
104
|
+
console.log(
|
|
105
|
+
`\n ${bold(
|
|
106
|
+
heads
|
|
107
|
+
.map((h, c) => h.padEnd(widths[c]!))
|
|
108
|
+
.join(' ')
|
|
109
|
+
.trimEnd(),
|
|
110
|
+
)}`,
|
|
111
|
+
)
|
|
112
|
+
cells.forEach((row, i) => {
|
|
113
|
+
const w = rows[i]!
|
|
89
114
|
const holds = Object.entries(holders)
|
|
90
115
|
.filter(([, slugs]) => slugs.includes(w.slug))
|
|
91
116
|
.map(([name, slugs]) => (slugs.length > 1 ? red(name) : name))
|
|
92
|
-
|
|
93
|
-
console.log(` ${
|
|
117
|
+
if (i === shared.length + 1) console.log(dim(` ${'─'.repeat(widths.slice(0, 4).reduce((a, b) => a + b + 2, 0) - 2)} workspaces`))
|
|
118
|
+
console.log(` ${line(row)}${holds.length ? bold(` holds ${holds.join(' + ')}`) : ''}`)
|
|
94
119
|
})
|
|
95
120
|
for (const [name, slugs] of Object.entries(holders))
|
|
96
121
|
if (slugs.length > 1) console.log(red(`\n ${name} is held by ${slugs.join(' and ')} at once: able ws take ${name} in the one that should hold it`))
|