-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.ts
77 lines (73 loc) · 2.49 KB
/
pdf.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Command, Option } from "commander";
import {
accessKeyOption,
branchOption,
buildIdOption,
buildNameOption,
concurrencyOption,
customIdOption,
defaultBranchOption,
projectOption,
regionOption,
suiteNameOption,
usernameOption,
} from "./options.js";
import { PdfCommandHandler, PdfCommandParams } from "../app/pdf-handler.js";
import { EOL } from "os";
import { VisualSnapshotsApi } from "../api/visual-snapshots-api.js";
import { initializeVisualApi } from "../api/visual-client.js";
import { WorkerPoolPdfSnapshotUploader } from "../app/worker/worker-pool-pdf-snapshot-uploader.js";
import { LibPdfFileLoader } from "../app/pdf-file-loader.js";
export const testNameOption = new Option(
"--test-name <test-name>",
"The name of the test you would like to appear in the Sauce Visual dashboard." +
EOL +
"Supports the following parameters: {filename}"
);
export const snapshotNameOption = new Option(
"--snapshot-name <snapshot-name>",
"The name of the snapshot you would like to appear in the Sauce Visual dashboard." +
EOL +
" Supports the following parameters: {filename}, {page}"
);
export const pdfCommand = (clientVersion: string) => {
return new Command()
.name("pdf")
.description("Create visual snapshots for each page of a PDF file")
.argument(
"<paths, globs, dirs...>",
"Paths to PDF files, glob patterns, or paths to directories containing PDF files."
)
.addOption(usernameOption)
.addOption(accessKeyOption)
.addOption(regionOption)
.addOption(buildNameOption)
.addOption(branchOption)
.addOption(defaultBranchOption)
.addOption(projectOption)
.addOption(buildIdOption)
.addOption(customIdOption)
.addOption(suiteNameOption)
.addOption(testNameOption)
.addOption(snapshotNameOption)
.addOption(concurrencyOption)
.action((globsOrDirs: string[], params: PdfCommandParams) => {
const visualSnapshotsApi = new VisualSnapshotsApi(
initializeVisualApi(params, clientVersion)
);
const pdfSnapshotUploader = new WorkerPoolPdfSnapshotUploader(
new LibPdfFileLoader(),
{
maxWorkers: params.concurrency,
}
);
new PdfCommandHandler(visualSnapshotsApi, pdfSnapshotUploader)
.handle(globsOrDirs, params)
.then(() => {
console.info("Successfully created PDF snapshots.");
})
.catch((err) => {
console.error(`At least one PDF snapshot creation failed: ${err}.`);
});
});
};