-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.js
More file actions
89 lines (57 loc) · 1.88 KB
/
setup.js
File metadata and controls
89 lines (57 loc) · 1.88 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const exec = require('child_process').execSync;
const fs = require('fs');
var randomGithubWebhookSecret = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
var webhookURL;
var paperkey = '';
var keybaseRepoURI = '';
var username = '';
function setupDirectory(){
var dir = './node_modules';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
exec('npm install');
}
function getParameters(){
const args = require('minimist')(process.argv.slice(2));
paperkey = args['paperkey'];
username = args['username'];
keybaseRepoURI = args['keybaseRepoURI'];
}
function replaceParameter(){
var data = fs.readFileSync('serverless.yml', 'utf8');
if(data.indexOf('REPLACE-WITH-YOUR-SECRET-HERE') >= 0){
var result = data.replace(/REPLACE-WITH-YOUR-SECRET-HERE/g, randomGithubWebhookSecret);
fs.writeFileSync('serverless.yml', result, 'utf8');
}
else{
var newData = data.split('GITHUB_WEBHOOK_SECRET: ');
newData = newData[1].split('\r');
randomGithubWebhookSecret = newData[0];
}
}
function getEndpointURL(result){
result = result.split("endpoints:");
result = result[1].split('functions');
result = result[0].split('POST - ');
result = result[1].split('\n');
webhookURL = result[0];
}
function generateWebhookURL(){
paperkey = encodeURI(paperkey);
webhookURL += `/?paperkey=${paperkey}&username=${username}&keybaseRepoURI=${keybaseRepoURI}`;
}
function main(){
console.log("Setting up directory...");
setupDirectory();
getParameters();
replaceParameter();
console.log("Deploying functions, this will take a while...");
var result = exec('serverless deploy').toString();
console.log("Generating Webhook URL");
getEndpointURL(result);
generateWebhookURL();
console.log("Random Github Webhook Secret: ", randomGithubWebhookSecret);
console.log("Github Webhook URL: ", webhookURL);
}
main();