From a06e5a4e4e7e6025ad7827947946281f01083ff2 Mon Sep 17 00:00:00 2001 From: Devin Jean Date: Tue, 7 May 2024 12:10:45 -0500 Subject: [PATCH] switch to github actions (#36) * switch to github actions * dry run for PRs * update publish --- .githooks/pre-commit | 2 - .github/workflows/publish.yml | 26 ++++++++ .gitignore | 8 ++- README.md | 43 ++----------- build.js | 40 ++++++++++++ index.html | 116 ++-------------------------------- index.js | 5 +- utils/templates/index.html | 59 ----------------- 8 files changed, 87 insertions(+), 212 deletions(-) delete mode 100755 .githooks/pre-commit create mode 100644 .github/workflows/publish.yml create mode 100644 build.js delete mode 100644 utils/templates/index.html diff --git a/.githooks/pre-commit b/.githooks/pre-commit deleted file mode 100755 index 804b1f1..0000000 --- a/.githooks/pre-commit +++ /dev/null @@ -1,2 +0,0 @@ -node utils/build-index.js -exit $? diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..67b793e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,26 @@ +name: Publish + +on: + push: + branches: ["master"] + pull_request: + +permissions: + pages: write + id-token: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - run: npm i && node build.js + - uses: actions/upload-pages-artifact@v1 + with: + path: build + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + - uses: actions/deploy-pages@v2 + if: github.ref == 'refs/heads/master' && github.event_name == 'push' diff --git a/.gitignore b/.gitignore index 24856e3..7600f74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ node_modules +<<<<<<< HEAD +package-lock.json .DS_Store -.vscode \ No newline at end of file +build/ +======= +.DS_Store +.vscode +>>>>>>> master diff --git a/README.md b/README.md index 53b001f..1508d18 100644 --- a/README.md +++ b/README.md @@ -2,44 +2,13 @@ This repository contains the NetsBlox Extensions to be hosted on https://extensions.netsblox.org, allowing NetsBlox to recognize them as first-party extensions. -Extensions currently included in this repository: - - - [AugmentedReality](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/AugmentedReality/index.js%22]) - Use QR codes to pin sprites to the world! - - - [BeatBlox](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/BeatBlox/index.js%22]) - BeatBlox extends Music Functionality within NetsBlox - - - [BetterShare](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/BetterShare/index.js%22]) - WIP - Provides a few utilities that can make sharing projects easier - - - [Blocks to Code to Blocks (beta)](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/BlocksToCodeToBlocks/index.js%22]) - Transform back and forth with LISP-like code and NetsBlox, based on new features in Snap! v10 (WIP) - - - [FaceLandmarker](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/FaceLandmarker/index.js%22]) - Track Faces in images/video using MediaPipe! - - - [HandGestures](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/HandGestures/index.js%22]) - Track 3D hand gestures in images/video using MediaPipe! - - - [HideCategories](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/HideCategories/index.js%22]) - This extension allows you to automatically hide categories and is particularly useful when setting different visible categories for collaborating users. - - - [PoseLandmarker](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/PoseLandmarker/index.js%22]) - Track 3D full body poses in images/video using MediaPipe! - - - [🤖 RoboScape Online](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/RoboScapeOnline/index.js%22]) - Networked robotics simulation in the browser! (WIP) - - - [🤖 RoboScape Online (beta)](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/RoboScapeOnline2/index.js%22]) - Networked robotics simulation in the browser! (WIP) - - - [TimeSync](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/TimeSync/index.js%22]) - calculate time sync info from the NetsBlox server - - - [TuneScope](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/TuneScope/index.js%22]) - Music Notation, Instruments, Drums, Tones, Chords, Tracks, from the University of Virginia (Glen Bull) - - - [WebSerial](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/WebSerial/index.js%22]) - Provides blocks for connecting to a device, e.g. an Arduino, over WebSerial - - - [WhenKeyPressedLogger](https://dev.netsblox.org/?extensions=[%22https://extensions.netsblox.org/extensions/WhenKeyPressedLogger/index.js%22]) - Logs 'When [key] key pressed' block activations for Ben - +View currently published extensions at https://extensions.netsblox.org/ ## Contributing -After cloning the repository, configure the githooks with: -``` -git config core.hooksPath .githooks -``` -This will ensure that any automated preparation will happen automatically such as updating the website. -Next, create a new directory in `extensions/`. This should contain the following files: +To make a new extension, simply create a new directory in `extensions/`. This should contain the following files: + - `index.js`: JS code for the actual extension -- `extension.json`: Description of the extension \ No newline at end of file +- `extension.json`: Description of the extension + +You can copy from an existing extension to see the required format for these files. diff --git a/build.js b/build.js new file mode 100644 index 0000000..7128130 --- /dev/null +++ b/build.js @@ -0,0 +1,40 @@ +const _ = require('lodash'); +const fs = require('fs'); +const path = require('path'); +const EXTENSIONS_DIR = path.join(__dirname, 'extensions'); +const OUT_DIR = path.join(__dirname, 'build'); + +const extensions = fs.readdirSync(EXTENSIONS_DIR).map(readExtension); + +try { fs.mkdirSync(OUT_DIR); } catch {} + +fs.writeFileSync(path.join(OUT_DIR, 'index.html'), renderTemplate('index.html', { extensions })); +fs.copyFileSync('index.js', path.join(OUT_DIR, 'index.js')); + +// ------------------------------------------ + +function readExtension(name) { + const dirpath = path.join(EXTENSIONS_DIR, name); + const settings = JSON.parse(fs.readFileSync(path.join(dirpath, 'extension.json'), 'utf8')); + const description = settings['description']; + let linkUrl = ""; + let scriptUrl = `https://extensions.netsblox.org/extensions/${name}/index.js`; + + if (!settings['useDev']) { + linkUrl = `https://editor.netsblox.org/?extensions=[%22${scriptUrl}%22]#`; + } else { + linkUrl = `https://dev.netsblox.org/?extensions=[%22${scriptUrl}%22]#`; + } + + return { + name, + displayName : settings['customName'] ?? name, + description, + linkUrl, + scriptUrl, + }; +} + +function renderTemplate(name, data) { + return _.template(fs.readFileSync(name, 'utf8'))(data).trim(); +} diff --git a/index.html b/index.html index 7b684a3..ef5aba0 100644 --- a/index.html +++ b/index.html @@ -21,119 +21,15 @@

NetsBlox Extensions

Show all descriptions Hide all descriptions - + <% extensions.forEach(ext=> { %>
- AugmentedReality + <%= ext.displayName %>

- - Use QR codes to pin sprites to the world! + + <%= ext.description %>

- -
- BeatBlox -

- - BeatBlox extends Music Functionality within NetsBlox -

-
- -
- BetterShare -

- - WIP - Provides a few utilities that can make sharing projects easier -

-
- -
- Blocks to Code to Blocks (beta) -

- - Transform back and forth with LISP-like code and NetsBlox, based on new features in Snap! v10 (WIP) -

-
- -
- FaceLandmarker -

- - Track Faces in images/video using MediaPipe! -

-
- -
- HandGestures -

- - Track 3D hand gestures in images/video using MediaPipe! -

-
- -
- HideCategories -

- - This extension allows you to automatically hide categories and is particularly useful when setting different visible categories for collaborating users. -

-
- -
- PoseLandmarker -

- - Track 3D full body poses in images/video using MediaPipe! -

-
- -
- 🤖 RoboScape Online -

- - Networked robotics simulation in the browser! (WIP) -

-
- -
- 🤖 RoboScape Online (beta) -

- - Networked robotics simulation in the browser! (WIP) -

-
- -
- TimeSync -

- - calculate time sync info from the NetsBlox server -

-
- -
- TuneScope -

- - Music Notation, Instruments, Drums, Tones, Chords, Tracks, from the University of Virginia (Glen Bull) -

-
- -
- WebSerial -

- - Provides blocks for connecting to a device, e.g. an Arduino, over WebSerial -

-
- -
- WhenKeyPressedLogger -

- - Logs 'When [key] key pressed' block activations for Ben -

-
- + <% }) %>
@@ -160,4 +56,4 @@

NetsBlox Extensions

- \ No newline at end of file + diff --git a/index.js b/index.js index 931ecab..a295218 100644 --- a/index.js +++ b/index.js @@ -61,12 +61,11 @@ search.oninput = () => { let result = fuzzysort.single(search.value, fullText); extension.style.display = (search.value == "" || result)? "block" : "none"; - - if (search.value == "") { + if(search.value == "") { // Clear highlight when no match title.innerHTML = title.innerText; - if (extension.open) { + if(extension.open) { desc.innerHTML = desc.innerText; } } diff --git a/utils/templates/index.html b/utils/templates/index.html deleted file mode 100644 index ef5aba0..0000000 --- a/utils/templates/index.html +++ /dev/null @@ -1,59 +0,0 @@ - - - NetsBlox Extensions - - - - - -

NetsBlox Extensions

- -

Welcome to the list of supported NetsBlox extensions! Click on one below to try it out!

- - - - - - Show all descriptions - Hide all descriptions - - <% extensions.forEach(ext=> { %> -
- <%= ext.displayName %> -

- - <%= ext.description %> -

-
- <% }) %> - -
- - - -

- For more information or to report an issue, please visit - github.com/NetsBlox/extensions. -

- - - - -