From bfa5ccdcbced62d4a6ec36bd546c63594fe1c1d9 Mon Sep 17 00:00:00 2001 From: Bomani Oseni McClendon Date: Fri, 12 Feb 2021 14:12:14 -0500 Subject: [PATCH 1/3] Change ENV key name to specify ml5-library usage --- .env.example | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index a1db1ecb8f..0f92822d16 100644 --- a/.env.example +++ b/.env.example @@ -10,9 +10,9 @@ EXAMPLE_USER_PASSWORD=hellop5js GG_EXAMPLES_USERNAME=generativedesign GG_EXAMPLES_EMAIL=benedikt.gross@generative-gestaltung.de GG_EXAMPLES_PASS=generativedesign -ML5_EXAMPLES_USERNAME=ml5 -ML5_EXAMPLES_EMAIL=examples@ml5js.org -ML5_EXAMPLES_PASS=helloml5 +ML5_LIBRARY_USERNAME=ml5 +ML5_LIBRARY_EMAIL=examples@ml5js.org +ML5_LIBRARY_PASS=helloml5 GITHUB_ID= GITHUB_SECRET= GOOGLE_ID= (use google+ api) From 9e7320abc2e54dcf55f0ff01a75288268c77b0e7 Mon Sep 17 00:00:00 2001 From: Bomani Oseni McClendon Date: Fri, 12 Feb 2021 15:25:28 -0500 Subject: [PATCH 2/3] Update examples script to support uploading examples in the ml5-library repo --- server/scripts/examples-ml5.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/server/scripts/examples-ml5.js b/server/scripts/examples-ml5.js index 801f25501c..a2acbb5d15 100644 --- a/server/scripts/examples-ml5.js +++ b/server/scripts/examples-ml5.js @@ -3,13 +3,12 @@ import rp from 'request-promise'; import Q from 'q'; import { ok } from 'assert'; -// TODO: Change branchName if necessary -const branchName = 'release'; +const branchName = 'main'; const branchRef = `?ref=${branchName}`; -const baseUrl = 'https://api.github.com/repos/ml5js/ml5-examples/contents'; +const baseUrl = 'https://api.github.com/repos/ml5js/ml5-library/contents'; const clientId = process.env.GITHUB_ID; const clientSecret = process.env.GITHUB_SECRET; -const editorUsername = process.env.ML5_EXAMPLES_USERNAME; +const editorUsername = process.env.ML5_LIBRARY_USERNAME; const personalAccessToken = process.env.EDITOR_API_ACCESS_TOKEN; const editorApiUrl = process.env.EDITOR_API_URL; const headers = { @@ -18,7 +17,7 @@ const headers = { ok(clientId, 'GITHUB_ID is required'); ok(clientSecret, 'GITHUB_SECRET is required'); -ok(editorUsername, 'ML5_EXAMPLES_USERNAME is required'); +ok(editorUsername, 'ML5_LIBRARY_USERNAME is required'); ok(personalAccessToken, 'EDITOR_API_ACCESS_TOKEN is required'); ok(editorApiUrl, 'EDITOR_API_URL is required'); @@ -89,7 +88,7 @@ async function fetchFileContent(item) { } if (file.url) { - const cdnRef = `https://cdn.jsdelivr.net/gh/ml5js/ml5-examples@${branchName}${ + const cdnRef = `https://cdn.jsdelivr.net/gh/ml5js/ml5-library@${branchName}${ file.url.split(branchName)[1] }`; file.url = cdnRef; @@ -104,7 +103,7 @@ async function fetchFileContent(item) { async function getCategories() { try { const options = Object.assign({}, githubRequestOptions); - options.url = `${options.url}/p5js${branchRef}`; + options.url = `${options.url}/examples/p5js${branchRef}`; const results = await rp(options); return results; @@ -158,7 +157,7 @@ async function traverseSketchTree(parentObject) { if (parentObject.type !== 'dir') { return output; } - // let options = `https://api.github.com/repos/ml5js/ml5-examples/contents/${sketches.path}${branchRef}` + // let options = `https://api.github.com/repos/ml5js/ml5-library/contents/examples/p5js/${sketches.path}${branchRef}` const options = Object.assign({}, githubRequestOptions); options.url = `${options.url}${parentObject.path}${branchRef}`; @@ -353,7 +352,7 @@ async function createProjectsInP5User(filledProjectList, user) { /** * MAKE - * Get all the sketches from the ml5-examples repo + * Get all the sketches from the ml5-library repo * Get the p5 examples * Dive down into each sketch and get all the files * Format the sketch files to be save to the db @@ -378,7 +377,7 @@ async function make() { /** * TEST - same as make except reads from file for testing purposes - * Get all the sketches from the ml5-examples repo + * Get all the sketches from the ml5-library repo * Get the p5 examples * Dive down into each sketch and get all the files * Format the sketch files to be save to the db @@ -414,7 +413,7 @@ async function test() { */ if (process.env.NODE_ENV === 'development') { - // test() + // test(); make(); // replace with test() if you don't want to run all the fetch functions over and over } else { make(); From bf49b04a49e3b59fc8967eb65bac5efd69f8ff46 Mon Sep 17 00:00:00 2001 From: Bomani Oseni McClendon Date: Fri, 12 Feb 2021 16:07:12 -0500 Subject: [PATCH 3/3] Add a regex replacement to use published version of the library in examples --- server/scripts/examples-ml5.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/scripts/examples-ml5.js b/server/scripts/examples-ml5.js index a2acbb5d15..6f4249da69 100644 --- a/server/scripts/examples-ml5.js +++ b/server/scripts/examples-ml5.js @@ -78,9 +78,16 @@ async function fetchFileContent(item) { options.url !== '' ) { file.content = await rp(options); + // NOTE: remove the URL property if there's content // Otherwise the p5 editor will try to pull from that url if (file.content !== null) delete file.url; + + // Replace localhost references with references to the currently published version. + file.content = file.content.replace( + /http:\/\/localhost(:[0-9]+)\/ml5.js/g, + 'https://unpkg.com/ml5@latest/dist/ml5.min.js' + ); } return file; @@ -124,7 +131,7 @@ async function getCategoryExamples(sketchRootList) { // let options = Object.assign({url: `${requestOptions.url}/${categories.path}${branchRef}`}, requestOptions) const options = Object.assign({}, githubRequestOptions); options.url = `${options.url}${categories.path}${branchRef}`; - // console.log(options) + const sketchDirs = await rp(options); try {