This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-keys.js
61 lines (54 loc) · 2.1 KB
/
make-keys.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 readline = require("readline");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var url = "https://cad.onshape.com"
const path1 = '/home/pi/Desktop/RaspberryPi-SpatialToolbox/vuforia-spatial-edge-server/addons/vuforia-spatial-robotic-addon/interfaces/Spike-Drawing/apikey/Node/config/apikey.js'
const path2 = '/home/pi/Desktop/RaspberryPi-SpatialToolbox/vuforia-spatial-edge-server/addons/vuforia-spatial-robotic-addon/interfaces/Drawing/apikey/Node/config/apikey.js'
promptUser();
function promptUser() {
rl.question("Are you using an enterprise account? (Y/N)\n", function(ent){
if (ent.toLowerCase().includes('y')) {
rl.question("What is the name of your enterprise? It comes before '.onshape.com' in the url.\n", function(enterprise){
url = "https://" + enterprise + ".onshape.com"
makeKeys(url)
})
}
else {
url = "https://cad.onshape.com"
makeKeys(url)
}
})
}
function makeKeys(url) {
rl.question("What is your access key for Onshape?\n", function(aKey){
rl.question("What is your secret key for Onshape?\n", function(sKey){
rl.question("Double check you've entered the keys correctly.\
\nWould you like to save these keys? (Y/N)\n", function(accept){
if (accept.toLowerCase().includes('y')) {
writeAPI(url, aKey, sKey)
rl.close()
}
else {
promptUser()
}
})
})
})
}
function writeAPI(url, aKey, sKey) {
var content = "var prod = {\n\t'baseUrl': '" + url + "',\n\t'accessKey': '" + aKey + "',\n\t'secretKey': '" + sKey + "',\n};\n\nmodule.exports = prod;";
try {
const data1 = fs.writeFileSync(path1, content)
const data2 = fs.writeFileSync(path2, content)
}
catch(e){
console.log(e)
}
}
rl.on('close', function(){
console.log("Thank you for entering your keys. They have been saved.\n");
process.exit(0)
})