@@ -3,13 +3,12 @@ import axios from 'axios';
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
@@ -85,14 +84,20 @@ async function fetchFileContent(item) {
8584 // NOTE: remove the URL property if there's content
8685 // Otherwise the p5 editor will try to pull from that url
8786 if ( file . content !== null ) delete file . url ;
87+
88+ // Replace localhost references with references to the currently published version.
89+ file . content = file . content . replace (
90+ / h t t p : \/ \/ l o c a l h o s t ( : [ 0 - 9 ] + ) \/ m l 5 .j s / g,
91+ 'https://unpkg.com/ml5@latest/dist/ml5.min.js'
92+ ) ;
8893 }
8994
9095 return file ;
9196 // if it is NOT an html or js file
9297 }
9398
9499 if ( file . url ) {
95- const cdnRef = `https://cdn.jsdelivr.net/gh/ml5js/ml5-examples @${ branchName } ${
100+ const cdnRef = `https://cdn.jsdelivr.net/gh/ml5js/ml5-library @${ branchName } ${
96101 file . url . split ( branchName ) [ 1 ]
97102 } `;
98103 file . url = cdnRef ;
@@ -161,7 +166,7 @@ async function traverseSketchTree(parentObject) {
161166 if ( parentObject . type !== 'dir' ) {
162167 return output ;
163168 }
164- // let options = `https://api.github.com/repos/ml5js/ml5-examples /contents/${sketches.path}${branchRef}`
169+ // let options = `https://api.github.com/repos/ml5js/ml5-library /contents/examples/p5js /${sketches.path}${branchRef}`
165170 const options = Object . assign ( { } , githubRequestOptions ) ;
166171 options . url = `${ options . url } ${ parentObject . path } ${ branchRef } ` ;
167172
@@ -366,7 +371,7 @@ async function createProjectsInP5User(filledProjectList, user) {
366371
367372/**
368373 * MAKE
369- * Get all the sketches from the ml5-examples repo
374+ * Get all the sketches from the ml5-library repo
370375 * Get the p5 examples
371376 * Dive down into each sketch and get all the files
372377 * Format the sketch files to be save to the db
@@ -391,7 +396,7 @@ async function make() {
391396
392397/**
393398 * TEST - same as make except reads from file for testing purposes
394- * Get all the sketches from the ml5-examples repo
399+ * Get all the sketches from the ml5-library repo
395400 * Get the p5 examples
396401 * Dive down into each sketch and get all the files
397402 * Format the sketch files to be save to the db
@@ -427,7 +432,7 @@ async function test() {
427432 */
428433
429434if ( process . env . NODE_ENV === 'development' ) {
430- // test()
435+ // test();
431436 make ( ) ; // replace with test() if you don't want to run all the fetch functions over and over
432437} else {
433438 make ( ) ;
0 commit comments