forked from cullenjett/quickbase-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-config.js
More file actions
59 lines (54 loc) · 1.94 KB
/
generate-config.js
File metadata and controls
59 lines (54 loc) · 1.94 KB
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
let fs = require('fs');
let template = `module.exports = {
username: "{{username}}",
password: "{{password}}",
realm: "{{realm}}",
dbid: "{{dbid}}",
appToken: "{{appToken}}",
userToken: "{{userToken}}",
appName: "{{appName}}",
authenticate_hours: "{{authenticate_hours}}",
}`;
const generateConfig = answers => {
return new Promise((resolve, reject) => {
for (let i in answers) {
if (i == 'password' && answers[i] == '') {
template = template.replace(
/password: \"\{\{password\}\}\",/,
`//leave commented out to use QUICKBASE_CLI_PASSWORD env variable\n\t//password:`
);
} else if (i == 'username' && answers[i] == '') {
template = template.replace(
/username: \"\{\{username\}\}\",/,
`//leave commented out to use QUICKBASE_CLI_USERNAME env variable\n\t//username:`
);
} else if (i == 'appToken' && answers[i] == '') {
template = template.replace(
/appToken: \"\{\{appToken\}\}\",/,
`//leave commented out to use QUICKBASE_CLI_APPTOKEN env variable\n\t//appToken:`
);
} else if (i == 'userToken' && answers[i] == '') {
template = template.replace(
/userToken: \"\{\{userToken\}\}\",/,
`//leave commented out to use QUICKBASE_CLI_USERTOKEN env variable\n\t//userToken:`
);
} else if (i == 'authenticate_hours' && answers[i] == '') {
const authenticate_hours = parseInt(answers[i]) || 1
template = template.replace(
/authenticate_hours: \"\{\{authenticate_hours\}\}\",/, 'authenticate_hours: "'+authenticate_hours+'"'
);
} else {
template = template.replace(new RegExp(`{{${i}}}`, 'g'), answers[i]);
}
}
console.log(template);
fs.writeFile('./quickbase-cli.config.js', template, err => {
if (err) {
reject(err);
} else {
resolve(err);
}
});
});
};
module.exports = generateConfig;