forked from structurizr/puppeteer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish-static-images.js
50 lines (37 loc) · 1.49 KB
/
publish-static-images.js
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
const puppeteer = require('puppeteer');
if (process.argv.length < 6) {
console.log("Please specify a username, password, and workspace ID.");
console.log("Usage: <structurizrUrl> <username> <password> <workspaceId>")
process.exit(1);
}
const structurizrUrl = process.argv[2];
const username = process.argv[3];
const password = process.argv[4];
const workspaceId = process.argv[5];
if (!new RegExp('^[0-9]+$').test(workspaceId)) {
console.log("The workspace ID must be a non-negative integer.");
process.exit(1);
}
const url = structurizrUrl + '/workspace/' + workspaceId + '/diagram-editor';
(async () => {
const browser = await puppeteer.launch({ignoreHTTPSErrors: true, headless: true});
const page = await browser.newPage();
console.log("Signing in...");
await page.goto(structurizrUrl + '/dashboard');
await page.type('#username', username);
await page.type('#password', password);
await page.click('button[type="submit"]');
await page.waitForSelector('#searchForm');
console.log("Opening diagrams in workspace " + workspaceId + "...");
await page.goto(url);
await page.waitForXPath("//*[name()='svg']");
console.log("Regenerating static images...");
await regenerateImages(page);
process.exit(0);
})();
async function regenerateImages(page) {
await page.evaluate(() => {
return Structurizr.diagram.publishImagesToRepository();
});
await page.waitForFunction('Structurizr.diagram.publishImagesToRepositoryFinished() == true', { timeout: 1000 * 60 * 3 });
}