Passed
Push — main ( ba3013...bfeaac )
by Cataldo
57s queued 12s
created

scripts/update-docs.js   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 39
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 28
mnd 2
bc 2
fnc 0
dl 0
loc 39
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
var fs = require("fs");
2
var PKG = require("../package.json");
3
var buffer = fs.readFileSync("./CHANGELOG.md");
4
5
var fileContent = buffer.toString();
6
7
var splitted = fileContent.split("## Versions");
8
var versionAlreadyPresent = splitted[1]
9
  .split("[")[1]
10
  .startsWith(PKG.version.toString());
11
12
var resVersions = "";
13
14
if (!versionAlreadyPresent) {
15
  resVersions =
16
    "-   [" + PKG.version + "](#" + PKG.version + ")\n" + splitted[1];
17
} else {
18
  resVersions = splitted[1];
19
}
20
21
var splittedChanges = resVersions.split("## Changes");
22
23
var resChanges = "";
24
25
if (!versionAlreadyPresent) {
26
  resChanges =
27
    "\n<br>\n\n### " + PKG.version + "-test\n-   \n\n" + splittedChanges[1];
28
} else {
29
  resChanges = splittedChanges[1];
30
}
31
32
fs.writeFileSync(
33
  "./CHANGELOG.md",
34
  splitted[0] +
35
    "## Versions" +
36
    splittedChanges[0] +
37
    "## Changes" +
38
    resChanges
39
);
40