@@ -3,13 +3,12 @@ import rp from 'request-promise';
3
3
import Q from 'q' ;
4
4
import { ok } from 'assert' ;
5
5
6
- // TODO: Change branchName if necessary
7
- const branchName = 'release' ;
6
+ const branchName = 'main' ;
8
7
const branchRef = `?ref=${ branchName } ` ;
9
- const baseUrl = 'https://api.github.com/repos/ml5js/ml5-examples /contents' ;
8
+ const baseUrl = 'https://api.github.com/repos/ml5js/ml5-library /contents' ;
10
9
const clientId = process . env . GITHUB_ID ;
11
10
const clientSecret = process . env . GITHUB_SECRET ;
12
- const editorUsername = process . env . ML5_EXAMPLES_USERNAME ;
11
+ const editorUsername = process . env . ML5_LIBRARY_USERNAME ;
13
12
const personalAccessToken = process . env . EDITOR_API_ACCESS_TOKEN ;
14
13
const editorApiUrl = process . env . EDITOR_API_URL ;
15
14
const headers = {
@@ -18,7 +17,7 @@ const headers = {
18
17
19
18
ok ( clientId , 'GITHUB_ID is required' ) ;
20
19
ok ( clientSecret , 'GITHUB_SECRET is required' ) ;
21
- ok ( editorUsername , 'ML5_EXAMPLES_USERNAME is required' ) ;
20
+ ok ( editorUsername , 'ML5_LIBRARY_USERNAME is required' ) ;
22
21
ok ( personalAccessToken , 'EDITOR_API_ACCESS_TOKEN is required' ) ;
23
22
ok ( editorApiUrl , 'EDITOR_API_URL is required' ) ;
24
23
@@ -79,17 +78,24 @@ async function fetchFileContent(item) {
79
78
options . url !== ''
80
79
) {
81
80
file . content = await rp ( options ) ;
81
+
82
82
// NOTE: remove the URL property if there's content
83
83
// Otherwise the p5 editor will try to pull from that url
84
84
if ( file . content !== null ) delete file . url ;
85
+
86
+ // Replace localhost references with references to the currently published version.
87
+ file . content = file . content . replace (
88
+ / h t t p : \/ \/ l o c a l h o s t ( : [ 0 - 9 ] + ) \/ m l 5 .j s / g,
89
+ 'https://unpkg.com/ml5@latest/dist/ml5.min.js'
90
+ ) ;
85
91
}
86
92
87
93
return file ;
88
94
// if it is NOT an html or js file
89
95
}
90
96
91
97
if ( file . url ) {
92
- const cdnRef = `https://cdn.jsdelivr.net/gh/ml5js/ml5-examples @${ branchName } ${
98
+ const cdnRef = `https://cdn.jsdelivr.net/gh/ml5js/ml5-library @${ branchName } ${
93
99
file . url . split ( branchName ) [ 1 ]
94
100
} `;
95
101
file . url = cdnRef ;
@@ -104,7 +110,7 @@ async function fetchFileContent(item) {
104
110
async function getCategories ( ) {
105
111
try {
106
112
const options = Object . assign ( { } , githubRequestOptions ) ;
107
- options . url = `${ options . url } /p5js${ branchRef } ` ;
113
+ options . url = `${ options . url } /examples/ p5js${ branchRef } ` ;
108
114
const results = await rp ( options ) ;
109
115
110
116
return results ;
@@ -125,7 +131,7 @@ async function getCategoryExamples(sketchRootList) {
125
131
// let options = Object.assign({url: `${requestOptions.url}/${categories.path}${branchRef}` }, requestOptions)
126
132
const options = Object . assign ( { } , githubRequestOptions ) ;
127
133
options . url = `${ options . url } ${ categories . path } ${ branchRef } ` ;
128
- // console.log(options)
134
+
129
135
const sketchDirs = await rp ( options ) ;
130
136
131
137
try {
@@ -158,7 +164,7 @@ async function traverseSketchTree(parentObject) {
158
164
if ( parentObject . type !== 'dir' ) {
159
165
return output ;
160
166
}
161
- // let options = `https://api.github.com/repos/ml5js/ml5-examples /contents/${sketches.path}${branchRef}`
167
+ // let options = `https://api.github.com/repos/ml5js/ml5-library /contents/examples/p5js /${sketches.path}${branchRef}`
162
168
const options = Object . assign ( { } , githubRequestOptions ) ;
163
169
options . url = `${ options . url } ${ parentObject . path } ${ branchRef } ` ;
164
170
@@ -353,7 +359,7 @@ async function createProjectsInP5User(filledProjectList, user) {
353
359
354
360
/**
355
361
* MAKE
356
- * Get all the sketches from the ml5-examples repo
362
+ * Get all the sketches from the ml5-library repo
357
363
* Get the p5 examples
358
364
* Dive down into each sketch and get all the files
359
365
* Format the sketch files to be save to the db
@@ -378,7 +384,7 @@ async function make() {
378
384
379
385
/**
380
386
* TEST - same as make except reads from file for testing purposes
381
- * Get all the sketches from the ml5-examples repo
387
+ * Get all the sketches from the ml5-library repo
382
388
* Get the p5 examples
383
389
* Dive down into each sketch and get all the files
384
390
* Format the sketch files to be save to the db
@@ -414,7 +420,7 @@ async function test() {
414
420
*/
415
421
416
422
if ( process . env . NODE_ENV === 'development' ) {
417
- // test()
423
+ // test();
418
424
make ( ) ; // replace with test() if you don't want to run all the fetch functions over and over
419
425
} else {
420
426
make ( ) ;
0 commit comments