@rettangoli/vt 0.0.1 → 0.0.2-rc1
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/package.json +1 -1
- package/src/cli/accept.js +1 -1
- package/src/cli/generate.js +1 -1
- package/src/common.js +39 -39
package/package.json
CHANGED
package/src/cli/accept.js
CHANGED
package/src/cli/generate.js
CHANGED
package/src/common.js
CHANGED
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
writeFileSync,
|
|
6
6
|
mkdirSync,
|
|
7
7
|
existsSync,
|
|
8
|
+
unlinkSync,
|
|
8
9
|
} from "fs";
|
|
9
10
|
import { join, dirname, resolve, extname } from "path";
|
|
11
|
+
import http from "http";
|
|
10
12
|
import { load as loadYaml } from "js-yaml";
|
|
11
13
|
import { Liquid } from "liquidjs";
|
|
12
14
|
import { chromium } from "playwright";
|
|
@@ -181,49 +183,47 @@ async function generateHtml(specsDir, templatePath, outputDir) {
|
|
|
181
183
|
* Start a web server to serve static files
|
|
182
184
|
*/
|
|
183
185
|
function startWebServer(artifactsDir, staticDir, port) {
|
|
184
|
-
const server =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const url = new URL(req.url);
|
|
188
|
-
let path = url.pathname;
|
|
189
|
-
|
|
190
|
-
// Default to index.html for root path
|
|
191
|
-
if (path === "/") {
|
|
192
|
-
path = "/index.html";
|
|
193
|
-
}
|
|
186
|
+
const server = http.createServer((req, res) => {
|
|
187
|
+
const url = new URL(req.url, `http://localhost:${port}`);
|
|
188
|
+
let path = url.pathname;
|
|
194
189
|
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
// Default to index.html for root path
|
|
191
|
+
if (path === "/") {
|
|
192
|
+
path = "/index.html";
|
|
193
|
+
}
|
|
197
194
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
195
|
+
// Remove leading slash for file path
|
|
196
|
+
const filePath = path.startsWith("/") ? path.slice(1) : path;
|
|
197
|
+
|
|
198
|
+
// Try to serve from artifacts directory first
|
|
199
|
+
const artifactsPath = join(artifactsDir, filePath);
|
|
200
|
+
if (existsSync(artifactsPath) && statSync(artifactsPath).isFile()) {
|
|
201
|
+
const fileContent = readFileSync(artifactsPath);
|
|
202
|
+
const contentType = getContentType(artifactsPath);
|
|
203
|
+
res.writeHead(200, { "Content-Type": contentType });
|
|
204
|
+
res.end(fileContent);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
208
|
+
// Then try to serve from static directory
|
|
209
|
+
const staticPath = join(staticDir, filePath);
|
|
210
|
+
if (existsSync(staticPath) && statSync(staticPath).isFile()) {
|
|
211
|
+
const fileContent = readFileSync(staticPath);
|
|
212
|
+
const contentType = getContentType(staticPath);
|
|
213
|
+
res.writeHead(200, { "Content-Type": contentType });
|
|
214
|
+
res.end(fileContent);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
headers: { "Content-Type": "text/plain" },
|
|
222
|
-
});
|
|
223
|
-
},
|
|
218
|
+
// If not found in either directory, return 404
|
|
219
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
220
|
+
res.end("Not Found");
|
|
224
221
|
});
|
|
225
222
|
|
|
226
|
-
|
|
223
|
+
server.listen(port, () => {
|
|
224
|
+
console.log(`Server started at http://localhost:${port}`);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
227
|
return server;
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -311,7 +311,7 @@ async function takeScreenshots(
|
|
|
311
311
|
|
|
312
312
|
// Remove temporary PNG file
|
|
313
313
|
if (existsSync(tempPngPath)) {
|
|
314
|
-
|
|
314
|
+
unlinkSync(tempPngPath);
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
// example instructions:
|
|
@@ -350,7 +350,7 @@ async function takeScreenshots(
|
|
|
350
350
|
|
|
351
351
|
// Remove temporary PNG file
|
|
352
352
|
if (existsSync(tempAdditionalPngPath)) {
|
|
353
|
-
|
|
353
|
+
unlinkSync(tempAdditionalPngPath);
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
console.log(
|