-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add update readme script * tweak generated text * add instruction in docs * tweak docs
- Loading branch information
1 parent
84419b3
commit 4133829
Showing
4 changed files
with
88 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ Please read our [Code of Conduct](https://github.com/ml5js/Code-of-Conduct), whi | |
|
||
Before getting started with ml5.js, review our [Code of Conduct](https://github.com/ml5js/Code-of-Conduct). There are several ways you can use the ml5.js library: | ||
|
||
<p id="latest-version"> | ||
<!-- Anchor for automatic version update script, do not remove this comment --> | ||
|
||
- You can use the latest version (1.0.2) by adding it to the head section of your HTML document: | ||
|
||
|
@@ -30,7 +30,7 @@ Before getting started with ml5.js, review our [Code of Conduct](https://github. | |
<script src="https://unpkg.com/[email protected]/dist/ml5.js"></script> | ||
``` | ||
|
||
</p data-id="latest-version"> | ||
<!-- Anchor for automatic version update script, do not remove this comment --> | ||
|
||
- If you need to use an earlier version for any reason, you can change the version number. The [previous versions of ml5.js can be found here](https://www.npmjs.com/package/ml5?activeTab=versions). You can use those previous versions by replacing `<version>` with the ml5 version of interest: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); |