Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,33 @@ without excessive gaps.

## NPM Publishing & Versioning Guide

We use **Semantic Versioning (SemVer)** to manage releases. Instead of manually editing `package.json`, use the following automated workflow to ensure the repository tags and the NPM registry remain perfectly in sync.
We use **Semantic Versioning (SemVer)** to manage releases. Instead of manually editing `package.json`, use the following workflow to keep the repository tags, GitHub Releases, and the npm registry in sync.

### 1. Semantic Versioning Commands
### 1. Bump the version

Decide which part of the version number ($X.Y.Z$) to increment based on your changes:
Start from a clean, up-to-date `main` (`git pull`, `git status`). Decide which part of the version number ($X.Y.Z$) to increment:

| Command | Result | Use Case |
| :------------------ | :------------------ | :-------------------------------------------------------------------- |
| `pnpm version patch` | `0.0.x` → `0.0.x+1` | Bug fixes, style tweaks, or minor text updates. |
| `pnpm version minor` | `0.x.0` → `0.x+1.0` | New features (e.g., a new PDF theme) that are backward-compatible. |
| `pnpm version major` | `x.0.0` → `x+1.0.0` | Breaking changes (e.g., changing the data tape structure or CLI API). |
| `npm version patch` | `0.0.x` → `0.0.x+1` | Bug fixes, style tweaks, or minor text updates. |
| `npm version minor` | `0.x.0` → `0.x+1.0` | New features (e.g., a new PDF theme) that are backward-compatible. |
| `npm version major` | `x.0.0` → `x+1.0.0` | Breaking changes (e.g., changing the data tape structure or CLI API). |

> **Note:** These commands automatically update `package.json` and `pnpm-lock.yaml`, create a git commit, and generate a git tag.
> **Note:** These commands update `package.json`, create a git commit, and create an annotated git tag (`vX.Y.Z`). Use `npm version`, not `pnpm version` — pnpm rejects the `-m` flag. `%s` in the message is replaced with the new version.

Example:

```bash
pnpm version patch -m "Release v%s: Fixed header spacing and updated blah theme"
npm version patch -m "Release v%s: Fixed header spacing and updated blah theme"
```

### 2. Sync to GitHub (with tags)

```bash
git push origin main --follow-tags
```

> `--follow-tags` only pushes **annotated** tags. If a tag was created by hand with `git tag vX.Y.Z` (lightweight), push it explicitly: `git push origin vX.Y.Z`. Verify with `git ls-remote --tags origin`.

### 3. Publish to npm

Expand All @@ -134,14 +138,10 @@ pnpm login
pnpm publish
```

### 5. Finalize GitHub Release

Go to the Releases tab on GitHub.
### 4. Create the GitHub Release

Click Draft a new release.

Select the Tag you just pushed (e.g., v0.0.6).

Click Generate release notes to automatically pull in your commit history.
```bash
gh release create vX.Y.Z --verify-tag --title vX.Y.Z --generate-notes --latest
```

Click Publish release
Or in the browser: Releases → Draft a new release → select the pushed tag → Generate release notes → Publish release.
Binary file modified public/baldur-terminal-cv.pdf
Binary file not shown.
Binary file modified public/baldur-vintage-cv.pdf
Binary file not shown.
Binary file removed public/craig-cv.pdf
Binary file not shown.
Binary file modified public/craig-terminal-cv.pdf
Binary file not shown.
Binary file modified public/craig-vintage-cv.pdf
Binary file not shown.
48 changes: 43 additions & 5 deletions scripts/copy-pdfs/_tests_/copy-pdfs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe("copyStaticPdfs", () => {
const writes: string[] = [];

fs.mkdirSync(publicDir, { recursive: true });
fs.writeFileSync(path.join(publicDir, "craig-cv.pdf"), "CRAIG PDF");
fs.writeFileSync(
path.join(publicDir, "craig-terminal-cv.pdf"),
"CRAIG PDF",
);
fs.writeFileSync(path.join(publicDir, "baldur-cv.pdf"), "BALDUR PDF");
fs.writeFileSync(path.join(publicDir, "notes.txt"), "ignore me");

Expand All @@ -40,10 +43,14 @@ describe("copyStaticPdfs", () => {
},
});

expect(result.copiedFiles).toEqual(["baldur-cv.pdf", "craig-cv.pdf"]);
expect(fs.readFileSync(path.join(distPdfDir, "craig-cv.pdf"), "utf8")).toBe(
"CRAIG PDF",
);
expect(result.copiedFiles.sort()).toEqual([
"baldur-cv.pdf",
"craig-terminal-cv.pdf",
]);
expect(result.removedFiles).toEqual([]);
expect(
fs.readFileSync(path.join(distPdfDir, "craig-terminal-cv.pdf"), "utf8"),
).toBe("CRAIG PDF");
expect(
fs.readFileSync(path.join(distPdfDir, "baldur-cv.pdf"), "utf8"),
).toBe("BALDUR PDF");
Expand All @@ -53,6 +60,37 @@ describe("copyStaticPdfs", () => {
]);
});

// run-cv shows a static download only when its file is packaged, so a CV
// deleted from public/ must not survive in dist/pdf/ from an earlier build.
it("removes PDFs from dist/pdf that are no longer in public", () => {
const publicDir = path.join(tempRoot, "public");
const distPdfDir = path.join(tempRoot, "dist", "pdf");
const writes: string[] = [];

fs.mkdirSync(publicDir, { recursive: true });
fs.mkdirSync(distPdfDir, { recursive: true });
fs.writeFileSync(path.join(publicDir, "baldur-cv.pdf"), "BALDUR PDF");
fs.writeFileSync(path.join(distPdfDir, "nobody-cv.pdf"), "STALE");
fs.writeFileSync(path.join(distPdfDir, "keep.txt"), "not a pdf");

const result = copyStaticPdfs({
publicDir,
distPdfDir,
stdout: {
write(chunk: string) {
writes.push(chunk);
return true;
},
},
});

expect(result.removedFiles).toEqual(["nobody-cv.pdf"]);
expect(fs.existsSync(path.join(distPdfDir, "nobody-cv.pdf"))).toBe(false);
expect(fs.existsSync(path.join(distPdfDir, "baldur-cv.pdf"))).toBe(true);
expect(fs.existsSync(path.join(distPdfDir, "keep.txt"))).toBe(true);
expect(writes).toContain("Removed 1 stale PDF file(s): nobody-cv.pdf\n");
});

it("throws when the public directory is missing", () => {
const publicDir = path.join(tempRoot, "missing-public");
const distPdfDir = path.join(tempRoot, "dist", "pdf");
Expand Down
30 changes: 25 additions & 5 deletions scripts/copy-pdfs/copy-pdfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface CopyStaticPdfsOptions {

interface CopyStaticPdfsResult {
copiedFiles: string[];
removedFiles: string[];
distPdfDir: string;
}

Expand All @@ -21,6 +22,14 @@ export function getCopyPdfPaths() {
};
}

function listPdfs(dir: string): string[] {
return fs
.readdirSync(dir, { withFileTypes: true })
.filter((entry) => entry.isFile())
.map((entry) => entry.name)
.filter((name) => name.toLowerCase().endsWith(".pdf"));
}

export function copyStaticPdfs({
publicDir,
distPdfDir,
Expand All @@ -35,16 +44,21 @@ export function copyStaticPdfs({

fs.mkdirSync(resolvedDistPdfDir, { recursive: true });

const files = fs
.readdirSync(resolvedPublicDir, { withFileTypes: true })
.filter((entry) => entry.isFile())
.map((entry) => entry.name)
.filter((name) => name.toLowerCase().endsWith(".pdf"));
const files = listPdfs(resolvedPublicDir);

if (files.length === 0) {
throw new Error(`No PDF files found in ${resolvedPublicDir}`);
}

// A PDF deleted from public/ must not linger in dist/pdf/: run-cv offers a
// static download only when its file is packaged.
const removedFiles = listPdfs(resolvedDistPdfDir).filter(
(name) => !files.includes(name),
);
for (const file of removedFiles) {
fs.rmSync(path.join(resolvedDistPdfDir, file));
}

for (const file of files) {
const source = path.join(resolvedPublicDir, file);
const target = path.join(resolvedDistPdfDir, file);
Expand All @@ -54,9 +68,15 @@ export function copyStaticPdfs({
stdout.write(
`Copied ${files.length} static PDF file(s) to ${resolvedDistPdfDir}\n`,
);
if (removedFiles.length > 0) {
stdout.write(
`Removed ${removedFiles.length} stale PDF file(s): ${removedFiles.join(", ")}\n`,
);
}

return {
copiedFiles: files,
removedFiles,
distPdfDir: resolvedDistPdfDir,
};
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-cv-web/PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default defineRunCvWeb({
outDir: "docs/run-cv",
basePath: "/run-cv/run-cv/",
virtualDist: "/run-cv/dist",
cvUrl: "/run-cv/run-cv/craig-cv.pdf",
cvUrl: "/run-cv/run-cv/baldur-cv.pdf",
});
```

Expand Down
12 changes: 9 additions & 3 deletions scripts/run-cv-web/browser/gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import config from "virtual:run-cv-web-config";
import { hashHuman } from "../shared/human-hash.js";
import { focusTerminal } from "./setup.js";
import { seed } from "./shims/fs.js";
import { registerPdfs, seed } from "./shims/fs.js";
import { setSession } from "./shims/session.js";

interface Payload {
Expand Down Expand Up @@ -44,7 +44,13 @@ async function unlock(typed: string): Promise<void> {
// takes its `if (!name)` branch and prints "Please provide a human name",
// which is the wrong screen for someone who did provide one.
setSession(found?.human ?? typed, pdfBase);
if (found) seed(found.files);
if (found) boot(found);
}

/** Seeds the human's markdown and limits the download menu to PDFs they serve. */
function boot(found: Payload): void {
seed(found.files);
registerPdfs(found.pdfs);
}

/** Resolves once the program may be imported. */
Expand All @@ -61,7 +67,7 @@ export async function runGate(): Promise<void> {
if (response.ok) {
const found = (await response.json()) as Payload;
setSession(found.human, pdfBase);
seed(found.files);
boot(found);
start();
return;
}
Expand Down
32 changes: 25 additions & 7 deletions scripts/run-cv-web/browser/shims/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ export type MemFs = ReturnType<typeof createFsFromVolume>;
* ~/Downloads, then opens the copy. The PDFs aren't bundled into the page:
* report them as present and skip the copy, and the `open` shim sends the
* visitor to the site's own CV instead.
*
* With `known` given, only those basenames count — so run-cv hides a static
* download (e.g. an HR/ATS CV) that this human's payload doesn't serve.
*/
export function isPackagedPdf(file: unknown, pdfDir: string): boolean {
export function isPackagedPdf(file: unknown, pdfDir: string, known?: ReadonlySet<string>): boolean {
const value = String(file);
return value.startsWith(`${pdfDir}/`) && value.toLowerCase().endsWith(".pdf");
if (!value.startsWith(`${pdfDir}/`) || !value.toLowerCase().endsWith(".pdf")) return false;
return !known || known.has(value.slice(pdfDir.length + 1).toLowerCase());
}

export interface RunCvFsOptions {
Expand All @@ -31,37 +35,51 @@ export interface RunCvFs {
* clears), so this is additive and safe to call more than once.
*/
seed(files: Record<string, string>): void;
/**
* Narrows "packaged" to these PDF basenames. Until called, every PDF under
* `pdfDir` counts, which is the single site-wide CV mode with no gate.
*/
registerPdfs(files: readonly string[]): void;
}

export function createRunCvFs(contents: Record<string, string>, options: RunCvFsOptions): RunCvFs {
const volume = Volume.fromJSON(contents);
volume.mkdirSync(options.pdfDir, { recursive: true });
volume.mkdirSync(options.downloadsDir, { recursive: true });

let known: Set<string> | undefined;
const packaged = (file: unknown) => isPackagedPdf(file, options.pdfDir, known);

const fs = createFsFromVolume(volume);
const realExistsSync = fs.existsSync;
const realCopyFileSync = fs.copyFileSync;

fs.existsSync = ((file: unknown) =>
isPackagedPdf(file, options.pdfDir) || realExistsSync(file as string)) as typeof fs.existsSync;
packaged(file) || realExistsSync(file as string)) as typeof fs.existsSync;

fs.copyFileSync = ((source: unknown, destination: unknown, mode?: number) =>
isPackagedPdf(source, options.pdfDir)
packaged(source)
? undefined
: realCopyFileSync(source as string, destination as string, mode)) as typeof fs.copyFileSync;

return { fs, seed: (more) => volume.fromJSON(more) };
return {
fs,
seed: (more) => volume.fromJSON(more),
registerPdfs: (files) => {
known = new Set([...(known ?? []), ...files.map((file) => file.toLowerCase())]);
},
};
}

// Under the gate `files` is empty and the markdown arrives at runtime, once a
// visitor types a name that hashes to a payload. An unseeded volume is the
// wrong-name path: run-cv finds no `introduction.md` and renders ACCESS DENIED.
const { fs, seed } = createRunCvFs(files, {
const { fs, seed, registerPdfs } = createRunCvFs(files, {
pdfDir: `${config.virtualDist}/pdf`,
downloadsDir: `${config.homedir}/Downloads`,
});

export { seed };
export { registerPdfs, seed };
export default fs;
// Destructured rather than wrapped in arrows: these are overloaded signatures,
// and a `(...args) => fs.x(...args)` wrapper collapses them to the first
Expand Down
Loading
Loading