File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 18
18
"test-travis" : " ./scripts/test-travis.sh" ,
19
19
"serve:docs" : " docsify serve docs" ,
20
20
"update:readme" : " node ./scripts/updateReadme.js" ,
21
+ "update:docs" : " node ./scripts/updateDocVersions.js $oldversion" ,
21
22
"publish:npm" : " npm run build && npm publish"
22
23
},
23
24
"repository" : {
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments