@@ -3,13 +3,12 @@ import rp from 'request-promise';
33import Q from 'q' ;
44import { ok } from 'assert' ;
55
6- // TODO: Change branchName if necessary
7- const branchName = 'release' ;
6+ const branchName = 'main' ;
87const 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' ;
109const clientId = process . env . GITHUB_ID ;
1110const clientSecret = process . env . GITHUB_SECRET ;
12- const editorUsername = process . env . ML5_EXAMPLES_USERNAME ;
11+ const editorUsername = process . env . ML5_LIBRARY_USERNAME ;
1312const personalAccessToken = process . env . EDITOR_API_ACCESS_TOKEN ;
1413const editorApiUrl = process . env . EDITOR_API_URL ;
1514const headers = {
@@ -18,7 +17,7 @@ const headers = {
1817
1918ok ( clientId , 'GITHUB_ID is required' ) ;
2019ok ( clientSecret , 'GITHUB_SECRET is required' ) ;
21- ok ( editorUsername , 'ML5_EXAMPLES_USERNAME is required' ) ;
20+ ok ( editorUsername , 'ML5_LIBRARY_USERNAME is required' ) ;
2221ok ( personalAccessToken , 'EDITOR_API_ACCESS_TOKEN is required' ) ;
2322ok ( editorApiUrl , 'EDITOR_API_URL is required' ) ;
2423
@@ -79,17 +78,24 @@ async function fetchFileContent(item) {
7978 options . url !== ''
8079 ) {
8180 file . content = await rp ( options ) ;
81+
8282 // NOTE: remove the URL property if there's content
8383 // Otherwise the p5 editor will try to pull from that url
8484 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+ ) ;
8591 }
8692
8793 return file ;
8894 // if it is NOT an html or js file
8995 }
9096
9197 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 } ${
9399 file . url . split ( branchName ) [ 1 ]
94100 } `;
95101 file . url = cdnRef ;
@@ -104,7 +110,7 @@ async function fetchFileContent(item) {
104110async function getCategories ( ) {
105111 try {
106112 const options = Object . assign ( { } , githubRequestOptions ) ;
107- options . url = `${ options . url } /p5js${ branchRef } ` ;
113+ options . url = `${ options . url } /examples/ p5js${ branchRef } ` ;
108114 const results = await rp ( options ) ;
109115
110116 return results ;
@@ -125,7 +131,7 @@ async function getCategoryExamples(sketchRootList) {
125131 // let options = Object.assign({url: `${requestOptions.url}/${categories.path}${branchRef}` }, requestOptions)
126132 const options = Object . assign ( { } , githubRequestOptions ) ;
127133 options . url = `${ options . url } ${ categories . path } ${ branchRef } ` ;
128- // console.log(options)
134+
129135 const sketchDirs = await rp ( options ) ;
130136
131137 try {
@@ -158,7 +164,7 @@ async function traverseSketchTree(parentObject) {
158164 if ( parentObject . type !== 'dir' ) {
159165 return output ;
160166 }
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}`
162168 const options = Object . assign ( { } , githubRequestOptions ) ;
163169 options . url = `${ options . url } ${ parentObject . path } ${ branchRef } ` ;
164170
@@ -353,7 +359,7 @@ async function createProjectsInP5User(filledProjectList, user) {
353359
354360/**
355361 * MAKE
356- * Get all the sketches from the ml5-examples repo
362+ * Get all the sketches from the ml5-library repo
357363 * Get the p5 examples
358364 * Dive down into each sketch and get all the files
359365 * Format the sketch files to be save to the db
@@ -378,7 +384,7 @@ async function make() {
378384
379385/**
380386 * 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
382388 * Get the p5 examples
383389 * Dive down into each sketch and get all the files
384390 * Format the sketch files to be save to the db
@@ -414,7 +420,7 @@ async function test() {
414420 */
415421
416422if ( process . env . NODE_ENV === 'development' ) {
417- // test()
423+ // test();
418424 make ( ) ; // replace with test() if you don't want to run all the fetch functions over and over
419425} else {
420426 make ( ) ;
0 commit comments