@able-autonomy/able 0.0.7 → 0.0.9
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/config.ts +6 -0
- package/package.json +1 -1
- package/src/commit.ts +4 -3
- package/src/workspaces/new.ts +26 -4
package/config.ts
CHANGED
|
@@ -37,6 +37,9 @@ export interface AbleConfig {
|
|
|
37
37
|
* touches; kept fast. `merge`: run from the root after those, at `able ws merge` only (the cross-package checks).
|
|
38
38
|
* Any failure stops it. Release checks (builds, tests) come with the Release module (98). */
|
|
39
39
|
checks?: { commit?: Record<string, Command[]>; merge?: Command[] }
|
|
40
|
+
/** `trailers`: lines such as `Co-Authored-By: …`, added to every commit Able makes with `able commit` and
|
|
41
|
+
* `able ws new --brief` (and so `able sync`'s); a message that already ends with one is not given it twice. */
|
|
42
|
+
commit?: { trailers?: string[] }
|
|
40
43
|
workspaces?: WorkspacesConfig
|
|
41
44
|
/** The branch workspaces are cut from and merged into. */
|
|
42
45
|
trunk: string
|
|
@@ -46,6 +49,9 @@ export interface AbleConfig {
|
|
|
46
49
|
knowledge?: string
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
/** The `git commit` flags for the host's trailers. */
|
|
53
|
+
export const trailerArgs = (config: AbleConfig) => (config.commit?.trailers ?? []).flatMap((t) => ['--trailer', t])
|
|
54
|
+
|
|
49
55
|
/** Types and editor help for `able.config.ts`; returns the config unchanged. */
|
|
50
56
|
export const defineConfig = (config: AbleConfig): AbleConfig => config
|
|
51
57
|
|
package/package.json
CHANGED
package/src/commit.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { existsSync } from 'node:fs'
|
|
11
11
|
import { join, relative, resolve } from 'node:path'
|
|
12
|
-
import { loadConfig } from '../config.ts'
|
|
12
|
+
import { loadConfig, trailerArgs } from '../config.ts'
|
|
13
13
|
import { runChecks } from './checks.ts'
|
|
14
14
|
import { failOnMerge, git, gitLoud } from './git.ts'
|
|
15
15
|
import { bold, confirm, dim, fail, green } from './ui.ts'
|
|
@@ -45,11 +45,12 @@ for (const f of before) console.log(dim(` ${f}`))
|
|
|
45
45
|
if (argv.includes('--dry')) process.exit(0)
|
|
46
46
|
if (!argv.includes('--yes') && !confirm(`Run the checks and commit as "${msg}"?`)) fail('aborted; nothing committed')
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const config = await loadConfig(root)
|
|
49
|
+
if (!runChecks(config, before, at)) fail('a check failed; nothing committed')
|
|
49
50
|
|
|
50
51
|
// The checks may have formatted files, so the list is read again.
|
|
51
52
|
const paths = changed()
|
|
52
53
|
// A path that is gone (a deletion, a rename's old name) has nothing to add, but still goes into the commit.
|
|
53
54
|
const present = paths.filter((p) => existsSync(join(root, p)))
|
|
54
|
-
if ((present.length && !gitLoud(root, 'add', '--', ...present)) || !gitLoud(root, 'commit', '--quiet', '-m', msg, '--', ...paths)) fail('git commit failed')
|
|
55
|
+
if ((present.length && !gitLoud(root, 'add', '--', ...present)) || !gitLoud(root, 'commit', '--quiet', '-m', msg, ...trailerArgs(config), '--', ...paths)) fail('git commit failed')
|
|
55
56
|
console.log(`\n ${green('✓')} ${git(root, 'log', '--oneline', '-1')}\n`)
|
package/src/workspaces/new.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
// able ws new <slug> [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`, then
|
|
1
|
+
// able ws new <slug> [--brief] [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`, then
|
|
2
2
|
// what a worktree can't inherit: the host's `copy` files and its `onCreate` commands, with this workspace's facts in
|
|
3
3
|
// `ABLE_WS_*`. Services are not started: `able ws start` does that. Every check runs before anything is created.
|
|
4
|
+
//
|
|
5
|
+
// `--brief` first publishes the workspace's brief, `<journal>/workspaces/<slug>.md`, from the main checkout on the trunk:
|
|
6
|
+
// it commits that file alone after its checks, when it has changes, and pushes the trunk, so the cut carries it. It
|
|
7
|
+
// refuses while the trunk has other unpushed commits, which would leave with it.
|
|
4
8
|
|
|
5
9
|
import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
6
10
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
7
|
-
import { loadConfig } from '../../config.ts'
|
|
8
|
-
import {
|
|
11
|
+
import { loadConfig, trailerArgs } from '../../config.ts'
|
|
12
|
+
import { runChecks } from '../checks.ts'
|
|
13
|
+
import { count, failOnMerge, fetchTrunk, git, gitLoud, mainRoot } from '../git.ts'
|
|
9
14
|
import { runCommand } from '../run.ts'
|
|
10
15
|
import { bold, dim, fail, green, yellow } from '../ui.ts'
|
|
11
16
|
import { branchOf, readState, workspaces, writeState } from './state.ts'
|
|
12
17
|
|
|
13
18
|
const args = process.argv.slice(4)
|
|
14
19
|
const slug = args.find((a) => !a.startsWith('-'))
|
|
15
|
-
if (!slug) fail('usage: able ws new <slug> [--no-fetch]')
|
|
20
|
+
if (!slug) fail('usage: able ws new <slug> [--brief] [--no-fetch]')
|
|
16
21
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) fail(`invalid name '${slug}': lowercase letters, digits and dashes only`)
|
|
17
22
|
|
|
18
23
|
const main = mainRoot()
|
|
@@ -32,6 +37,23 @@ const { ports } = ws
|
|
|
32
37
|
const portOffset = ports ? (Array.from({ length: ports.max }, (_, i) => (i + 1) * ports.step).find((o) => !taken.has(o)) ?? fail('no free port offset; remove a workspace first')) : 0
|
|
33
38
|
|
|
34
39
|
if (!args.includes('--no-fetch')) fetchTrunk(main, config.trunk)
|
|
40
|
+
|
|
41
|
+
if (args.includes('--brief')) {
|
|
42
|
+
const { trunk, journal } = config
|
|
43
|
+
const file = `${journal}/workspaces/${slug}.md`
|
|
44
|
+
if (!existsSync(join(main, file))) fail(`no brief at ${file}; write it first`)
|
|
45
|
+
if (git(main, 'rev-parse', '--abbrev-ref', 'HEAD') !== trunk) fail(`the main checkout is not on ${trunk}`)
|
|
46
|
+
failOnMerge(main)
|
|
47
|
+
const unpushed = git(main, 'log', '--oneline', `origin/${trunk}..${trunk}`)
|
|
48
|
+
if (unpushed) fail(`${trunk} has unpushed commits that would leave with the brief:\n${unpushed}`)
|
|
49
|
+
if (git(main, 'status', '--porcelain', '--', file)) {
|
|
50
|
+
const at = { slug: 'main', path: main, portOffset: 0, main }
|
|
51
|
+
if (!runChecks(config, [file], at)) fail('a check failed; nothing committed')
|
|
52
|
+
if (!gitLoud(main, 'add', '--', file) || !gitLoud(main, 'commit', '--quiet', '-m', `journal: ${slug} brief`, ...trailerArgs(config), '--', file)) fail('commit of the brief failed')
|
|
53
|
+
}
|
|
54
|
+
if (count(main, `origin/${trunk}..${trunk}`) && !gitLoud(main, 'push', '--quiet', 'origin', trunk)) fail(`push of ${trunk} failed`)
|
|
55
|
+
}
|
|
56
|
+
|
|
35
57
|
// Cut from origin's trunk: the main checkout's own branch may lag, and is the operator's to move.
|
|
36
58
|
const start = git(main, 'rev-parse', '--verify', '--quiet', `origin/${config.trunk}`) ? `origin/${config.trunk}` : config.trunk
|
|
37
59
|
|