toolcrib 0.9.0 → 0.11.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/README.md +95 -17
- package/package.json +1 -1
- package/src/commands/apply.js +34 -9
- package/src/commands/exportPatches.js +283 -0
- package/src/commands/init.js +7 -1
- package/src/commands/merge.js +248 -86
- package/src/index.js +11 -0
- package/src/lib/discussions.js +183 -0
- package/src/lib/exportFormat.js +224 -0
- package/src/lib/exportPatches.js +582 -0
- package/src/lib/git.js +95 -6
- package/src/lib/importScan.js +139 -0
- package/src/lib/lineMerge.js +190 -0
- package/src/lib/patches.js +80 -27
- package/src/lib/release.js +3 -0
- package/src/lib/zip.js +61 -0
package/README.md
CHANGED
|
@@ -138,12 +138,21 @@ toolcrib apply
|
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
This is the command that actually creates/modifies files. It applies each
|
|
141
|
-
patch in order
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
patch in order and reports how many succeeded. Staged work is never thrown
|
|
142
|
+
away:
|
|
143
|
+
|
|
144
|
+
- A patch that applied is removed from `./toolcrib-patches/`.
|
|
145
|
+
- **If any patch fails, nothing else is deleted.** The failed patches stay in
|
|
146
|
+
the folder and are listed, so you can fix the cause and re-run `apply`
|
|
147
|
+
(or delete the folder and run `merge` again).
|
|
148
|
+
- Conflict notes and upstream copies from `merge` (under
|
|
149
|
+
`./toolcrib-patches/conflicts/`) are not patches, so `apply` never writes
|
|
150
|
+
them into `./toolcrib/`. They stay in the folder, and `apply` lists them,
|
|
151
|
+
until you delete the folder.
|
|
152
|
+
- The folder itself is removed only when everything in it has been dealt with.
|
|
153
|
+
|
|
154
|
+
`init` and `merge` refuse to start while `./toolcrib-patches/` exists and is
|
|
155
|
+
not empty, and tell you to run `toolcrib apply` or delete the folder.
|
|
147
156
|
|
|
148
157
|
If your project isn't already a git repository, `apply` will offer to run
|
|
149
158
|
`git init` for you first (it uses `git apply` when possible, since that
|
|
@@ -203,16 +212,45 @@ toolcrib merge --version 2.1.0 # upgrade to a specific version
|
|
|
203
212
|
|
|
204
213
|
Works like `init`, but smarter: for every vendored file, it compares three
|
|
205
214
|
things — what you originally got, what's actually on disk now, and what
|
|
206
|
-
the new version ships — and sorts each file into one of
|
|
215
|
+
the new version ships — and sorts each file into one of these outcomes:
|
|
207
216
|
|
|
208
|
-
- **
|
|
217
|
+
- **Updated** — you never touched the file; the new version's copy is
|
|
209
218
|
staged as a patch.
|
|
210
|
-
- **Kept
|
|
219
|
+
- **Kept local** — you edited the file yourself and upstream didn't change
|
|
211
220
|
it; left alone, no patch generated.
|
|
212
|
-
- **
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
221
|
+
- **Merged** — you edited it *and* upstream changed it, but in different
|
|
222
|
+
places. `merge` does a line-level three-way merge (your copy, the version
|
|
223
|
+
you installed, the new version) and stages the merged file as an ordinary
|
|
224
|
+
patch. It uses `git merge-file` when git is installed and a built-in
|
|
225
|
+
merge otherwise. Line endings are normalized for the merge and your
|
|
226
|
+
file's own style (CRLF or LF, and a leading BOM) is kept in the result.
|
|
227
|
+
- **Absorbed upstream** — the new release already contains your change (it
|
|
228
|
+
merges to exactly the new version's file, or your file already equals it).
|
|
229
|
+
Reported separately so you can see your patch landed upstream.
|
|
230
|
+
- **Conflict** — the edits overlap. The file is staged *with conflict
|
|
231
|
+
markers* (`<<<<<<< local` / `=======` / `>>>>>>> vX.Y.Z`) as a normal
|
|
232
|
+
patch, and listed by path in the summary. A file you edited that upstream
|
|
233
|
+
removed, or one you deleted that upstream changed, can't be merged: your
|
|
234
|
+
file is left untouched and only a note is written.
|
|
235
|
+
- **Binary conflict** — a file that isn't valid UTF-8 text (or contains a NUL
|
|
236
|
+
byte) is never line-merged. Your copy is untouched; the upstream copy is
|
|
237
|
+
staged whole, next to a note, in the staging folder.
|
|
238
|
+
- **Project-added** — a file under `./toolcrib/` that neither the installed nor
|
|
239
|
+
the new release ships (your own component, say). Listed as kept and never
|
|
240
|
+
touched. (`__tests__/` is only considered when you installed the test suite.)
|
|
241
|
+
- **Collision** — you added a file at a path the new release now ships. It is
|
|
242
|
+
three-way merged against an empty base: identical content is absorbed,
|
|
243
|
+
anything else is staged with conflict markers and reported as a collision.
|
|
244
|
+
|
|
245
|
+
Conflict notes and binary upstream copies are written under
|
|
246
|
+
`./toolcrib-patches/conflicts/` as plain files (`<path>.md`, `<path>.upstream`).
|
|
247
|
+
They are never written into `./toolcrib/`, because `apply` only applies
|
|
248
|
+
`.patch` files. When it finishes, `merge` prints a count for each outcome
|
|
249
|
+
above, then the conflicting paths and where their notes are.
|
|
250
|
+
|
|
251
|
+
Limitation: only files in conflict are checked for binary content. A binary
|
|
252
|
+
file that only upstream changed still goes through the ordinary text-patch
|
|
253
|
+
path, as before; the toolkit ships text source only.
|
|
216
254
|
|
|
217
255
|
If you installed the test suite via `toolcrib init --with-tests`, `merge`
|
|
218
256
|
keeps it in sync automatically — no separate flag needed here; it checks
|
|
@@ -231,6 +269,37 @@ toolcrib versions
|
|
|
231
269
|
Useful for picking an exact `--version` for `init` or `merge` instead of
|
|
232
270
|
always taking `latest`.
|
|
233
271
|
|
|
272
|
+
### `toolcrib export-patches`
|
|
273
|
+
|
|
274
|
+
Sends your changes to the vendored toolcrib source back upstream. It
|
|
275
|
+
compares `./toolcrib/` against the release recorded in
|
|
276
|
+
`toolcrib/.toolcrib-lock.json`, then writes one folder per contribution
|
|
277
|
+
to `./toolcrib-upstream/`. Each folder holds `git apply`-able patches
|
|
278
|
+
against toolcrib's own `src/` layout, plus a `SUMMARY.md`.
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
toolcrib export-patches # write folders to ./toolcrib-upstream/
|
|
282
|
+
toolcrib export-patches --out ./upstream # choose another folder
|
|
283
|
+
toolcrib export-patches --post # post each folder as a discussion (asks y/N)
|
|
284
|
+
toolcrib export-patches --post --yes # post without the prompt (needed outside a terminal)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
- Only `components/`, `theme/`, `eventBus/`, and `observer/` changes are
|
|
288
|
+
exported. Changes to `ai-docs/`, `eslint-rules/`, and vendored tests are
|
|
289
|
+
listed as not exported. Edits to `index.ts` are expected and not
|
|
290
|
+
exported, since upstream regenerates it.
|
|
291
|
+
- Changes to shared files are split by contribution. A change that matches
|
|
292
|
+
no contribution is app-specific and not exported. A change that matches
|
|
293
|
+
two is ambiguous and not exported.
|
|
294
|
+
- Before posting, fill in each `SUMMARY.md`'s `intent:` lines
|
|
295
|
+
(`bug-fix`, `missing-feature`, or `customization`).
|
|
296
|
+
- `--post` creates a discussion in the **Consumer Patches** category of the
|
|
297
|
+
toolcrib repository, using your own `gh` login. It asks y/N first and
|
|
298
|
+
never posts without that answer or `--yes`. A folder that was already
|
|
299
|
+
posted (it has a `posted.json`) is skipped.
|
|
300
|
+
- The command never changes your project files. It only reads `./toolcrib/`
|
|
301
|
+
and writes the output folder.
|
|
302
|
+
|
|
234
303
|
## Reviewing and applying patches
|
|
235
304
|
|
|
236
305
|
After `init` or `merge`, you'll have a `./toolcrib-patches/` folder full of
|
|
@@ -271,10 +340,19 @@ notes of your own outside the fence, then run `merge` to restore it
|
|
|
271
340
|
cleanly.
|
|
272
341
|
|
|
273
342
|
**`merge` reports a conflict.**
|
|
274
|
-
You changed a vendored file yourself, and the new version changed it
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
343
|
+
You changed a vendored file yourself, and the new version changed it in an
|
|
344
|
+
overlapping place. For a text file, `apply` writes it with conflict markers:
|
|
345
|
+
resolve each `<<<<<<< local` ... `>>>>>>> vX.Y.Z` block in place. The note at
|
|
346
|
+
`./toolcrib-patches/conflicts/<file>.md` shows what upstream changed. For
|
|
347
|
+
removed, deleted and binary files nothing is written to your file; read the
|
|
348
|
+
note (and the staged `.upstream` copy for binary files). Or hand it to your AI
|
|
349
|
+
assistant with "reconcile my local changes to `<file>` with the upstream
|
|
350
|
+
update." Delete `./toolcrib-patches/` when you're done; `merge` and `init`
|
|
351
|
+
won't run while it's there.
|
|
352
|
+
|
|
353
|
+
**`merge` or `init` says `./toolcrib-patches/` already holds staged work.**
|
|
354
|
+
They refuse to overwrite unapplied patches or conflict notes. Run `toolcrib
|
|
355
|
+
apply`, or delete the folder if you're finished with it.
|
|
278
356
|
|
|
279
357
|
**A bundler-specific note from `doctor`.**
|
|
280
358
|
`doctor` detects Next.js, Create React App, Vite, webpack, and Parcel from
|
package/package.json
CHANGED
package/src/commands/apply.js
CHANGED
|
@@ -4,6 +4,12 @@ import * as p from '@clack/prompts';
|
|
|
4
4
|
import { PATCH_DIR } from '../lib/patches.js';
|
|
5
5
|
import { isGitInstalled, ensureGitRepo, gitApplyStreaming } from '../lib/git.js';
|
|
6
6
|
import { applyPatchFallback } from '../lib/patchFallback.js';
|
|
7
|
+
import { listFilesRecursive } from '../lib/zip.js';
|
|
8
|
+
|
|
9
|
+
/** Every file left under the staging folder, forward-slash, relative to it. */
|
|
10
|
+
function listStaged(dir) {
|
|
11
|
+
return listFilesRecursive(dir);
|
|
12
|
+
}
|
|
7
13
|
|
|
8
14
|
export async function applyCommand() {
|
|
9
15
|
const projectRoot = process.cwd();
|
|
@@ -23,7 +29,14 @@ export async function applyCommand() {
|
|
|
23
29
|
.map((f) => path.join(patchDir, f));
|
|
24
30
|
|
|
25
31
|
if (patchFiles.length === 0) {
|
|
26
|
-
|
|
32
|
+
const staged = listStaged(patchDir);
|
|
33
|
+
// Only empty folders left (every note resolved and deleted): clear them.
|
|
34
|
+
if (staged.length === 0) fs.rmSync(patchDir, { recursive: true, force: true });
|
|
35
|
+
p.outro(
|
|
36
|
+
staged.length > 0
|
|
37
|
+
? `No pending patches. ./toolcrib-patches/ still holds ${staged.length} note/upstream-copy file(s) from a merge; resolve them, then delete the folder.`
|
|
38
|
+
: 'No pending patches.'
|
|
39
|
+
);
|
|
27
40
|
return;
|
|
28
41
|
}
|
|
29
42
|
|
|
@@ -64,18 +77,30 @@ export async function applyCommand() {
|
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
79
|
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
80
|
+
// Staging safety: nothing that hasn't been dealt with is ever deleted.
|
|
81
|
+
// Patches that applied are done, so they're removed (re-running apply
|
|
82
|
+
// would only fail on them). A failed patch stays, and so does everything
|
|
83
|
+
// else staged beside the patches (conflict notes, binary upstream copies):
|
|
84
|
+
// those are the user's work-in-progress, and `merge`/`init` refuse to run
|
|
85
|
+
// over a non-empty folder precisely so they can't be lost.
|
|
86
|
+
for (const patchFile of succeeded) fs.rmSync(patchFile, { force: true });
|
|
87
|
+
const remaining = listStaged(patchDir);
|
|
88
|
+
if (remaining.length === 0) fs.rmSync(patchDir, { recursive: true, force: true });
|
|
73
89
|
|
|
74
90
|
p.log.success(`Applied ${succeeded.length} of ${patchFiles.length} patch(es).`);
|
|
75
91
|
if (failed.length > 0) {
|
|
76
92
|
p.log.warn(
|
|
77
|
-
`${failed.length} patch(es) failed and were
|
|
78
|
-
`
|
|
93
|
+
`${failed.length} patch(es) failed and were kept in ./toolcrib-patches/ (nothing was deleted):\n` +
|
|
94
|
+
failed.map((f) => ` ${path.basename(f.patchFile)}${f.error ? ` — ${f.error.split('\n')[0]}` : ''}`).join('\n') +
|
|
95
|
+
`\nFix the cause and re-run 'toolcrib apply', or delete the folder and run 'toolcrib merge' again to regenerate them.`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const notes = remaining.filter((f) => !f.endsWith('.patch'));
|
|
99
|
+
if (notes.length > 0) {
|
|
100
|
+
p.log.info(
|
|
101
|
+
`${notes.length} staged file(s) were not applied (they are notes and upstream copies, never written into ./toolcrib/):\n` +
|
|
102
|
+
notes.map((f) => ` ./toolcrib-patches/${f}`).join('\n') +
|
|
103
|
+
`\nResolve what they describe, then delete ./toolcrib-patches/. 'toolcrib merge' will not run until it's gone.`
|
|
79
104
|
);
|
|
80
105
|
}
|
|
81
106
|
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import { fetchRelease } from '../lib/release.js';
|
|
6
|
+
import { readLock } from '../lib/project.js';
|
|
7
|
+
import { listFilesRecursive } from '../lib/zip.js';
|
|
8
|
+
import { analyzeExport } from '../lib/exportPatches.js';
|
|
9
|
+
import {
|
|
10
|
+
contributionFolder,
|
|
11
|
+
patchFileName,
|
|
12
|
+
renderSummary,
|
|
13
|
+
renderReadme,
|
|
14
|
+
parseIntents,
|
|
15
|
+
INTENT_PLACEHOLDER,
|
|
16
|
+
} from '../lib/exportFormat.js';
|
|
17
|
+
import {
|
|
18
|
+
defaultRunGh,
|
|
19
|
+
ghLogin,
|
|
20
|
+
createDiscussion,
|
|
21
|
+
addDiscussionComment,
|
|
22
|
+
buildPostPlan,
|
|
23
|
+
CATEGORY_URL,
|
|
24
|
+
MAX_BODY,
|
|
25
|
+
} from '../lib/discussions.js';
|
|
26
|
+
|
|
27
|
+
const TOOLKIT_DIR = 'toolcrib';
|
|
28
|
+
const DEFAULT_OUT = './toolcrib-upstream';
|
|
29
|
+
const MARKER = '.toolcrib-export';
|
|
30
|
+
// Meta-configuration the CLI itself writes, never toolkit source.
|
|
31
|
+
const SKIP_LOCAL = new Set(['.toolcrib-lock.json', '.toolcrib-tests-config.json']);
|
|
32
|
+
|
|
33
|
+
const cliVersion = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
34
|
+
|
|
35
|
+
function readLocalFiles(projectRoot) {
|
|
36
|
+
const root = path.join(projectRoot, TOOLKIT_DIR);
|
|
37
|
+
const files = new Map();
|
|
38
|
+
for (const relPath of listFilesRecursive(root)) {
|
|
39
|
+
if (SKIP_LOCAL.has(relPath)) continue;
|
|
40
|
+
files.set(relPath, fs.readFileSync(path.join(root, relPath), 'utf-8'));
|
|
41
|
+
}
|
|
42
|
+
return files;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Refuse to clear a directory this command didn't create. Returns an error string, or null when safe. */
|
|
46
|
+
function checkOutDir(outDir) {
|
|
47
|
+
if (!fs.existsSync(outDir)) return null;
|
|
48
|
+
if (!fs.statSync(outDir).isDirectory()) return `${outDir} exists and is not a directory.`;
|
|
49
|
+
const entries = fs.readdirSync(outDir);
|
|
50
|
+
if (entries.length > 0 && !entries.includes(MARKER)) {
|
|
51
|
+
return `${outDir} is not empty and was not created by \`toolcrib export-patches\` (no ${MARKER} marker). Choose another --out, or remove it yourself.`;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Upstream path of a patch, from its `+++ b/` header (or `--- a/` for a deletion). */
|
|
57
|
+
function upstreamPathOf(patchText) {
|
|
58
|
+
const plus = /^\+\+\+ b\/(.+)$/m.exec(patchText);
|
|
59
|
+
if (plus) return plus[1].trim();
|
|
60
|
+
const minus = /^--- a\/(.+)$/m.exec(patchText);
|
|
61
|
+
return minus ? minus[1].trim() : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function postExport(options) {
|
|
65
|
+
const projectRoot = process.cwd();
|
|
66
|
+
const runGh = options.runGh ?? defaultRunGh;
|
|
67
|
+
const confirm = options.confirm ?? p.confirm;
|
|
68
|
+
const isTTY = options.isTTY ?? Boolean(process.stdin.isTTY);
|
|
69
|
+
p.intro('toolcrib export-patches --post');
|
|
70
|
+
|
|
71
|
+
const outDir = path.resolve(projectRoot, options.out ?? DEFAULT_OUT);
|
|
72
|
+
if (!fs.existsSync(path.join(outDir, MARKER))) {
|
|
73
|
+
p.log.error(`No export found at ${outDir}; run \`toolcrib export-patches\` first.`);
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const folders = fs
|
|
79
|
+
.readdirSync(outDir, { withFileTypes: true })
|
|
80
|
+
.filter((d) => d.isDirectory())
|
|
81
|
+
.map((d) => d.name)
|
|
82
|
+
.sort();
|
|
83
|
+
const plans = [];
|
|
84
|
+
for (const folder of folders) {
|
|
85
|
+
const dir = path.join(outDir, folder);
|
|
86
|
+
const postedFile = path.join(dir, 'posted.json');
|
|
87
|
+
if (fs.existsSync(postedFile)) {
|
|
88
|
+
let url = '';
|
|
89
|
+
try {
|
|
90
|
+
url = JSON.parse(fs.readFileSync(postedFile, 'utf8')).url ?? '';
|
|
91
|
+
} catch {
|
|
92
|
+
// unreadable record: still treat as posted
|
|
93
|
+
}
|
|
94
|
+
p.log.info(`${folder}: already posted${url ? ` (${url})` : ''}; skipping.`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const summaryPath = path.join(dir, 'SUMMARY.md');
|
|
98
|
+
if (!fs.existsSync(summaryPath)) continue;
|
|
99
|
+
const summaryText = fs.readFileSync(summaryPath, 'utf8');
|
|
100
|
+
const patches = fs
|
|
101
|
+
.readdirSync(dir)
|
|
102
|
+
.filter((f) => f.endsWith('.patch'))
|
|
103
|
+
.sort()
|
|
104
|
+
.map((fileName) => {
|
|
105
|
+
const text = fs.readFileSync(path.join(dir, fileName), 'utf8');
|
|
106
|
+
return { fileName, upstreamPath: upstreamPathOf(text) ?? fileName, text };
|
|
107
|
+
});
|
|
108
|
+
plans.push({ folder, dir, summaryText, plan: buildPostPlan({ summaryText, patches }) });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (plans.length === 0) {
|
|
112
|
+
p.outro('Nothing to post.');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const unspecified = plans.filter((x) => parseIntents(x.summaryText).includes(INTENT_PLACEHOLDER));
|
|
117
|
+
if (unspecified.length) {
|
|
118
|
+
p.log.warn(
|
|
119
|
+
`These contributions still have \`intent: ${INTENT_PLACEHOLDER}\` in SUMMARY.md: ${unspecified.map((x) => x.folder).join(', ')}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const login = ghLogin(runGh);
|
|
124
|
+
if (!login) {
|
|
125
|
+
p.log.info(
|
|
126
|
+
`gh CLI not found or not logged in. To post by hand: open ${CATEGORY_URL}, start a new discussion, use the title below and paste SUMMARY.md as the body (and each patch as a comment if the body is over ${MAX_BODY.toLocaleString('en-US')} characters).\n` +
|
|
127
|
+
plans.map((x) => ` ${x.folder}: ${x.plan.title}`).join('\n')
|
|
128
|
+
);
|
|
129
|
+
p.outro('Not posted.');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
p.log.info(
|
|
134
|
+
plans
|
|
135
|
+
.map((x) => `${x.plan.title}\n body ${x.plan.body.length} chars, ${x.plan.comments.length} comment(s)`)
|
|
136
|
+
.join('\n') + `\nPosting as @${login} to escape-llc/toolcrib → Consumer Patches`
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (!options.yes) {
|
|
140
|
+
if (!isTTY) {
|
|
141
|
+
p.log.info('Not an interactive terminal; re-run with --yes to post.');
|
|
142
|
+
p.outro('Not posted.');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const answer = await confirm({ message: `Post ${plans.length} discussion(s)?`, initialValue: false });
|
|
146
|
+
if (p.isCancel(answer) || !answer) {
|
|
147
|
+
p.outro('Not posted.');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'toolcrib-post-'));
|
|
153
|
+
try {
|
|
154
|
+
let n = 0;
|
|
155
|
+
for (const { folder, dir, plan } of plans) {
|
|
156
|
+
try {
|
|
157
|
+
const write = (text) => {
|
|
158
|
+
const file = path.join(tmp, `${++n}.md`);
|
|
159
|
+
fs.writeFileSync(file, text);
|
|
160
|
+
return file;
|
|
161
|
+
};
|
|
162
|
+
const { id, url } = createDiscussion(runGh, { title: plan.title, bodyFile: write(plan.body) });
|
|
163
|
+
const commentUrls = [];
|
|
164
|
+
for (const c of plan.comments) {
|
|
165
|
+
commentUrls.push(addDiscussionComment(runGh, { discussionId: id, bodyFile: write(c) }));
|
|
166
|
+
}
|
|
167
|
+
fs.writeFileSync(
|
|
168
|
+
path.join(dir, 'posted.json'),
|
|
169
|
+
JSON.stringify({ url, id, postedAt: new Date().toISOString(), comments: commentUrls }, null, 2) + '\n'
|
|
170
|
+
);
|
|
171
|
+
p.log.success(`${folder}: ${url}`);
|
|
172
|
+
} catch (err) {
|
|
173
|
+
p.log.error(`${folder}: ${err.message}`);
|
|
174
|
+
process.exitCode = 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} finally {
|
|
178
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
179
|
+
}
|
|
180
|
+
p.outro(process.exitCode === 1 ? 'Finished with errors.' : 'Posted.');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export async function exportPatchesCommand(options = {}) {
|
|
184
|
+
if (options.post) return postExport(options);
|
|
185
|
+
const projectRoot = process.cwd();
|
|
186
|
+
p.intro('toolcrib export-patches');
|
|
187
|
+
|
|
188
|
+
const lock = readLock(projectRoot);
|
|
189
|
+
if (!lock) {
|
|
190
|
+
p.log.error('No toolcrib install found (missing .toolcrib-lock.json). Run `toolcrib init` first.');
|
|
191
|
+
process.exitCode = 1;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const outDir = path.resolve(projectRoot, options.out ?? DEFAULT_OUT);
|
|
196
|
+
const outError = checkOutDir(outDir);
|
|
197
|
+
if (outError) {
|
|
198
|
+
p.log.error(outError);
|
|
199
|
+
process.exitCode = 1;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const spinner = p.spinner();
|
|
204
|
+
spinner.start(`Fetching installed release (v${lock.version})`);
|
|
205
|
+
let release;
|
|
206
|
+
try {
|
|
207
|
+
release = await fetchRelease(lock.version);
|
|
208
|
+
} catch (err) {
|
|
209
|
+
spinner.stop('Failed to fetch release');
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
212
|
+
spinner.stop(`Comparing ./${TOOLKIT_DIR}/ against v${release.version}`);
|
|
213
|
+
|
|
214
|
+
let analysis;
|
|
215
|
+
try {
|
|
216
|
+
const releaseFiles = new Map();
|
|
217
|
+
for (const relPath of release.allFiles()) releaseFiles.set(relPath, release.readFile(relPath));
|
|
218
|
+
analysis = analyzeExport({ releaseFiles, localFiles: readLocalFiles(projectRoot) });
|
|
219
|
+
} finally {
|
|
220
|
+
await release.cleanup();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!analysis.hasChanges) {
|
|
224
|
+
p.log.info('No changes to vendored toolkit source.');
|
|
225
|
+
p.outro('Nothing to export.');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const baseVersion = release.version;
|
|
230
|
+
const entries = analysis.contributions.map((contribution, i) => ({
|
|
231
|
+
folder: contributionFolder(i, contribution.name),
|
|
232
|
+
contribution,
|
|
233
|
+
}));
|
|
234
|
+
|
|
235
|
+
fs.rmSync(outDir, { recursive: true, force: true });
|
|
236
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
237
|
+
fs.writeFileSync(path.join(outDir, MARKER), 'Created by `toolcrib export-patches`; safe to replace.\n');
|
|
238
|
+
|
|
239
|
+
for (const { folder, contribution } of entries) {
|
|
240
|
+
const dir = path.join(outDir, folder);
|
|
241
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
242
|
+
const patches = contribution.files
|
|
243
|
+
.filter((f) => f.patch)
|
|
244
|
+
.map((file, i) => ({ file, fileName: patchFileName(i, file.upstreamPath) }));
|
|
245
|
+
for (const { file, fileName } of patches) fs.writeFileSync(path.join(dir, fileName), file.patch);
|
|
246
|
+
fs.writeFileSync(
|
|
247
|
+
path.join(dir, 'SUMMARY.md'),
|
|
248
|
+
renderSummary({
|
|
249
|
+
contribution,
|
|
250
|
+
baseVersion,
|
|
251
|
+
cliVersion,
|
|
252
|
+
notExported: analysis.notExported,
|
|
253
|
+
regeneratedUpstream: analysis.regeneratedUpstream,
|
|
254
|
+
patches,
|
|
255
|
+
})
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
fs.writeFileSync(
|
|
259
|
+
path.join(outDir, 'README.md'),
|
|
260
|
+
renderReadme({
|
|
261
|
+
baseVersion,
|
|
262
|
+
entries,
|
|
263
|
+
notExported: analysis.notExported,
|
|
264
|
+
regeneratedUpstream: analysis.regeneratedUpstream,
|
|
265
|
+
appSpecific: analysis.appSpecific,
|
|
266
|
+
ambiguous: analysis.ambiguous,
|
|
267
|
+
})
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
p.log.success(
|
|
271
|
+
`${entries.length} contribution(s) written to ${outDir}` +
|
|
272
|
+
`\n ${analysis.notExported.length} file(s) not exported` +
|
|
273
|
+
`\n ${analysis.appSpecific.length} app-specific shared-file hunk(s)` +
|
|
274
|
+
`\n ${analysis.ambiguous.length} ambiguous shared-file hunk(s)`
|
|
275
|
+
);
|
|
276
|
+
// Commander always fills in --out's default, so compare resolved paths
|
|
277
|
+
// rather than checking whether the option was set.
|
|
278
|
+
const isDefaultOut = outDir === path.resolve(projectRoot, DEFAULT_OUT);
|
|
279
|
+
const outArg = isDefaultOut ? '' : ` --out ${options.out}`;
|
|
280
|
+
p.outro(
|
|
281
|
+
`Fill in each contribution's \`intent:\` lines in its SUMMARY.md, review, then run \`toolcrib export-patches --post${outArg}\`.`
|
|
282
|
+
);
|
|
283
|
+
}
|
package/src/commands/init.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import * as p from '@clack/prompts';
|
|
3
3
|
import { fetchRelease, fetchTestsRelease } from '../lib/release.js';
|
|
4
4
|
import { resolveVersion } from '../lib/github.js';
|
|
5
|
-
import { PendingChanges, joinPatchPath } from '../lib/patches.js';
|
|
5
|
+
import { PendingChanges, joinPatchPath, hasStagedWork, STAGED_WORK_MESSAGE } from '../lib/patches.js';
|
|
6
6
|
import { resolveDependencyDecisions, buildProposedPackageJson, mergeImportsField } from '../lib/deps.js';
|
|
7
7
|
import { readJsonIfExists, readTextIfExists, fileExists, proposeGitignore, proposeLockUpdate } from '../lib/project.js';
|
|
8
8
|
import { MANAGED_DOCS, DEFAULT_TARGET_FILE, KNOWN_TARGET_FILES, upsertManagedBlock } from '../lib/managedDocs.js';
|
|
@@ -39,6 +39,12 @@ export async function initCommand(options) {
|
|
|
39
39
|
|
|
40
40
|
p.intro('toolcrib init');
|
|
41
41
|
|
|
42
|
+
if (hasStagedWork(projectRoot)) {
|
|
43
|
+
p.log.error(STAGED_WORK_MESSAGE);
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
const spinner = p.spinner();
|
|
43
49
|
spinner.start(`Resolving version "${options.version}"`);
|
|
44
50
|
// Resolved once here, then passed as a concrete version string to both
|