feat: publish Velum copies beside project folder
This commit is contained in:
@@ -3,7 +3,7 @@ import { basename, dirname, join } from "node:path";
|
||||
import type { PlaceholderMapping } from "../types";
|
||||
import { canonicalPerson } from "./project-review";
|
||||
import {
|
||||
createRun, digest, isRestorableDocument, listRuns, loadProjectWhitelist,
|
||||
createRun, digest, isRestorableDocument, listRuns, loadProjectWhitelist, publishProjectCopies,
|
||||
replaceProjectFilesInPlace, resolveWithin, restorePath, restoreText,
|
||||
saveProjectWhitelist, saveRun,
|
||||
} from "./velum-project";
|
||||
@@ -128,6 +128,7 @@ export async function reviseProjectRun(args: {
|
||||
Object.assign(textReplacements, plan.replacements);
|
||||
let replacementAttempted = false;
|
||||
let whitelistChanged = false;
|
||||
let publishedCopyPath: string | undefined;
|
||||
try {
|
||||
for (const file of previous.files) {
|
||||
const source = resolveWithin(join(previousDirectory, "files"), file.output);
|
||||
@@ -163,12 +164,18 @@ export async function reviseProjectRun(args: {
|
||||
await saveRun(directory, run);
|
||||
replacementAttempted = true;
|
||||
await replaceProjectFilesInPlace(previous.projectPath, directory, run.files);
|
||||
} else await saveRun(directory, run);
|
||||
} else {
|
||||
publishedCopyPath = await publishProjectCopies(run, directory);
|
||||
run.copyPath = publishedCopyPath;
|
||||
await saveRun(directory, run);
|
||||
}
|
||||
} catch (error) {
|
||||
// Keep the backup if replacing the project folder was attempted, even when
|
||||
// its own rollback reports an error.
|
||||
if (!replacementAttempted) await fs.rm(directory, { recursive: true, force: true });
|
||||
else await fs.rm(join(directory, "run.json"), { force: true });
|
||||
if (!replacementAttempted) {
|
||||
await fs.rm(directory, { recursive: true, force: true });
|
||||
if (publishedCopyPath) await fs.rm(publishedCopyPath, { recursive: true, force: true });
|
||||
} else await fs.rm(join(directory, "run.json"), { force: true });
|
||||
if (whitelistChanged) {
|
||||
try { await saveProjectWhitelist(previous.projectPath, previousWhitelist, support); }
|
||||
catch (rollbackError) {
|
||||
|
||||
@@ -32,6 +32,8 @@ export type ProjectRun = {
|
||||
commentAuthorCoverage?: boolean;
|
||||
/** Word tracked-change authors and deleted text were reviewed. */
|
||||
reviewAuthorCoverage?: boolean;
|
||||
/** Visible copy next to the source project; immutable snapshots remain in Raycast support. */
|
||||
copyPath?: string;
|
||||
};
|
||||
|
||||
const DOCUMENTS = new Set([".docx", ".xlsx", ".pptx", ".pdf"]);
|
||||
@@ -299,6 +301,39 @@ export async function saveRun(directory: string, run: ProjectRun): Promise<void>
|
||||
await fs.rename(tmp, dest);
|
||||
}
|
||||
|
||||
export function runCopiesPath(run: ProjectRun, directory: string): string {
|
||||
return run.copyPath ?? join(directory, "files");
|
||||
}
|
||||
|
||||
/** Publish only output files next to the project, without the private mapping. */
|
||||
export async function publishProjectCopies(run: ProjectRun, directory: string): Promise<string> {
|
||||
const projectPath = canonicalProjectPath(run.projectPath);
|
||||
const parent = dirname(projectPath);
|
||||
const target = join(parent, `${basename(projectPath)}-Velum-${run.id}`);
|
||||
try {
|
||||
await fs.lstat(target);
|
||||
throw new Error(`Kopienordner bereits vorhanden: ${target}`);
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
||||
}
|
||||
const staging = await fs.mkdtemp(join(parent, `.${basename(projectPath)}-Velum-`));
|
||||
try {
|
||||
for (const file of run.files) {
|
||||
const source = resolveWithin(join(directory, "files"), file.output);
|
||||
if (!(await fs.lstat(source)).isFile()) throw new Error(`Keine reguläre Ausgabedatei: ${file.output}`);
|
||||
const destination = resolveWithin(staging, file.output);
|
||||
await fs.mkdir(dirname(destination), { recursive: true, mode: 0o700 });
|
||||
await fs.copyFile(source, destination, fsConstants.COPYFILE_EXCL);
|
||||
await fs.chmod(destination, 0o600);
|
||||
}
|
||||
await fs.rename(staging, target);
|
||||
return target;
|
||||
} catch (error) {
|
||||
await fs.rm(staging, { recursive: true, force: true });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function listRuns(projectPath: string, support = environment.supportPath): Promise<Array<{
|
||||
run: ProjectRun; directory: string;
|
||||
}>> {
|
||||
|
||||
Reference in New Issue
Block a user