Skip to content

Commit cec6fe5

Browse files
saustinposcarlevin
authored andcommitted
show build progress for all targets in live preview
PDF, braille, and EPUB auto-build now shows progress in the PreTeXt output channel (matching the HTML build behavior).
1 parent 5e4b8f6 commit cec6fe5

1 file changed

Lines changed: 41 additions & 12 deletions

File tree

packages/vscode-extension/src/livePreview.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,38 @@ async function openFileExternally(
112112

113113
if (!outputFile) {
114114
pretextOutputChannel.appendLine(
115-
`[External Preview] No ${extension} file found, running build...`,
115+
`[External Preview] No ${extension} file found, building first...`,
116116
);
117-
const buildResult = await new Promise<boolean>((resolve) => {
117+
pretextOutputChannel.show();
118+
utils.updateStatusBarItem(ptxSBItem, "building");
119+
120+
await new Promise<boolean>((resolve) => {
118121
const fullCommand = cli.cmd() + " build " + target;
122+
pretextOutputChannel.appendLine(`[External Preview] Running: ${fullCommand}`);
119123
const buildProcess = spawn(fullCommand, [], {
120124
cwd: projectPath,
121125
shell: true,
122126
});
123-
buildProcess.on("close", (code) => resolve(code === 0));
127+
buildProcess.stdout?.on("data", (data: Buffer) => {
128+
const text = utils.stripColorCodes(data.toString());
129+
if (text.trim()) { pretextOutputChannel.appendLine(text); }
130+
});
131+
buildProcess.stderr?.on("data", (data: Buffer) => {
132+
const text = utils.stripColorCodes(data.toString());
133+
if (text.trim()) { pretextOutputChannel.appendLine(text); }
134+
});
135+
buildProcess.on("close", (code) => {
136+
pretextOutputChannel.appendLine(`[External Preview] Build exited with code ${code}`);
137+
resolve(true);
138+
});
124139
});
125140

126-
if (buildResult) {
127-
try {
128-
const files = fs.readdirSync(outputDir);
129-
outputFile = files.find((f) => f.endsWith(extension));
130-
} catch {
131-
// still not found
132-
}
141+
// Check if the build produced the file
142+
try {
143+
const files = fs.readdirSync(outputDir);
144+
outputFile = files.find((f) => f.endsWith(extension));
145+
} catch {
146+
// still not found
133147
}
134148

135149
if (!outputFile) {
@@ -170,15 +184,30 @@ async function openFilePreview(
170184

171185
if (!outputFile) {
172186
pretextOutputChannel.appendLine(
173-
`[File Preview] No ${extension} file found, running build...`,
187+
`[File Preview] No ${extension} file found, building first...`,
174188
);
189+
pretextOutputChannel.show();
190+
utils.updateStatusBarItem(ptxSBItem, "building");
191+
175192
const buildResult = await new Promise<boolean>((resolve) => {
176193
const fullCommand = cli.cmd() + " build " + target;
194+
pretextOutputChannel.appendLine(`[File Preview] Running: ${fullCommand}`);
177195
const buildProcess = spawn(fullCommand, [], {
178196
cwd: projectPath,
179197
shell: true,
180198
});
181-
buildProcess.on("close", (code) => resolve(code === 0));
199+
buildProcess.stdout?.on("data", (data: Buffer) => {
200+
const text = utils.stripColorCodes(data.toString());
201+
if (text.trim()) { pretextOutputChannel.appendLine(text); }
202+
});
203+
buildProcess.stderr?.on("data", (data: Buffer) => {
204+
const text = utils.stripColorCodes(data.toString());
205+
if (text.trim()) { pretextOutputChannel.appendLine(text); }
206+
});
207+
buildProcess.on("close", (code) => {
208+
pretextOutputChannel.appendLine(`[File Preview] Build exited with code ${code}`);
209+
resolve(true);
210+
});
182211
});
183212

184213
if (buildResult) {

0 commit comments

Comments
 (0)