-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-users.js
39 lines (32 loc) · 935 Bytes
/
import-users.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
const puppeteer = require('puppeteer');
const {
promptCredential,
handleError,
validateFiletype,
logInWorkD,
importWorkDUsers,
openUserManagementPage,
getArguments
} = require('./common/functions');
(async () => {
let browser, page;
try {
const args = getArguments(1);
const inputFilePath = args[0];
validateFiletype(inputFilePath, ['csv']);
const outputFilePath = inputFilePath.replace(/\.csv$/gi,'_imported.csv');
console.log('info: reading CSV file');
const credential = await promptCredential();
browser = await puppeteer.launch();
page = await browser.newPage();
await logInWorkD(page, credential.username, credential.password);
await openUserManagementPage(page);
await importWorkDUsers(page, inputFilePath, outputFilePath);
} catch (error) {
handleError(error);
} finally {
if (browser != null) {
await browser.close();
}
}
})();