-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
export-documentation.js
61 lines (48 loc) · 1.72 KB
/
export-documentation.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
51
52
53
54
55
56
57
58
59
60
61
const puppeteer = require('puppeteer');
const fs = require('fs');
const IGNORE_HTTPS_ERRORS = true;
const HEADLESS = true;
if (process.argv.length < 3) {
console.log("Usage: <structurizrUrl> [username] [password]")
process.exit(1);
}
const url = process.argv[2];
var username;
var password;
if (process.argv.length > 2) {
username = process.argv[3];
password = process.argv[4];
}
(async () => {
const browser = await puppeteer.launch({ignoreHTTPSErrors: IGNORE_HTTPS_ERRORS, headless: HEADLESS});
const page = await browser.newPage();
if (username !== undefined && password !== undefined) {
// sign in
const parts = url.split('://');
const signinUrl = parts[0] + '://' + parts[1].substring(0, parts[1].indexOf('/')) + '/dashboard';
console.log(' - Signing in via ' + signinUrl);
await page.goto(signinUrl, { waitUntil: 'networkidle2' });
await page.type('#username', username);
await page.type('#password', password);
await page.keyboard.press('Enter');
await page.waitForSelector('div#dashboard');
}
// visit the documentation page
console.log(" - Opening " + url);
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForFunction('structurizr.scripting && structurizr.scripting.isDocumentationRendered() === true');
await page.exposeFunction('saveHtml', (content) => {
const filename = 'documentation.html';
console.log(" - Writing " + filename);
fs.writeFile(filename, content, 'utf8', function (err) {
if (err) throw err;
});
console.log(" - Finished");
browser.close();
});
await page.evaluate(() => {
return structurizr.scripting.exportDocumentationToOfflineHtmlPage(function(html) {
saveHtml(html);
});
});
})();