-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-types.format.js
49 lines (44 loc) · 1.29 KB
/
event-types.format.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
const readline = require('readline');
const fs = require('fs');
const filePath = '/libs/stripe/src/lib/webhook/event-types.enum.ts';
const file = fs.readFileSync(filePath);
const data = file.toString();
const inputLines = data.split('\n');
const outputLines = [inputLines[0]];
for(let i = 1; i < inputLines.length; i++) {
const inputLIne = inputLines[i].trim();
if (inputLIne === '}') {
outputLines.push(inputLIne);
continue;
}
if (inputLIne.length === 0) {
outputLines.push(`\t${inputLIne}`);
continue;
}
if (inputLIne.startsWith('Occurs') || inputLIne.startsWith('Represents')) {
const tmp = outputLines.pop();
outputLines.push('\t/**');
outputLines.push(`\t* ${inputLIne}`);
outputLines.push('\t*/');
outputLines.push(tmp);
continue;
}
const chars = inputLIne.split('');
const outputLine = [];
for(let j = 0; j < chars.length; j++) {
const char = chars[j];
const pChar = chars[j-1];
if (char === '_' || char === '.') {
continue;
}
if (pChar === '_' || pChar === '.') {
outputLine.push(char.toUpperCase());
} else {
outputLine.push(char);
}
}
outputLines.push(`\t${outputLine.join('')} = '${inputLIne}',`);
}
const outputData = outputLines.join('\n');
fs.writeFileSync(filePath, outputData);
console.log();