-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.js
More file actions
108 lines (94 loc) · 2.83 KB
/
functions.js
File metadata and controls
108 lines (94 loc) · 2.83 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const chalk = require("chalk");
const execa = require("execa");
var fs = require('fs');
var Table = require('cli-table');
const inquirer = require('inquirer')
module.exports = {
saveinput: async (input) => {},
displayinput: async (input) => {},
getInput: async () => {
const questions = [{
name: "forum",
type: "input",
message: "Enter the " + chalk.white.bold("Discourse Forum") + " you want to run SourceCred against:",
}
];
return inquirer.prompt(questions);
},
startBackend: async () => {
try {
await execa.command("yarn backend");
} catch (error) {
console.error();
}
},
runSC: async forum => {
try {
await execa.command(`node bin/sourcecred.js discourse https://${forum.forum}`);
} catch (error) {
console.error(error);
return
}
},
calcCred: async forum => {
try {
await execa.command(`node bin/sourcecred.js scores ${forum.forum} > CRED.json`, {
shell: true
});
} catch (error) {
console.error();
}
},
processCSV: async () => {
try {
const data = require(process.cwd() + '/CRED.json')
cred = []
data[1].users.map((element) => {
cred.push([element.address[4], element.totalCred])
})
var jsonString = JSON.stringify(cred);
fs.writeFile('./toMint.json', jsonString, (error) => {
if (error) {
console.log(error)
}
console.log("Saved toMint.json")
})
const fields = ['Address', 'Grain'];
const opts = {
fields
};
// SAVE CSV LOGIC
const csvContent = cred.map(e => e.join(",")).join("\n");
fs.writeFile('./toMint.csv', csvContent, (error) => {
if (error) {
console.log(error)
}
console.log("Saved toMint.csv")
})
// return Promise.resolve(data);
// print the cred as table
var table = new Table({
head: [chalk.blueBright.bold('Address'), chalk.blueBright.bold('Ammount')],
colWidths: [60, 30]
});
cred.map((row) => {
table.push(row)
})
return table.toString()
} catch (error) {
console.log(error)
}
return Promise.resolve("data");
},
mintGrain: async () => {
return Promise.resolve("data");
},
userInput: async () => {
const questions = [{
name: "mint",
type: "confirm",
message: chalk.bold("Mint Grain?"),
default: true,
}, ];
},
};