-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathupdateReadme.js
50 lines (38 loc) · 1.72 KB
/
updateReadme.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
/**
* @file This script updates the version number in the README file.
* The script reads the version number from the package.json file and updates the README file with the new version number.
*/
const ml5Version = require("../package.json").version;
const fs = require("fs");
const readmePath = "README.md";
/**
* Generates the section of text with new version number to be inserted into the README.
* @param {string} newVersionNumber - The new version number to be inserted into the README.
* @returns {string} The new section of text to be inserted into the README.
*/
function makeNewVersionString(newVersionNumber) {
const newVersionString = `<!-- Anchor for automatic version update script, do not remove this comment -->
- You can use the latest version (${newVersionNumber}) by adding it to the head section of your HTML document:
**v${newVersionNumber}**
\`\`\`html
<script src="https://unpkg.com/ml5@${newVersionNumber}/dist/ml5.js"></script>
\`\`\`
<!-- Anchor for automatic version update script, do not remove this comment -->`;
return newVersionString;
}
/**
* Updates the README version number to the new version number.
* Point of entry for the script.
*/
function main() {
const newVersionString = makeNewVersionString(ml5Version);
console.log(`Updating README version number to ${ml5Version}...`);
const readme = fs.readFileSync(readmePath, "utf8");
const newReadme = readme.replace(
/<!-- Anchor for automatic version update script, do not remove this comment -->([\s\S]*)<!-- Anchor for automatic version update script, do not remove this comment -->/g,
newVersionString
);
fs.writeFileSync(readmePath, newReadme);
console.log("🟢 README version number update successful!");
}
main();