Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/exportHandler/exportHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { exec } from "child_process";
import { promisify } from "util";
import { removeHtmlTags, generateSrtData } from "./subtitleUtils";
import { generateVttData } from "./vttUtils";
import { zipDirectory } from "./utils/zipUtils";

// import { exportRtfWithPandoc } from "../../webviews/codex-webviews/src/NewSourceUploader/importers/rtf/pandocNodeBridge";

Expand Down Expand Up @@ -215,6 +216,7 @@ export enum CodexExportFormat {
export interface ExportOptions {
skipValidation?: boolean;
removeIds?: boolean;
zipOutput?: boolean;
includeAudio?: boolean;
includeTimestamps?: boolean;
}
Expand Down Expand Up @@ -1739,6 +1741,7 @@ export async function exportCodexContent(
filesToExport: string[],
options?: ExportOptions
) {
const shouldZip = options?.zipOutput ?? false;
const includeAudio = options?.includeAudio === true && format !== CodexExportFormat.AUDIO;
const isMulti = includeAudio;

Expand All @@ -1751,7 +1754,7 @@ export async function exportCodexContent(
const baseName = `${projectName}-${formatLabel}-${dateStamp}`;
let candidate = path.join(userSelectedPath, baseName);
let suffix = 1;
while (fs.existsSync(candidate)) {
while (fs.existsSync(candidate) || fs.existsSync(`${candidate}.zip`)) {
candidate = path.join(userSelectedPath, `${baseName}-${suffix}`);
suffix++;
}
Expand Down Expand Up @@ -1829,6 +1832,13 @@ export async function exportCodexContent(
debug("Failed to generate NOTICE.txt files:", e);
}
}

if (shouldZip) {
const zipPath = `${wrapperPath}.zip`;
await zipDirectory(wrapperPath, zipPath);
fs.rmSync(wrapperPath, { recursive: true, force: true });
vscode.window.showInformationMessage(`Exported to ${zipPath}`);
}
}

async function generateMissingContentNotices(
Expand Down
17 changes: 17 additions & 0 deletions src/exportHandler/utils/zipUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import archiver from "archiver";
import * as fs from "fs";
import { basename } from "path";

export const zipDirectory = (sourceDir: string, destZipPath: string): Promise<void> => {
return new Promise((resolve, reject) => {
const output = fs.createWriteStream(destZipPath);
const archive = archiver("zip", { zlib: { level: 9 } });

output.on("close", resolve);
archive.on("error", reject);

archive.pipe(output);
archive.directory(sourceDir, basename(sourceDir));
archive.finalize();
});
};
8 changes: 7 additions & 1 deletion src/projectManager/projectExportView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,12 @@ function getWebviewContent(
Select Location
</button>
</div>

<div id="exportOutputOptions" style="margin-top: 16px;">
<div style="display: flex; align-items: center;">
<input type="checkbox" id="zipOutput">
<label for="zipOutput" style="margin-left: 8px;">Zip output</label>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -1466,6 +1471,7 @@ function getWebviewContent(
options.includeAudio = true;
options.includeTimestamps = selectedAudioMode === 'audio-timestamps';
}
if (document.getElementById('zipOutput')?.checked) options.zipOutput = true;
vscode.postMessage({
command: 'export',
format: formatToSend,
Expand Down
Loading