From ad193e56d524f69ce39ab5bf831bd799c104f363 Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Fri, 3 Apr 2020 14:13:35 -0700 Subject: [PATCH] Initial files for MakeCode project --- .gitattributes | 5 + .github/workflows/makecode-release.yml | 63 +++++++++ .github/workflows/makecode.yml | 29 ++++ .gitignore | 10 +- .vscode/settings.json | 23 +++ .vscode/tasks.json | 30 ++++ Gemfile | 2 + Makefile | 10 ++ README.md | 30 ++++ _config.yml | 6 + assets/index.html | 105 ++++++++++++++ assets/js/loader.js | 139 ++++++++++++++++++ index.html | 186 +++++++++++++++++++++++++ main.blocks | 4 + main.ts | 1 + pxt.json | 21 +++ test.ts | 1 + tsconfig.json | 9 ++ 18 files changed, 673 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/makecode-release.yml create mode 100644 .github/workflows/makecode.yml create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 Gemfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 _config.yml create mode 100644 assets/index.html create mode 100644 assets/js/loader.js create mode 100644 index.html create mode 100644 main.blocks create mode 100644 main.ts create mode 100644 pxt.json create mode 100644 test.ts create mode 100644 tsconfig.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..872cb24 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +index.html linguist-generated=true +assets/index.html linguist-generated=true +assets/js/loader.js linguist-generated=true +assets/js/binary.js linguist-generated=true +assets/version.txt linguist-generated=true diff --git a/.github/workflows/makecode-release.yml b/.github/workflows/makecode-release.yml new file mode 100644 index 0000000..63802b9 --- /dev/null +++ b/.github/workflows/makecode-release.yml @@ -0,0 +1,63 @@ +name: MakeCode Arcade Release + +on: + release: + types: + - created +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x] + + steps: + - uses: actions/checkout@v1 + - name: install node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: install makecode + run: | + npm install -g pxt + pxt target arcade + - name: build js + run: | + pxt clean + pxt install + pxt build --cloud + - name: build D51 + continue-on-error: true + run: | + pxt clean + pxt install --hw samd51 + pxt build --hw samd51 --cloud + cp ./built/binary.uf2 binary-d51.uf2 + - name: build F4 + continue-on-error: true + run: | + pxt clean + pxt install --hw stm32f401 + pxt build --hw stm32f401 --cloud + cp ./built/binary.uf2 binary-f4.uf2 + - name: build P0 + continue-on-error: true + run: | + pxt clean + pxt install --hw rpi + pxt build --hw rpi --cloud + cp ./built/binary.uf2 binary-p0.uf2 + - name: bundle all + run: | + cat binary-*.uf2 > built/arcade.uf2 + - name: upload bundled + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./built/arcade.uf2 + asset_name: arcade.uf2 + asset_content_type: application/octet-stream \ No newline at end of file diff --git a/.github/workflows/makecode.yml b/.github/workflows/makecode.yml new file mode 100644 index 0000000..ad5e9f3 --- /dev/null +++ b/.github/workflows/makecode.yml @@ -0,0 +1,29 @@ +name: MakeCode + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm install + run: | + npm install -g pxt + pxt target arcade + - name: build + run: | + pxt install + pxt build --cloud + env: + CI: true diff --git a/.gitignore b/.gitignore index 4feabaa..c974ab5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ -# Initial +built +node_modules +yotta_modules +yotta_targets +pxt_modules +_site +*.db +*.tgz +.header.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f8106d4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,23 @@ +{ + "editor.formatOnType": true, + "files.autoSave": "afterDelay", + "files.watcherExclude": { + "**/.git/objects/**": true, + "**/built/**": true, + "**/node_modules/**": true, + "**/yotta_modules/**": true, + "**/yotta_targets": true, + "**/pxt_modules/**": true + }, + "files.associations": { + "*.blocks": "html", + "*.jres": "json" + }, + "search.exclude": { + "**/built": true, + "**/node_modules": true, + "**/yotta_modules": true, + "**/yotta_targets": true, + "**/pxt_modules": true + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..9ee2cf6 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ + +// A task runner that calls the MakeCode (PXT) compiler +{ + "version": "2.0.0", + "tasks": [{ + "label": "pxt deploy", + "type": "shell", + "command": "pxt deploy --local", + "group": "build", + "problemMatcher": [ "$tsc" ] + }, { + "label": "pxt build", + "type": "shell", + "command": "pxt build --local", + "group": "build", + "problemMatcher": [ "$tsc" ] + }, { + "label": "pxt install", + "type": "shell", + "command": "pxt install", + "group": "build", + "problemMatcher": [ "$tsc" ] + }, { + "label": "pxt clean", + "type": "shell", + "command": "pxt clean", + "group": "test", + "problemMatcher": [ "$tsc" ] + }] +} diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..91ceacd --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'github-pages', group: :jekyll_plugins \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9068464 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: deploy + +build: + pxt build + +deploy: + pxt deploy + +test: + pxt test diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a02ebc --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +> Open this page at [https://jwunderl.github.io/pxt-status-bar/](https://jwunderl.github.io/pxt-status-bar/) + +## Use this extension + +This repository can be added as an **extension** in MakeCode. + +* open [https://arcade.makecode.com/](https://arcade.makecode.com/) +* click on **New Project** +* click on **Extensions** under the gearwheel menu +* search for **https://github.com/jwunderl/pxt-status-bar** and import + +## Edit this extension ![Build status badge](https://github.com/jwunderl/pxt-status-bar/workflows/MakeCode/badge.svg) + +To edit this repository in MakeCode. + +* open [https://arcade.makecode.com/](https://arcade.makecode.com/) +* click on **Import** then click on **Import URL** +* paste **https://github.com/jwunderl/pxt-status-bar** and click import + +## Blocks preview + +This image shows the blocks code from the last commit in master. +This image may take a few minutes to refresh. + +![A rendered view of the blocks](https://github.com/jwunderl/pxt-status-bar/raw/master/.github/makecode/blocks.png) + +#### Metadata (used for search, rendering) + +* for PXT/arcade + diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..ceb42ef --- /dev/null +++ b/_config.yml @@ -0,0 +1,6 @@ +makecode: + target: arcade + platform: arcade + home_url: https://arcade.makecode.com/ +theme: jekyll-theme-slate +include: assets diff --git a/assets/index.html b/assets/index.html new file mode 100644 index 0000000..e6edab5 --- /dev/null +++ b/assets/index.html @@ -0,0 +1,105 @@ + + + + + + + + + +
+
+
+ + + + + + + + + +
+ +
+ + + diff --git a/assets/js/loader.js b/assets/js/loader.js new file mode 100644 index 0000000..1e7caa4 --- /dev/null +++ b/assets/js/loader.js @@ -0,0 +1,139 @@ +function makeCodeRun(options) { + var code = ""; + var isReady = false; + var simState = {} + var simStateChanged = false + var started = false; + var meta = undefined; + + // hide scrollbar + window.scrollTo(0, 1); + // init runtime + initSimState(); + fetchCode(); + + // helpers + function fetchCode() { + sendReq(options.js, function (c, status) { + if (status != 200) + return; + code = c; + // find metadata + code.replace(/^\/\/\s+meta=([^\n]+)\n/m, function (m, metasrc) { + meta = JSON.parse(metasrc); + }) + var vel = document.getElementById("version"); + if (meta.version && meta.repo && vel) { + var ap = document.createElement("a"); + ap.download = "arcade.uf2"; + ap.href = "https://github.com/" + meta.repo + "/releases/download/v" + meta.version + "/arcade.uf2"; + ap.innerText = "v" + meta.version; + vel.appendChild(ap); + } + // load simulator with correct version + document.getElementById("simframe") + .setAttribute("src", meta.simUrl); + initFullScreen(); + }) + } + + function startSim() { + if (!code || !isReady || started) + return + setState("run"); + started = true; + const runMsg = { + type: "run", + parts: [], + code: code, + partDefinitions: {}, + cdnUrl: meta.cdnUrl, + version: meta.target, + storedState: simState, + frameCounter: 1, + options: { + "theme": "green", + "player": "" + }, + id: "green-" + Math.random() + } + postMessage(runMsg); + } + + function stopSim() { + setState("stopped"); + postMessage({ + type: "stop" + }); + started = false; + } + + window.addEventListener('message', function (ev) { + var d = ev.data + if (d.type == "ready") { + var loader = document.getElementById("loader"); + if (loader) + loader.remove(); + isReady = true; + startSim(); + } else if (d.type == "simulator") { + switch (d.command) { + case "restart": + stopSim(); + startSim(); + break; + case "setstate": + simState[d.stateKey] = d.stateValue + simStateChanged = true + break; + } + } + }, false); + + // helpers + function setState(st) { + var r = document.getElementById("root"); + if (r) + r.setAttribute("data-state", st); + } + + function postMessage(msg) { + const frame = document.getElementById("simframe"); + if (frame) + frame.contentWindow.postMessage(msg, meta.simUrl); + } + + function sendReq(url, cb) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (xhttp.readyState == 4) { + cb(xhttp.responseText, xhttp.status) + } + }; + xhttp.open("GET", url, true); + xhttp.send(); + } + + function initSimState() { + try { + simState = JSON.parse(localStorage["simstate"]) + } catch (e) { + simState = {} + } + setInterval(function () { + if (simStateChanged) + localStorage["simstate"] = JSON.stringify(simState) + simStateChanged = false + }, 200) + } + + function initFullScreen() { + var sim = document.getElementById("simframe"); + var fs = document.getElementById("fullscreen"); + if (fs && sim.requestFullscreen) { + fs.onclick = function() { sim.requestFullscreen(); } + } else if (fs) { + fs.remove(); + } + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..ff43837 --- /dev/null +++ b/index.html @@ -0,0 +1,186 @@ +--- +# this is an empty front matter +--- + + + + + + {{ site.github.project_title }} + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + +
+ + + + + + diff --git a/main.blocks b/main.blocks new file mode 100644 index 0000000..eb39f70 --- /dev/null +++ b/main.blocks @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/main.ts @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/pxt.json b/pxt.json new file mode 100644 index 0000000..75e765b --- /dev/null +++ b/pxt.json @@ -0,0 +1,21 @@ +{ + "name": "pxt-status-bar", + "version": "0.0.0", + "description": "", + "dependencies": { + "device": "*" + }, + "files": [ + "README.md", + "main.blocks", + "main.ts" + ], + "testFiles": [ + "test.ts" + ], + "public": true, + "supportedTargets": [ + "arcade" + ], + "preferredEditor": "blocksprj" +} diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..7bf240c --- /dev/null +++ b/test.ts @@ -0,0 +1 @@ +// tests go here; this will not be compiled when this package is used as an extension. diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a2079ff --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "target": "es5", + "noImplicitAny": true, + "outDir": "built", + "rootDir": "." + }, + "exclude": ["pxt_modules/**/*test.ts"] +}