This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
buildWebtaskJson.js
70 lines (55 loc) · 1.73 KB
/
buildWebtaskJson.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
62
63
64
65
66
67
68
69
70
const fs = require('fs');
const { logTypes: getLogTypes } = require('auth0-log-extension-tools');
const yargs = require('yargs');
const argv = yargs
.option('provider', {
alias: 'p',
default: null
})
.argv;
(function () {
const provider = argv.provider;
if (!provider) {
throw new Error('Cannot build webtask.json, provider not set.');
}
updateLogTypes();
const commonWT = JSON.parse(fs.readFileSync('./webtask-templates/common.json'));
const providerWT = JSON.parse(fs.readFileSync(`./webtask-templates/${provider}.json`));
const secrets = Object.assign({}, commonWT.secrets, providerWT.secrets);
Object.keys(secrets).forEach(key => {
if (secrets[key] === null) delete secrets[key];
});
const wtJson = Object.assign({}, commonWT, providerWT, { secrets });
try {
const content = JSON.stringify(wtJson, null, ' ');
fs.writeFile('./webtask.json', content + '\n', (err) => {
if (err) {
console.error(err);
} else {
console.info(`Successfully generated webtask.json for ${provider} provider`);
}
return null;
});
} catch (e) {
console.error(e);
return null;
}
}());
function updateLogTypes () {
const options = [ { text: '', value: '-' }];
for (let key in getLogTypes) {
if (getLogTypes[key] && getLogTypes[key].name) {
options.push({ text: getLogTypes[key].name, value: key });
}
}
try {
const wtJson = JSON.parse(fs.readFileSync('./webtask-templates/common.json'));
wtJson.secrets.LOG_TYPES.options = options;
const content = JSON.stringify(wtJson, null, ' ');
fs.writeFileSync('./webtask-templates/common.json', content + '\n');
return null;
} catch (e) {
console.error(e);
return null;
}
}