Skip to content

Commit ef7ee72

Browse files
authored
adds script to update docs ml5 versions (#666)
1 parent 465d63d commit ef7ee72

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"test-travis": "./scripts/test-travis.sh",
1919
"serve:docs": "docsify serve docs",
2020
"update:readme": "node ./scripts/updateReadme.js",
21+
"update:docs": "node ./scripts/updateDocVersions.js $oldversion",
2122
"publish:npm": "npm run build && npm publish"
2223
},
2324
"repository": {

scripts/updateDocVersions.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* USAGE
3+
* run:
4+
*```
5+
*$ oldversion=0.4.2 npm run update:docs
6+
*```
7+
*/
8+
9+
const fs = require('fs');
10+
11+
12+
// ------------------
13+
// Helper functions
14+
// ------------------
15+
function readTextFile(fpath){
16+
const readme = fs.readFileSync(fpath, 'utf8');
17+
return readme;
18+
}
19+
20+
function readPackageJson(fpath){
21+
let output = fs.readFileSync(fpath);
22+
output = JSON.parse(output);
23+
return output;
24+
}
25+
26+
function updateFileVersion(inputFilePath, regex, newUrl){
27+
const readme = readTextFile(inputFilePath);
28+
const updatedReadme = readme.replace(regex, newUrl)
29+
fs.writeFileSync(inputFilePath, updatedReadme);
30+
}
31+
32+
const oldVersion = process.env.oldversion;
33+
const ml5Version = readPackageJson('./package.json').version || 'latest';
34+
const newUrl = `https://unpkg.com/ml5@${ml5Version}/dist/ml5.min.js`;
35+
const regex = new RegExp(`https://unpkg.com/ml5@${oldVersion}/dist/ml5.min.js`, "g");
36+
37+
38+
function make(){
39+
if(!oldVersion) {
40+
console.log("!!!old version needed!!! \n oldversion=0.4.X npm run update:docs");
41+
process.exit(1);
42+
}
43+
44+
updateFileVersion('./docs/README.md', regex, newUrl);
45+
updateFileVersion('./docs/tutorials/hello-ml5.md', regex, newUrl);
46+
47+
console.log(`updated docs from version ${oldVersion} to ${ml5Version}`)
48+
}
49+
make();
50+
51+
52+
53+
54+

0 commit comments

Comments
 (0)