From 39c3a11d9f65730baac527c5586799709aba9055 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Tue, 7 Dec 2021 21:38:09 +0100 Subject: [PATCH 01/35] first draft: does not export to correct path yet --- typescript/sharedLib/.gitignore | 2 ++ typescript/sharedLib/README.md | 27 +++++++++++++++++++ typescript/sharedLib/package-lock.json | 37 ++++++++++++++++++++++++++ typescript/sharedLib/package.json | 20 ++++++++++++++ typescript/sharedLib/src/app.ts | 2 ++ typescript/sharedLib/tsconfig.json | 8 ++++++ 6 files changed, 96 insertions(+) create mode 100644 typescript/sharedLib/.gitignore create mode 100644 typescript/sharedLib/README.md create mode 100644 typescript/sharedLib/package-lock.json create mode 100644 typescript/sharedLib/package.json create mode 100644 typescript/sharedLib/src/app.ts create mode 100644 typescript/sharedLib/tsconfig.json diff --git a/typescript/sharedLib/.gitignore b/typescript/sharedLib/.gitignore new file mode 100644 index 000000000..b2af6e004 --- /dev/null +++ b/typescript/sharedLib/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +!package-lock.json \ No newline at end of file diff --git a/typescript/sharedLib/README.md b/typescript/sharedLib/README.md new file mode 100644 index 000000000..78b07b332 --- /dev/null +++ b/typescript/sharedLib/README.md @@ -0,0 +1,27 @@ +# BangleTS + +A generic project setup for compiling apps from Typescript to Bangle.js ready, readable Javascript. +It includes types for *some* of the modules and globals that are exposed for apps to use. +The goal is to have types for everything, but that will take some time. Feel free to help out by contributing! + +## Using the types +TODO + +## Compilation + +Install [npm](https://www.npmjs.com/get-npm) if you haven't already. +Make sure you are using version ^8 by running `npm -v`. If the version is incorrect, run `npm i -g npm@^8`. + +After having installed npm for your platform, open a terminal, and navigate into the `/typescript/sharedLib` folder. Then run: + +``` +npm ci +``` + +to install the project's build tools, and: + +``` +npm run build:app pathToYourApp.ts +``` + +To build your app. The last command will generate the `app.js` file containing the transpiled code for the BangleJS. diff --git a/typescript/sharedLib/package-lock.json b/typescript/sharedLib/package-lock.json new file mode 100644 index 000000000..9df411a91 --- /dev/null +++ b/typescript/sharedLib/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "banglets", + "version": "0.1.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "banglets", + "version": "0.1.0", + "license": "MIT", + "devDependencies": { + "typescript": "^4.5.2" + } + }, + "node_modules/typescript": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", + "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "typescript": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", + "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "dev": true + } + } +} diff --git a/typescript/sharedLib/package.json b/typescript/sharedLib/package.json new file mode 100644 index 000000000..2bf45de2e --- /dev/null +++ b/typescript/sharedLib/package.json @@ -0,0 +1,20 @@ +{ + "name": "bangle.ts", + "version": "0.1.0", + "description": "Typescript configuration and typings for Bangle.js", + "main": "app.js", + "types": "app.d.ts", + "scripts": { + "build:testapp": "tsc src/app.ts", + "build:types": "tsc src/bangle.d.ts", + "build:app": "tsc" + }, + "author": { + "name": "Sebastian Di Luzio", + "email": "sebastian@diluz.io" + }, + "license": "MIT", + "devDependencies": { + "typescript": "^4.5.2" + } +} diff --git a/typescript/sharedLib/src/app.ts b/typescript/sharedLib/src/app.ts new file mode 100644 index 000000000..6e5739557 --- /dev/null +++ b/typescript/sharedLib/src/app.ts @@ -0,0 +1,2 @@ +const testString = 'test hehe'; +console.log(testString); diff --git a/typescript/sharedLib/tsconfig.json b/typescript/sharedLib/tsconfig.json new file mode 100644 index 000000000..42b34ec65 --- /dev/null +++ b/typescript/sharedLib/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "es2015", + "noImplicitAny": true, + "target": "es2015", + "outDir": "../dist" + } +} From 3cd9c3952560dec0f7689de0cf2eb9302125afb6 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Tue, 7 Dec 2021 21:46:28 +0100 Subject: [PATCH 02/35] add build example to export to correct path --- typescript/sharedLib/README.md | 5 +++-- typescript/sharedLib/package.json | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/typescript/sharedLib/README.md b/typescript/sharedLib/README.md index 78b07b332..a54a4c75a 100644 --- a/typescript/sharedLib/README.md +++ b/typescript/sharedLib/README.md @@ -1,10 +1,11 @@ # BangleTS A generic project setup for compiling apps from Typescript to Bangle.js ready, readable Javascript. -It includes types for *some* of the modules and globals that are exposed for apps to use. +It includes types for _some_ of the modules and globals that are exposed for apps to use. The goal is to have types for everything, but that will take some time. Feel free to help out by contributing! ## Using the types + TODO ## Compilation @@ -21,7 +22,7 @@ npm ci to install the project's build tools, and: ``` -npm run build:app pathToYourApp.ts +npx tsc ./relativePathToYourApp/app.ts --outDir ./relativePathToYourApp/dist ``` To build your app. The last command will generate the `app.js` file containing the transpiled code for the BangleJS. diff --git a/typescript/sharedLib/package.json b/typescript/sharedLib/package.json index 2bf45de2e..814db8f3e 100644 --- a/typescript/sharedLib/package.json +++ b/typescript/sharedLib/package.json @@ -5,9 +5,8 @@ "main": "app.js", "types": "app.d.ts", "scripts": { - "build:testapp": "tsc src/app.ts", - "build:types": "tsc src/bangle.d.ts", - "build:app": "tsc" + "build:testapp": "tsc ./src/app.ts --outDir ./dist", + "build:types": "tsc ./src/bangle.d.ts" }, "author": { "name": "Sebastian Di Luzio", From 61cc93b0b6e461b25daa5225497466c00a099662 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Tue, 7 Dec 2021 22:27:09 +0100 Subject: [PATCH 03/35] prepare for using with widChargingStatus global types are not yet received correctly, but we're close! - use widChargerStatus as first example to make setup work - add github action to compile supplied types/globals on pushes --- .github/workflows/nodejs.yml | 25 +++ .../{widget.js => widget.ts} | 0 typescript/{sharedLib => }/.gitignore | 0 typescript/{sharedLib => }/README.md | 0 typescript/globals.d.ts | 145 ++++++++++++++++++ typescript/{sharedLib => }/package-lock.json | 0 typescript/{sharedLib => }/package.json | 4 +- typescript/sharedLib/src/app.ts | 2 - typescript/{sharedLib => }/tsconfig.json | 6 +- 9 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/nodejs.yml rename apps/widChargingStatus/{widget.js => widget.ts} (100%) rename typescript/{sharedLib => }/.gitignore (100%) rename typescript/{sharedLib => }/README.md (100%) create mode 100644 typescript/globals.d.ts rename typescript/{sharedLib => }/package-lock.json (100%) rename typescript/{sharedLib => }/package.json (70%) delete mode 100644 typescript/sharedLib/src/app.ts rename typescript/{sharedLib => }/tsconfig.json (52%) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 000000000..9503d8934 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,25 @@ +name: Node CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.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: go to typescript directory + run: cd typescript + - name: npm ci + run: npm ci + - name: build types + run: npm run build:types \ No newline at end of file diff --git a/apps/widChargingStatus/widget.js b/apps/widChargingStatus/widget.ts similarity index 100% rename from apps/widChargingStatus/widget.js rename to apps/widChargingStatus/widget.ts diff --git a/typescript/sharedLib/.gitignore b/typescript/.gitignore similarity index 100% rename from typescript/sharedLib/.gitignore rename to typescript/.gitignore diff --git a/typescript/sharedLib/README.md b/typescript/README.md similarity index 100% rename from typescript/sharedLib/README.md rename to typescript/README.md diff --git a/typescript/globals.d.ts b/typescript/globals.d.ts new file mode 100644 index 000000000..702ef26cb --- /dev/null +++ b/typescript/globals.d.ts @@ -0,0 +1,145 @@ +// TODO all of these globals (copied from eslintrc need to be typed at some point) +/* "globals": { + // Methods and Fields at https://banglejs.com/reference + "Array": "readonly", + "ArrayBuffer": "readonly", + "ArrayBufferView": "readonly", + "Bangle": "readonly", + "BluetoothDevice": "readonly", + "BluetoothRemoteGATTCharacteristic": "readonly", + "BluetoothRemoteGATTServer": "readonly", + "BluetoothRemoteGATTService": "readonly", + "Boolean": "readonly", + "console": "readonly", + "DataView": "readonly", + "Date": "readonly", + "E": "readonly", + "Error": "readonly", + "Flash": "readonly", + "Float32Array": "readonly", + "Float64Array": "readonly", + "fs": "readonly", + "Function": "readonly", + "Graphics": "readonly", + "heatshrink": "readonly", + "I2C": "readonly", + "Int16Array": "readonly", + "Int32Array": "readonly", + "Int8Array": "readonly", + "InternalError": "readonly", + "JSON": "readonly", + "Math": "readonly", + "Modules": "readonly", + "NRF": "readonly", + "Number": "readonly", + "Object": "readonly", + "OneWire": "readonly", + "Pin": "readonly", + "process": "readonly", + "Promise": "readonly", + "ReferenceError": "readonly", + "RegExp": "readonly", + "Serial": "readonly", + "SPI": "readonly", + "Storage": "readonly", + "StorageFile": "readonly", + "String": "readonly", + "SyntaxError": "readonly", + "tensorflow": "readonly", + "TFMicroInterpreter": "readonly", + "TypeError": "readonly", + "Uint16Array": "readonly", + "Uint24Array": "readonly", + "Uint32Array": "readonly", + "Uint8Array": "readonly", + "Uint8ClampedArray": "readonly", + "Waveform": "readonly", + // Methods and Fields at https://banglejs.com/reference + "analogRead": "readonly", + "analogWrite": "readonly", + "arguments": "readonly", + "atob": "readonly", + "Bluetooth": "readonly", + "BTN": "readonly", + "BTN1": "readonly", + "BTN2": "readonly", + "BTN3": "readonly", + "BTN4": "readonly", + "BTN5": "readonly", + "btoa": "readonly", + "changeInterval": "readonly", + "clearInterval": "readonly", + "clearTimeout": "readonly", + "clearWatch": "readonly", + "decodeURIComponent": "readonly", + "digitalPulse": "readonly", + "digitalRead": "readonly", + "digitalWrite": "readonly", + "dump": "readonly", + "echo": "readonly", + "edit": "readonly", + "encodeURIComponent": "readonly", + "eval": "readonly", + "getPinMode": "readonly", + "getSerial": "readonly", + "getTime": "readonly", + "global": "readonly", + "HIGH": "readonly", + "I2C1": "readonly", + "Infinity": "readonly", + "isFinite": "readonly", + "isNaN": "readonly", + "LED": "readonly", + "LED1": "readonly", + "LED2": "readonly", + "load": "readonly", + "LoopbackA": "readonly", + "LoopbackB": "readonly", + "LOW": "readonly", + "NaN": "readonly", + "parseFloat": "readonly", + "parseInt": "readonly", + "peek16": "readonly", + "peek32": "readonly", + "peek8": "readonly", + "pinMode": "readonly", + "poke16": "readonly", + "poke32": "readonly", + "poke8": "readonly", + "print": "readonly", + "require": "readonly", + "reset": "readonly", + "save": "readonly", + "Serial1": "readonly", + "setBusyIndicator": "readonly", + "setInterval": "readonly", + "setSleepIndicator": "readonly", + "setTime": "readonly", + "setTimeout": "readonly", + "setWatch": "readonly", + "shiftOut": "readonly", + "SPI1": "readonly", + "Terminal": "readonly", + "trace": "readonly", + "VIBRATE": "readonly", + // Aliases and not defined at https://banglejs.com/reference + "g": "readonly", + */ + +declare const Bangle: { + // functions + buzz: () => void; + drawWidgets: () => void; + isCharging: () => boolean; + // events + on(event: 'charging', listener: (charging: boolean) => void): void; + // TODO add more +}; + +type Widget = { + area: 'tr' | 'tl'; + width: number; + draw: () => void; +}; + +declare const WIDGETS: { [key: string]: Widget }; diff --git a/typescript/sharedLib/package-lock.json b/typescript/package-lock.json similarity index 100% rename from typescript/sharedLib/package-lock.json rename to typescript/package-lock.json diff --git a/typescript/sharedLib/package.json b/typescript/package.json similarity index 70% rename from typescript/sharedLib/package.json rename to typescript/package.json index 814db8f3e..513e7b7df 100644 --- a/typescript/sharedLib/package.json +++ b/typescript/package.json @@ -5,8 +5,8 @@ "main": "app.js", "types": "app.d.ts", "scripts": { - "build:testapp": "tsc ./src/app.ts --outDir ./dist", - "build:types": "tsc ./src/bangle.d.ts" + "build:example": "tsc ../apps/widChargingStatus/widget.ts --outDir ../apps/widChargingStatus/dist", + "build:types": "tsc ./globals.d.ts" }, "author": { "name": "Sebastian Di Luzio", diff --git a/typescript/sharedLib/src/app.ts b/typescript/sharedLib/src/app.ts deleted file mode 100644 index 6e5739557..000000000 --- a/typescript/sharedLib/src/app.ts +++ /dev/null @@ -1,2 +0,0 @@ -const testString = 'test hehe'; -console.log(testString); diff --git a/typescript/sharedLib/tsconfig.json b/typescript/tsconfig.json similarity index 52% rename from typescript/sharedLib/tsconfig.json rename to typescript/tsconfig.json index 42b34ec65..ce8e6278b 100644 --- a/typescript/sharedLib/tsconfig.json +++ b/typescript/tsconfig.json @@ -3,6 +3,8 @@ "module": "es2015", "noImplicitAny": true, "target": "es2015", - "outDir": "../dist" - } + "outDir": "../dist", + "isolatedModules": false + }, + "include": ["./globals.d.ts"] } From 63b26f5d1ffeb069c373d94eb9a9705004a1c1c1 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Wed, 8 Dec 2021 20:22:39 +0100 Subject: [PATCH 04/35] move dev dependencies to main package.json, get first compiling version of test widget - i still want to be able to get the types ambiently defined without any weird import needed - it would be nice to be able to have a separate package.json in ./typescirpt. not sure if it's possible, I would move working on that part to the end --- apps.json | 2 +- apps/widChargingStatus/dist/widget.js | 31 +++++++++++ apps/widChargingStatus/widget.ts | 60 +++++++++++---------- package.json | 8 ++- tsconfig.json | 7 +++ typescript/.gitignore | 2 - typescript/package-lock.json | 37 ------------- typescript/package.json | 19 ------- typescript/tsconfig.json | 10 ---- typescript/{ => types}/globals.d.ts | 77 ++++++++++++++++----------- 10 files changed, 124 insertions(+), 129 deletions(-) create mode 100644 apps/widChargingStatus/dist/widget.js create mode 100644 tsconfig.json delete mode 100644 typescript/.gitignore delete mode 100644 typescript/package-lock.json delete mode 100644 typescript/package.json delete mode 100644 typescript/tsconfig.json rename typescript/{ => types}/globals.d.ts (75%) diff --git a/apps.json b/apps.json index 13bb5892d..58a67d8c2 100644 --- a/apps.json +++ b/apps.json @@ -4763,7 +4763,7 @@ "tags": "widget", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"widChargingStatus.wid.js","url":"widget.js"} + {"name":"widChargingStatus.wid.js","url":"./dist/widget.js"} ] }, { diff --git a/apps/widChargingStatus/dist/widget.js b/apps/widChargingStatus/dist/widget.js new file mode 100644 index 000000000..7772a5b87 --- /dev/null +++ b/apps/widChargingStatus/dist/widget.js @@ -0,0 +1,31 @@ +"use strict"; +exports.__esModule = true; +(function () { + var icon = require('heatshrink').decompress(atob('ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA')); + var iconWidth = 18; + function draw() { + g.reset(); + if (Bangle.isCharging()) { + g.setColor('#FD0'); + g.drawImage(icon, this.x + 1, this.y + 1, { + scale: 0.6875 + }); + } + } + WIDGETS.chargingStatus = { + area: 'tr', + width: Bangle.isCharging() ? iconWidth : 0, + draw: draw + }; + Bangle.on('charging', function (charging) { + if (charging) { + Bangle.buzz(); + WIDGETS.chargingStatus.width = iconWidth; + } + else { + WIDGETS.chargingStatus.width = 0; + } + Bangle.drawWidgets(); // re-layout widgets + g.flip(); + }); +})(); diff --git a/apps/widChargingStatus/widget.ts b/apps/widChargingStatus/widget.ts index 90f9199fa..e3ce2d7e2 100644 --- a/apps/widChargingStatus/widget.ts +++ b/apps/widChargingStatus/widget.ts @@ -1,31 +1,37 @@ +import { loadGlobals } from '../../typescript/types/globals'; // TODO find a nicer way to load ambient type definitions than this + (() => { - const icon = require("heatshrink").decompress(atob("ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA")); - const iconWidth = 18; + const icon = require('heatshrink').decompress( + atob( + 'ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA' + ) + ); + const iconWidth = 18; - function draw() { - g.reset(); - if (Bangle.isCharging()) { - g.setColor("#FD0"); - g.drawImage(icon, this.x + 1, this.y + 1, { - scale: 0.6875 - }); - } - } + function draw() { + g.reset(); + if (Bangle.isCharging()) { + g.setColor('#FD0'); + g.drawImage(icon, this.x + 1, this.y + 1, { + scale: 0.6875, + }); + } + } - WIDGETS.chargingStatus = { - area: 'tr', - width: Bangle.isCharging() ? iconWidth : 0, - draw: draw, - }; + WIDGETS.chargingStatus = { + area: 'tr', + width: Bangle.isCharging() ? iconWidth : 0, + draw: draw, + }; - Bangle.on('charging', (charging) => { - if (charging) { - Bangle.buzz(); - WIDGETS.chargingStatus.width = iconWidth; - } else { - WIDGETS.chargingStatus.width = 0; - } - Bangle.drawWidgets(); // re-layout widgets - g.flip(); - }); -})(); \ No newline at end of file + Bangle.on('charging', (charging) => { + if (charging) { + Bangle.buzz(); + WIDGETS.chargingStatus.width = iconWidth; + } else { + WIDGETS.chargingStatus.width = 0; + } + Bangle.drawWidgets(); // re-layout widgets + g.flip(); + }); +})(); diff --git a/package.json b/package.json index b796044c9..1ecfb6280 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,16 @@ "author": "Gordon Williams (http://espruino.com)", "version": "0.0.1", "devDependencies": { - "eslint": "7.1.0" + "eslint": "7.1.0", + "@types/node": "16.11.12", + "typescript": "4.5.2" }, "scripts": { "lint-apps": "eslint ./apps --ext .js", "test": "node bin/sanitycheck.js && eslint ./apps --ext .js", - "start": "npx http-server -c-1" + "start": "npx http-server -c-1", + "build:example": "tsc ./apps/widChargingStatus/widget.ts --outDir ./apps/widChargingStatus/dist", + "build:types": "tsc .typescript/types/globals.d.ts" }, "dependencies": { "acorn": "^7.2.0" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..46a557e89 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "es2015", + "noImplicitAny": true, + "target": "es2015" + } +} diff --git a/typescript/.gitignore b/typescript/.gitignore deleted file mode 100644 index b2af6e004..000000000 --- a/typescript/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -!package-lock.json \ No newline at end of file diff --git a/typescript/package-lock.json b/typescript/package-lock.json deleted file mode 100644 index 9df411a91..000000000 --- a/typescript/package-lock.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "banglets", - "version": "0.1.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "banglets", - "version": "0.1.0", - "license": "MIT", - "devDependencies": { - "typescript": "^4.5.2" - } - }, - "node_modules/typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - } - }, - "dependencies": { - "typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", - "dev": true - } - } -} diff --git a/typescript/package.json b/typescript/package.json deleted file mode 100644 index 513e7b7df..000000000 --- a/typescript/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "bangle.ts", - "version": "0.1.0", - "description": "Typescript configuration and typings for Bangle.js", - "main": "app.js", - "types": "app.d.ts", - "scripts": { - "build:example": "tsc ../apps/widChargingStatus/widget.ts --outDir ../apps/widChargingStatus/dist", - "build:types": "tsc ./globals.d.ts" - }, - "author": { - "name": "Sebastian Di Luzio", - "email": "sebastian@diluz.io" - }, - "license": "MIT", - "devDependencies": { - "typescript": "^4.5.2" - } -} diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json deleted file mode 100644 index ce8e6278b..000000000 --- a/typescript/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "module": "es2015", - "noImplicitAny": true, - "target": "es2015", - "outDir": "../dist", - "isolatedModules": false - }, - "include": ["./globals.d.ts"] -} diff --git a/typescript/globals.d.ts b/typescript/types/globals.d.ts similarity index 75% rename from typescript/globals.d.ts rename to typescript/types/globals.d.ts index 702ef26cb..97a40ae54 100644 --- a/typescript/globals.d.ts +++ b/typescript/types/globals.d.ts @@ -1,33 +1,19 @@ // TODO all of these globals (copied from eslintrc need to be typed at some point) /* "globals": { // Methods and Fields at https://banglejs.com/reference - "Array": "readonly", - "ArrayBuffer": "readonly", - "ArrayBufferView": "readonly", - "Bangle": "readonly", "BluetoothDevice": "readonly", "BluetoothRemoteGATTCharacteristic": "readonly", "BluetoothRemoteGATTServer": "readonly", "BluetoothRemoteGATTService": "readonly", - "Boolean": "readonly", - "console": "readonly", "DataView": "readonly", - "Date": "readonly", "E": "readonly", "Error": "readonly", "Flash": "readonly", - "Float32Array": "readonly", - "Float64Array": "readonly", "fs": "readonly", "Function": "readonly", - "Graphics": "readonly", "heatshrink": "readonly", "I2C": "readonly", - "Int16Array": "readonly", - "Int32Array": "readonly", - "Int8Array": "readonly", "InternalError": "readonly", - "JSON": "readonly", "Math": "readonly", "Modules": "readonly", "NRF": "readonly", @@ -122,24 +108,53 @@ "Terminal": "readonly", "trace": "readonly", "VIBRATE": "readonly", - // Aliases and not defined at https://banglejs.com/reference - "g": "readonly", */ -declare const Bangle: { - // functions - buzz: () => void; - drawWidgets: () => void; - isCharging: () => boolean; - // events - on(event: 'charging', listener: (charging: boolean) => void): void; - // TODO add more -}; +export type loadGlobals = {}; -type Widget = { - area: 'tr' | 'tl'; - width: number; - draw: () => void; -}; +declare global { + const Bangle: { + // functions + buzz: () => void; + drawWidgets: () => void; + isCharging: () => boolean; + // events + on(event: 'charging', listener: (charging: boolean) => void): void; + // TODO add more + }; -declare const WIDGETS: { [key: string]: Widget }; + type Image = { + width: number; + height: number; + bpp?: number; + buffer: ArrayBuffer | string; + transparent?: number; + palette?: Uint16Array; + }; + + type GraphicsApi = { + reset: () => void; + flip: () => void; + setColor: (color: string) => void; // TODO we can most likely type color more usefully than this + drawImage: ( + image: string | Image | ArrayBuffer, + xOffset: number, + yOffset: number, + options?: { + rotate?: number; + scale?: number; + } + ) => void; + // TODO add more + }; + + const Graphics: GraphicsApi; + const g: GraphicsApi; + + type Widget = { + area: 'tr' | 'tl'; + width: number; + draw: () => void; + }; + const WIDGETS: { [key: string]: Widget }; +} From d46736c01a4fa85888e78a8c8814ddcd26384908 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Wed, 8 Dec 2021 20:23:14 +0100 Subject: [PATCH 05/35] adjust github actions --- .github/workflows/nodejs.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 9503d8934..e2a12cc51 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -4,7 +4,6 @@ on: [push] jobs: build: - runs-on: ubuntu-latest strategy: @@ -12,14 +11,12 @@ jobs: node-version: [16.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: go to typescript directory - run: cd typescript - - name: npm ci - run: npm ci - - name: build types - run: npm run build:types \ No newline at end of file + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm i + run: npm i + - name: build types + run: npm run build:types From 0a2426a6dd9add940909a552663eb0b25ce86ade Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Wed, 8 Dec 2021 20:24:11 +0100 Subject: [PATCH 06/35] fix type build script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ecfb6280..f6426e7e2 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "test": "node bin/sanitycheck.js && eslint ./apps --ext .js", "start": "npx http-server -c-1", "build:example": "tsc ./apps/widChargingStatus/widget.ts --outDir ./apps/widChargingStatus/dist", - "build:types": "tsc .typescript/types/globals.d.ts" + "build:types": "tsc ./typescript/types/globals.d.ts" }, "dependencies": { "acorn": "^7.2.0" From 83d445c1a28c7257cfd09b819a0b949ce439507e Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 20:52:17 +0100 Subject: [PATCH 07/35] move package back within typescript --- package.json | 8 +--- typescript/.gitignore | 2 + typescript/README.md | 4 +- typescript/package-lock.json | 49 +++++++++++++++++++++++ typescript/package.json | 14 +++++++ tsconfig.json => typescript/tsconfig.json | 0 6 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 typescript/.gitignore create mode 100644 typescript/package-lock.json create mode 100644 typescript/package.json rename tsconfig.json => typescript/tsconfig.json (100%) diff --git a/package.json b/package.json index f6426e7e2..b796044c9 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,12 @@ "author": "Gordon Williams (http://espruino.com)", "version": "0.0.1", "devDependencies": { - "eslint": "7.1.0", - "@types/node": "16.11.12", - "typescript": "4.5.2" + "eslint": "7.1.0" }, "scripts": { "lint-apps": "eslint ./apps --ext .js", "test": "node bin/sanitycheck.js && eslint ./apps --ext .js", - "start": "npx http-server -c-1", - "build:example": "tsc ./apps/widChargingStatus/widget.ts --outDir ./apps/widChargingStatus/dist", - "build:types": "tsc ./typescript/types/globals.d.ts" + "start": "npx http-server -c-1" }, "dependencies": { "acorn": "^7.2.0" diff --git a/typescript/.gitignore b/typescript/.gitignore new file mode 100644 index 000000000..630f61ee5 --- /dev/null +++ b/typescript/.gitignore @@ -0,0 +1,2 @@ +./node_modules +!package-lock.json diff --git a/typescript/README.md b/typescript/README.md index a54a4c75a..9b38459ae 100644 --- a/typescript/README.md +++ b/typescript/README.md @@ -13,7 +13,7 @@ TODO Install [npm](https://www.npmjs.com/get-npm) if you haven't already. Make sure you are using version ^8 by running `npm -v`. If the version is incorrect, run `npm i -g npm@^8`. -After having installed npm for your platform, open a terminal, and navigate into the `/typescript/sharedLib` folder. Then run: +After having installed npm for your platform, open a terminal, and navigate into the `/typescript` folder. Then run: ``` npm ci @@ -22,7 +22,7 @@ npm ci to install the project's build tools, and: ``` -npx tsc ./relativePathToYourApp/app.ts --outDir ./relativePathToYourApp/dist +npx tsc ../apps/relativePathToYourApp/app.ts --outDir ../apps/relativePathToYourApp/dist ``` To build your app. The last command will generate the `app.js` file containing the transpiled code for the BangleJS. diff --git a/typescript/package-lock.json b/typescript/package-lock.json new file mode 100644 index 000000000..bd3cfc702 --- /dev/null +++ b/typescript/package-lock.json @@ -0,0 +1,49 @@ +{ + "name": "Bangle.ts", + "version": "0.0.1", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "Bangle.ts", + "version": "0.0.1", + "devDependencies": { + "@types/node": "16.11.12", + "typescript": "4.5.2" + } + }, + "node_modules/@types/node": { + "version": "16.11.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.12.tgz", + "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==", + "dev": true + }, + "node_modules/typescript": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", + "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "@types/node": { + "version": "16.11.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.12.tgz", + "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==", + "dev": true + }, + "typescript": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", + "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "dev": true + } + } +} diff --git a/typescript/package.json b/typescript/package.json new file mode 100644 index 000000000..03f435497 --- /dev/null +++ b/typescript/package.json @@ -0,0 +1,14 @@ +{ + "name": "Bangle.ts", + "description": "Bangle.js Typescript Project Setup and Types", + "author": "Sebastian Di Luzio (https://diluz.io)", + "version": "0.0.1", + "devDependencies": { + "@types/node": "16.11.12", + "typescript": "4.5.2" + }, + "scripts": { + "build:example": "tsc ../apps/widChargingStatus/widget.ts --outDir ../apps/widChargingStatus/dist", + "build:types": "tsc ./types/globals.d.ts" + } +} diff --git a/tsconfig.json b/typescript/tsconfig.json similarity index 100% rename from tsconfig.json rename to typescript/tsconfig.json From 45bd654eca724a8cb15cddf1eab883978c38bd87 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 21:19:01 +0100 Subject: [PATCH 08/35] fix global vars inside IDE (only cli to go) --- apps/widChargingStatus/dist/widget.js | 2 - apps/widChargingStatus/widget.ts | 2 - typescript/package-lock.json | 13 - typescript/package.json | 1 - typescript/tsconfig.json | 3 +- typescript/types/globals.d.ts | 327 ++++++++++++++------------ 6 files changed, 177 insertions(+), 171 deletions(-) diff --git a/apps/widChargingStatus/dist/widget.js b/apps/widChargingStatus/dist/widget.js index 7772a5b87..eea96ce58 100644 --- a/apps/widChargingStatus/dist/widget.js +++ b/apps/widChargingStatus/dist/widget.js @@ -1,5 +1,3 @@ -"use strict"; -exports.__esModule = true; (function () { var icon = require('heatshrink').decompress(atob('ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA')); var iconWidth = 18; diff --git a/apps/widChargingStatus/widget.ts b/apps/widChargingStatus/widget.ts index e3ce2d7e2..a8cf2ed94 100644 --- a/apps/widChargingStatus/widget.ts +++ b/apps/widChargingStatus/widget.ts @@ -1,5 +1,3 @@ -import { loadGlobals } from '../../typescript/types/globals'; // TODO find a nicer way to load ambient type definitions than this - (() => { const icon = require('heatshrink').decompress( atob( diff --git a/typescript/package-lock.json b/typescript/package-lock.json index bd3cfc702..52be5f98a 100644 --- a/typescript/package-lock.json +++ b/typescript/package-lock.json @@ -8,16 +8,9 @@ "name": "Bangle.ts", "version": "0.0.1", "devDependencies": { - "@types/node": "16.11.12", "typescript": "4.5.2" } }, - "node_modules/@types/node": { - "version": "16.11.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.12.tgz", - "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==", - "dev": true - }, "node_modules/typescript": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", @@ -33,12 +26,6 @@ } }, "dependencies": { - "@types/node": { - "version": "16.11.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.12.tgz", - "integrity": "sha512-+2Iggwg7PxoO5Kyhvsq9VarmPbIelXP070HMImEpbtGCoyWNINQj4wzjbQCXzdHTRXnqufutJb5KAURZANNBAw==", - "dev": true - }, "typescript": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", diff --git a/typescript/package.json b/typescript/package.json index 03f435497..83ea7d82b 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -4,7 +4,6 @@ "author": "Sebastian Di Luzio (https://diluz.io)", "version": "0.0.1", "devDependencies": { - "@types/node": "16.11.12", "typescript": "4.5.2" }, "scripts": { diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 46a557e89..8a7ab3342 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -3,5 +3,6 @@ "module": "es2015", "noImplicitAny": true, "target": "es2015" - } + }, + "include": ["../apps/**/*", "./**/*"] } diff --git a/typescript/types/globals.d.ts b/typescript/types/globals.d.ts index 97a40ae54..359d5d294 100644 --- a/typescript/types/globals.d.ts +++ b/typescript/types/globals.d.ts @@ -1,160 +1,183 @@ // TODO all of these globals (copied from eslintrc need to be typed at some point) -/* "globals": { - // Methods and Fields at https://banglejs.com/reference - "BluetoothDevice": "readonly", - "BluetoothRemoteGATTCharacteristic": "readonly", - "BluetoothRemoteGATTServer": "readonly", - "BluetoothRemoteGATTService": "readonly", - "DataView": "readonly", - "E": "readonly", - "Error": "readonly", - "Flash": "readonly", - "fs": "readonly", - "Function": "readonly", - "heatshrink": "readonly", - "I2C": "readonly", - "InternalError": "readonly", - "Math": "readonly", - "Modules": "readonly", - "NRF": "readonly", - "Number": "readonly", - "Object": "readonly", - "OneWire": "readonly", - "Pin": "readonly", - "process": "readonly", - "Promise": "readonly", - "ReferenceError": "readonly", - "RegExp": "readonly", - "Serial": "readonly", - "SPI": "readonly", - "Storage": "readonly", - "StorageFile": "readonly", - "String": "readonly", - "SyntaxError": "readonly", - "tensorflow": "readonly", - "TFMicroInterpreter": "readonly", - "TypeError": "readonly", - "Uint16Array": "readonly", - "Uint24Array": "readonly", - "Uint32Array": "readonly", - "Uint8Array": "readonly", - "Uint8ClampedArray": "readonly", - "Waveform": "readonly", - // Methods and Fields at https://banglejs.com/reference - "analogRead": "readonly", - "analogWrite": "readonly", - "arguments": "readonly", - "atob": "readonly", - "Bluetooth": "readonly", - "BTN": "readonly", - "BTN1": "readonly", - "BTN2": "readonly", - "BTN3": "readonly", - "BTN4": "readonly", - "BTN5": "readonly", - "btoa": "readonly", - "changeInterval": "readonly", - "clearInterval": "readonly", - "clearTimeout": "readonly", - "clearWatch": "readonly", - "decodeURIComponent": "readonly", - "digitalPulse": "readonly", - "digitalRead": "readonly", - "digitalWrite": "readonly", - "dump": "readonly", - "echo": "readonly", - "edit": "readonly", - "encodeURIComponent": "readonly", - "eval": "readonly", - "getPinMode": "readonly", - "getSerial": "readonly", - "getTime": "readonly", - "global": "readonly", - "HIGH": "readonly", - "I2C1": "readonly", - "Infinity": "readonly", - "isFinite": "readonly", - "isNaN": "readonly", - "LED": "readonly", - "LED1": "readonly", - "LED2": "readonly", - "load": "readonly", - "LoopbackA": "readonly", - "LoopbackB": "readonly", - "LOW": "readonly", - "NaN": "readonly", - "parseFloat": "readonly", - "parseInt": "readonly", - "peek16": "readonly", - "peek32": "readonly", - "peek8": "readonly", - "pinMode": "readonly", - "poke16": "readonly", - "poke32": "readonly", - "poke8": "readonly", - "print": "readonly", - "require": "readonly", - "reset": "readonly", - "save": "readonly", - "Serial1": "readonly", - "setBusyIndicator": "readonly", - "setInterval": "readonly", - "setSleepIndicator": "readonly", - "setTime": "readonly", - "setTimeout": "readonly", - "setWatch": "readonly", - "shiftOut": "readonly", - "SPI1": "readonly", - "Terminal": "readonly", - "trace": "readonly", - "VIBRATE": "readonly", +/* { + // Methods and Fields at https://banglejs.com/reference + "Array": "readonly", + "ArrayBuffer": "readonly", + "ArrayBufferView": "readonly", + "Bangle": "readonly", + "BluetoothDevice": "readonly", + "BluetoothRemoteGATTCharacteristic": "readonly", + "BluetoothRemoteGATTServer": "readonly", + "BluetoothRemoteGATTService": "readonly", + "Boolean": "readonly", + "console": "readonly", + "DataView": "readonly", + "Date": "readonly", + "E": "readonly", + "Error": "readonly", + "Flash": "readonly", + "Float32Array": "readonly", + "Float64Array": "readonly", + "fs": "readonly", + "Function": "readonly", + "Graphics": "readonly", // partly done + "heatshrink": "readonly", + "I2C": "readonly", + "Int16Array": "readonly", + "Int32Array": "readonly", + "Int8Array": "readonly", + "InternalError": "readonly", + "JSON": "readonly", + "Math": "readonly", + "Modules": "readonly", + "NRF": "readonly", + "Number": "readonly", + "Object": "readonly", + "OneWire": "readonly", + "Pin": "readonly", + "process": "readonly", + "Promise": "readonly", + "ReferenceError": "readonly", + "RegExp": "readonly", + "Serial": "readonly", + "SPI": "readonly", + "Storage": "readonly", + "StorageFile": "readonly", + "String": "readonly", + "SyntaxError": "readonly", + "tensorflow": "readonly", + "TFMicroInterpreter": "readonly", + "TypeError": "readonly", + "Uint16Array": "readonly", + "Uint24Array": "readonly", + "Uint32Array": "readonly", + "Uint8Array": "readonly", + "Uint8ClampedArray": "readonly", + "Waveform": "readonly", + // Methods and Fields at https://banglejs.com/reference + "analogRead": "readonly", + "analogWrite": "readonly", + "arguments": "readonly", + "atob": "readonly", + "Bluetooth": "readonly", + "BTN": "readonly", + "BTN1": "readonly", + "BTN2": "readonly", + "BTN3": "readonly", + "BTN4": "readonly", + "BTN5": "readonly", + "btoa": "readonly", + "changeInterval": "readonly", + "clearInterval": "readonly", + "clearTimeout": "readonly", + "clearWatch": "readonly", + "decodeURIComponent": "readonly", + "digitalPulse": "readonly", + "digitalRead": "readonly", + "digitalWrite": "readonly", + "dump": "readonly", + "echo": "readonly", + "edit": "readonly", + "encodeURIComponent": "readonly", + "eval": "readonly", + "getPinMode": "readonly", + "getSerial": "readonly", + "getTime": "readonly", + "global": "readonly", + "HIGH": "readonly", + "I2C1": "readonly", + "Infinity": "readonly", + "isFinite": "readonly", + "isNaN": "readonly", + "LED": "readonly", + "LED1": "readonly", + "LED2": "readonly", + "load": "readonly", + "LoopbackA": "readonly", + "LoopbackB": "readonly", + "LOW": "readonly", + "NaN": "readonly", + "parseFloat": "readonly", + "parseInt": "readonly", + "peek16": "readonly", + "peek32": "readonly", + "peek8": "readonly", + "pinMode": "readonly", + "poke16": "readonly", + "poke32": "readonly", + "poke8": "readonly", + "print": "readonly", + "require": "readonly", + "reset": "readonly", + "save": "readonly", + "Serial1": "readonly", + "setBusyIndicator": "readonly", + "setInterval": "readonly", + "setSleepIndicator": "readonly", + "setTime": "readonly", + "setTimeout": "readonly", + "setWatch": "readonly", + "shiftOut": "readonly", + "SPI1": "readonly", + "Terminal": "readonly", + "trace": "readonly", + "VIBRATE": "readonly", + // Aliases and not defined at https://banglejs.com/reference + "g": "readonly", // done + "WIDGETS": "readonly" // done + } */ -export type loadGlobals = {}; +// ambient JS definitions -declare global { - const Bangle: { - // functions - buzz: () => void; - drawWidgets: () => void; - isCharging: () => boolean; - // events - on(event: 'charging', listener: (charging: boolean) => void): void; - // TODO add more - }; +declare const require: ((module: 'heatshrink') => { + decompress: (compressedString: string) => string; +}) & // TODO add more + ((module: 'otherString') => {}); - type Image = { - width: number; - height: number; - bpp?: number; - buffer: ArrayBuffer | string; - transparent?: number; - palette?: Uint16Array; - }; +// ambient bangle.js definitions - type GraphicsApi = { - reset: () => void; - flip: () => void; - setColor: (color: string) => void; // TODO we can most likely type color more usefully than this - drawImage: ( - image: string | Image | ArrayBuffer, - xOffset: number, - yOffset: number, - options?: { - rotate?: number; - scale?: number; - } - ) => void; - // TODO add more - }; +declare const Bangle: { + // functions + buzz: () => void; + drawWidgets: () => void; + isCharging: () => boolean; + // events + on(event: 'charging', listener: (charging: boolean) => void): void; + // TODO add more +}; - const Graphics: GraphicsApi; - const g: GraphicsApi; +declare type Image = { + width: number; + height: number; + bpp?: number; + buffer: ArrayBuffer | string; + transparent?: number; + palette?: Uint16Array; +}; - type Widget = { - area: 'tr' | 'tl'; - width: number; - draw: () => void; - }; - const WIDGETS: { [key: string]: Widget }; -} +declare type GraphicsApi = { + reset: () => void; + flip: () => void; + setColor: (color: string) => void; // TODO we can most likely type color more usefully than this + drawImage: ( + image: string | Image | ArrayBuffer, + xOffset: number, + yOffset: number, + options?: { + rotate?: number; + scale?: number; + } + ) => void; + // TODO add more +}; + +declare const Graphics: GraphicsApi; +declare const g: GraphicsApi; + +declare type Widget = { + area: 'tr' | 'tl'; + width: number; + draw: () => void; +}; +declare const WIDGETS: { [key: string]: Widget }; From 15d24ac1b3f5a1412adda885b116894d47c749a2 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 21:36:42 +0100 Subject: [PATCH 09/35] update TS rules to make them stricter --- apps/widChargingStatus/dist/widget.js | 19 +++++++++++-------- apps/widChargingStatus/widget.ts | 21 ++++++++++++--------- typescript/tsconfig.json | 11 ++++++++++- typescript/types/globals.d.ts | 2 +- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/apps/widChargingStatus/dist/widget.js b/apps/widChargingStatus/dist/widget.js index eea96ce58..6cac1931f 100644 --- a/apps/widChargingStatus/dist/widget.js +++ b/apps/widChargingStatus/dist/widget.js @@ -16,14 +16,17 @@ draw: draw }; Bangle.on('charging', function (charging) { - if (charging) { - Bangle.buzz(); - WIDGETS.chargingStatus.width = iconWidth; + var widget = WIDGETS.chargingStatus; + if (widget) { + if (charging) { + Bangle.buzz(); + widget.width = iconWidth; + } + else { + widget.width = 0; + } + Bangle.drawWidgets(); // re-layout widgets + g.flip(); } - else { - WIDGETS.chargingStatus.width = 0; - } - Bangle.drawWidgets(); // re-layout widgets - g.flip(); }); })(); diff --git a/apps/widChargingStatus/widget.ts b/apps/widChargingStatus/widget.ts index a8cf2ed94..712bf4f97 100644 --- a/apps/widChargingStatus/widget.ts +++ b/apps/widChargingStatus/widget.ts @@ -6,7 +6,7 @@ ); const iconWidth = 18; - function draw() { + function draw(this: { x: number; y: number }) { g.reset(); if (Bangle.isCharging()) { g.setColor('#FD0'); @@ -19,17 +19,20 @@ WIDGETS.chargingStatus = { area: 'tr', width: Bangle.isCharging() ? iconWidth : 0, - draw: draw, + draw, }; Bangle.on('charging', (charging) => { - if (charging) { - Bangle.buzz(); - WIDGETS.chargingStatus.width = iconWidth; - } else { - WIDGETS.chargingStatus.width = 0; + const widget = WIDGETS.chargingStatus; + if (widget) { + if (charging) { + Bangle.buzz(); + widget.width = iconWidth; + } else { + widget.width = 0; + } + Bangle.drawWidgets(); // re-layout widgets + g.flip(); } - Bangle.drawWidgets(); // re-layout widgets - g.flip(); }); })(); diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 8a7ab3342..09101094b 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -2,7 +2,16 @@ "compilerOptions": { "module": "es2015", "noImplicitAny": true, - "target": "es2015" + "target": "es2015", + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "strict": true }, "include": ["../apps/**/*", "./**/*"] } diff --git a/typescript/types/globals.d.ts b/typescript/types/globals.d.ts index 359d5d294..46d1e3b0a 100644 --- a/typescript/types/globals.d.ts +++ b/typescript/types/globals.d.ts @@ -178,6 +178,6 @@ declare const g: GraphicsApi; declare type Widget = { area: 'tr' | 'tl'; width: number; - draw: () => void; + draw: (this: { x: number; y: number }) => void; }; declare const WIDGETS: { [key: string]: Widget }; From 96b099b10ac58143d15b0ea28e1476a81d573c57 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 21:51:35 +0100 Subject: [PATCH 10/35] make tsconfig work for all ts apps --- .github/workflows/nodejs.yml | 9 +++++++-- apps.json | 2 +- apps/widChargingStatus/{dist => }/widget.js | 15 ++++++++------- typescript/package.json | 2 +- typescript/tsconfig.json | 3 ++- 5 files changed, 19 insertions(+), 12 deletions(-) rename apps/widChargingStatus/{dist => }/widget.js (61%) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index e2a12cc51..8187fc890 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -16,7 +16,12 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: npm i - run: npm i + - name: npm ci + working-directory: ./typescript + run: npm ci - name: build types + working-directory: ./typescript + run: npm run build:types + - name: build all TS apps + working-directory: ./typescript run: npm run build:types diff --git a/apps.json b/apps.json index 58a67d8c2..6e85c19d7 100644 --- a/apps.json +++ b/apps.json @@ -4763,7 +4763,7 @@ "tags": "widget", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"widChargingStatus.wid.js","url":"./dist/widget.js"} + {"name":"widChargingStatus.wid.js","url":"./widget.js"} ] }, { diff --git a/apps/widChargingStatus/dist/widget.js b/apps/widChargingStatus/widget.js similarity index 61% rename from apps/widChargingStatus/dist/widget.js rename to apps/widChargingStatus/widget.js index 6cac1931f..68a7c0aca 100644 --- a/apps/widChargingStatus/dist/widget.js +++ b/apps/widChargingStatus/widget.js @@ -1,22 +1,23 @@ -(function () { - var icon = require('heatshrink').decompress(atob('ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA')); - var iconWidth = 18; +"use strict"; +(() => { + const icon = require('heatshrink').decompress(atob('ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA')); + const iconWidth = 18; function draw() { g.reset(); if (Bangle.isCharging()) { g.setColor('#FD0'); g.drawImage(icon, this.x + 1, this.y + 1, { - scale: 0.6875 + scale: 0.6875, }); } } WIDGETS.chargingStatus = { area: 'tr', width: Bangle.isCharging() ? iconWidth : 0, - draw: draw + draw, }; - Bangle.on('charging', function (charging) { - var widget = WIDGETS.chargingStatus; + Bangle.on('charging', (charging) => { + const widget = WIDGETS.chargingStatus; if (widget) { if (charging) { Bangle.buzz(); diff --git a/typescript/package.json b/typescript/package.json index 83ea7d82b..4bfb88d27 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -7,7 +7,7 @@ "typescript": "4.5.2" }, "scripts": { - "build:example": "tsc ../apps/widChargingStatus/widget.ts --outDir ../apps/widChargingStatus/dist", + "build:apps": "tsc", "build:types": "tsc ./types/globals.d.ts" } } diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 09101094b..aff7a6d38 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -13,5 +13,6 @@ "noUnusedParameters": true, "strict": true }, - "include": ["../apps/**/*", "./**/*"] + "include": ["../apps/**/*", "./**/*"], + "exclude": ["../apps/banglerun", "../apps/hebrew_calendar"] } From a393d573d644993927b4155c0c5c6ca570cb88a0 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 21:52:26 +0100 Subject: [PATCH 11/35] Update nodejs.yml --- .github/workflows/nodejs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 8187fc890..a9ada5e5e 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -21,7 +21,7 @@ jobs: run: npm ci - name: build types working-directory: ./typescript - run: npm run build:types + run: npm run build:apps - name: build all TS apps working-directory: ./typescript run: npm run build:types From d7be82bcc71a2445993e7adcec8074142cfa6038 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:01:01 +0100 Subject: [PATCH 12/35] Update README.md --- typescript/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/README.md b/typescript/README.md index 9b38459ae..66506924e 100644 --- a/typescript/README.md +++ b/typescript/README.md @@ -22,7 +22,7 @@ npm ci to install the project's build tools, and: ``` -npx tsc ../apps/relativePathToYourApp/app.ts --outDir ../apps/relativePathToYourApp/dist +npm run build:apps ``` -To build your app. The last command will generate the `app.js` file containing the transpiled code for the BangleJS. +To build all Typescript apps. The last command will generate the `app.js` files containing the transpiled code for the BangleJS. From a86f2c108dfc119de10d8ac3b65e1bc21009649b Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:02:41 +0100 Subject: [PATCH 13/35] Update README.md --- typescript/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/typescript/README.md b/typescript/README.md index 66506924e..d1f60fd0b 100644 --- a/typescript/README.md +++ b/typescript/README.md @@ -6,7 +6,8 @@ The goal is to have types for everything, but that will take some time. Feel fre ## Using the types -TODO +All currently typed modules can be found in `/typescript/types.globals.d.ts`. +The typing is an ongoing process. If anything is still missing, you can add it! It will automatically be available in your TS files. ## Compilation From 4990c426752586600ebb08ae472d71cbe2ed22c4 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:04:43 +0100 Subject: [PATCH 14/35] Update tsconfig.json --- typescript/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index aff7a6d38..40537c680 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -14,5 +14,6 @@ "strict": true }, "include": ["../apps/**/*", "./**/*"], + // these apps have been excluded because they were built before this configuration was created and are using their own "exclude": ["../apps/banglerun", "../apps/hebrew_calendar"] } From 4511520c88c4f4e2174639c41bb24195f3a82d83 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:17:06 +0100 Subject: [PATCH 15/35] upgrade chargingStatus version --- apps.json | 2 +- apps/widChargingStatus/ChangeLog | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps.json b/apps.json index 3466ab0fb..0a6cebba7 100644 --- a/apps.json +++ b/apps.json @@ -4782,7 +4782,7 @@ "name": "Charging Status", "shortName":"ChargingStatus", "icon": "widget.png", - "version":"0.1", + "version":"0.2", "type": "widget", "description": "A simple widget that shows a yellow lightning icon to indicate whenever the watch is charging. This way one can see the charging status at a glance, no matter which battery widget is being used.", "tags": "widget", diff --git a/apps/widChargingStatus/ChangeLog b/apps/widChargingStatus/ChangeLog index d3175e1ab..ceb7cb883 100644 --- a/apps/widChargingStatus/ChangeLog +++ b/apps/widChargingStatus/ChangeLog @@ -1 +1,2 @@ -0.1: First release. \ No newline at end of file +0.1: First release. +0.2: No functional changes, just moved codebase to Typescript. \ No newline at end of file From d255d42a8c34b70c762cd8f4f3197aedfcf78a21 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:27:25 +0100 Subject: [PATCH 16/35] disable strict to see if that fixes widget --- apps/widChargingStatus/widget.js | 1 - typescript/tsconfig.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/widChargingStatus/widget.js b/apps/widChargingStatus/widget.js index 68a7c0aca..042e225f7 100644 --- a/apps/widChargingStatus/widget.js +++ b/apps/widChargingStatus/widget.js @@ -1,4 +1,3 @@ -"use strict"; (() => { const icon = require('heatshrink').decompress(atob('ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA')); const iconWidth = 18; diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 40537c680..114e01ac3 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -11,7 +11,7 @@ "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "noUnusedParameters": true, - "strict": true + "noImplicitUseStrict": true }, "include": ["../apps/**/*", "./**/*"], // these apps have been excluded because they were built before this configuration was created and are using their own From 0ece5ccdb0d8f61b963c7473ef00c47466b86900 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:32:36 +0100 Subject: [PATCH 17/35] more testing to get app back running --- apps.json | 2 +- apps/widChargingStatus/widget.js | 2 +- apps/widChargingStatus/widget.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps.json b/apps.json index 0a6cebba7..6f53c0c48 100644 --- a/apps.json +++ b/apps.json @@ -4782,7 +4782,7 @@ "name": "Charging Status", "shortName":"ChargingStatus", "icon": "widget.png", - "version":"0.2", + "version":"0.3", "type": "widget", "description": "A simple widget that shows a yellow lightning icon to indicate whenever the watch is charging. This way one can see the charging status at a glance, no matter which battery widget is being used.", "tags": "widget", diff --git a/apps/widChargingStatus/widget.js b/apps/widChargingStatus/widget.js index 042e225f7..386b84947 100644 --- a/apps/widChargingStatus/widget.js +++ b/apps/widChargingStatus/widget.js @@ -13,7 +13,7 @@ WIDGETS.chargingStatus = { area: 'tr', width: Bangle.isCharging() ? iconWidth : 0, - draw, + draw: draw, }; Bangle.on('charging', (charging) => { const widget = WIDGETS.chargingStatus; diff --git a/apps/widChargingStatus/widget.ts b/apps/widChargingStatus/widget.ts index 712bf4f97..14b4df4a4 100644 --- a/apps/widChargingStatus/widget.ts +++ b/apps/widChargingStatus/widget.ts @@ -19,7 +19,7 @@ WIDGETS.chargingStatus = { area: 'tr', width: Bangle.isCharging() ? iconWidth : 0, - draw, + draw: draw, }; Bangle.on('charging', (charging) => { From 0499f04dc3de9c1d5725c325ad67ddb6d676b939 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:36:22 +0100 Subject: [PATCH 18/35] try to use strict again --- apps/widChargingStatus/widget.js | 1 + typescript/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/widChargingStatus/widget.js b/apps/widChargingStatus/widget.js index 386b84947..5d9ea3837 100644 --- a/apps/widChargingStatus/widget.js +++ b/apps/widChargingStatus/widget.js @@ -1,3 +1,4 @@ +"use strict"; (() => { const icon = require('heatshrink').decompress(atob('ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA')); const iconWidth = 18; diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 114e01ac3..40537c680 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -11,7 +11,7 @@ "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noImplicitUseStrict": true + "strict": true }, "include": ["../apps/**/*", "./**/*"], // these apps have been excluded because they were built before this configuration was created and are using their own From 8baa3eca7235085698f08c5c8b2501048da1aa44 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:38:26 +0100 Subject: [PATCH 19/35] Update apps.json --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 6f53c0c48..3f2363a31 100644 --- a/apps.json +++ b/apps.json @@ -4782,7 +4782,7 @@ "name": "Charging Status", "shortName":"ChargingStatus", "icon": "widget.png", - "version":"0.3", + "version":"0.4", "type": "widget", "description": "A simple widget that shows a yellow lightning icon to indicate whenever the watch is charging. This way one can see the charging status at a glance, no matter which battery widget is being used.", "tags": "widget", From 5c851714ee17ad55ca6692a6e9ad49e717a16d11 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:43:33 +0100 Subject: [PATCH 20/35] revert chargingStatus version --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 3f2363a31..0a6cebba7 100644 --- a/apps.json +++ b/apps.json @@ -4782,7 +4782,7 @@ "name": "Charging Status", "shortName":"ChargingStatus", "icon": "widget.png", - "version":"0.4", + "version":"0.2", "type": "widget", "description": "A simple widget that shows a yellow lightning icon to indicate whenever the watch is charging. This way one can see the charging status at a glance, no matter which battery widget is being used.", "tags": "widget", From c462547a2bfe283e610ea093bfa34a9cc98faf75 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 22:45:10 +0100 Subject: [PATCH 21/35] fix github actions --- .github/workflows/nodejs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index a9ada5e5e..c268c884c 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -21,7 +21,7 @@ jobs: run: npm ci - name: build types working-directory: ./typescript - run: npm run build:apps + run: npm run build:types - name: build all TS apps working-directory: ./typescript - run: npm run build:types + run: npm run build:apps From fc2c3c86a4c9c68b9ec56f5731775955f710b4c3 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Fri, 10 Dec 2021 23:17:18 +0100 Subject: [PATCH 22/35] document typing progress --- typescript/types/globals.d.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/typescript/types/globals.d.ts b/typescript/types/globals.d.ts index 46d1e3b0a..2ef52dcdf 100644 --- a/typescript/types/globals.d.ts +++ b/typescript/types/globals.d.ts @@ -1,10 +1,12 @@ -// TODO all of these globals (copied from eslintrc need to be typed at some point) -/* { +// TODO all of these globals (copied from eslintrc) need to be typed at some point +/* The typing status is listed on the left of the attribute, e.g.: +status "Attribute" + // Methods and Fields at https://banglejs.com/reference "Array": "readonly", "ArrayBuffer": "readonly", "ArrayBufferView": "readonly", - "Bangle": "readonly", +started "Bangle": "readonly", "BluetoothDevice": "readonly", "BluetoothRemoteGATTCharacteristic": "readonly", "BluetoothRemoteGATTServer": "readonly", @@ -20,8 +22,8 @@ "Float64Array": "readonly", "fs": "readonly", "Function": "readonly", - "Graphics": "readonly", // partly done - "heatshrink": "readonly", +started "Graphics": "readonly", +done "heatshrink": "readonly", "I2C": "readonly", "Int16Array": "readonly", "Int32Array": "readonly", @@ -107,7 +109,7 @@ "poke32": "readonly", "poke8": "readonly", "print": "readonly", - "require": "readonly", +started "require": "readonly", "reset": "readonly", "save": "readonly", "Serial1": "readonly", @@ -123,9 +125,8 @@ "trace": "readonly", "VIBRATE": "readonly", // Aliases and not defined at https://banglejs.com/reference - "g": "readonly", // done - "WIDGETS": "readonly" // done - } +done "g": "readonly", +done "WIDGETS": "readonly" */ // ambient JS definitions From 4dbec88b7f1e4bb741916fbaeb3c156b2c95fd08 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Tue, 14 Dec 2021 21:42:58 +0100 Subject: [PATCH 23/35] Port banglerun to new typescript system --- apps/banglerun/README.md | 19 +------------------ apps/banglerun/{src => }/activity.ts | 0 apps/banglerun/{src => }/app.ts | 0 apps/banglerun/{src => }/display.ts | 0 apps/banglerun/{src => }/gps.ts | 0 apps/banglerun/{src => }/hrm.ts | 0 apps/banglerun/{src => }/log.ts | 8 +++++--- apps/banglerun/package.json | 27 --------------------------- apps/banglerun/{src => }/state.ts | 18 +++++++++++++----- apps/banglerun/{src => }/step.ts | 0 apps/banglerun/tsconfig.json | 10 ---------- apps/banglerun/tsconfig.spec.json | 10 ---------- typescript/tsconfig.json | 4 ++-- 13 files changed, 21 insertions(+), 75 deletions(-) rename apps/banglerun/{src => }/activity.ts (100%) rename apps/banglerun/{src => }/app.ts (100%) rename apps/banglerun/{src => }/display.ts (100%) rename apps/banglerun/{src => }/gps.ts (100%) rename apps/banglerun/{src => }/hrm.ts (100%) rename apps/banglerun/{src => }/log.ts (80%) delete mode 100644 apps/banglerun/package.json rename apps/banglerun/{src => }/state.ts (80%) rename apps/banglerun/{src => }/step.ts (100%) delete mode 100644 apps/banglerun/tsconfig.json delete mode 100644 apps/banglerun/tsconfig.spec.json diff --git a/apps/banglerun/README.md b/apps/banglerun/README.md index 80e984bfa..99fbaaf1a 100644 --- a/apps/banglerun/README.md +++ b/apps/banglerun/README.md @@ -5,21 +5,4 @@ An app for running sessions. Displays info and logs your run for later viewing. ## Compilation The app is written in Typescript, and needs to be transpiled in order to be -run on the BangleJS. The easiest way to perform this step is by using the -ubiquitous [NPM package manager](https://www.npmjs.com/get-npm). - -After having installed NPM for your platform, checkout the `BangleApps` repo, -open a terminal, and navigate into the `apps/banglerun` folder. Then issue: - -``` -npm i -``` - -to install the project's build tools, and: - -``` -npm run build -``` - -To build the app. The last command will generate the `app.js` file, containing -the transpiled code for the BangleJS. +run on the BangleJS. See ../../typescript/README.md for instructions. diff --git a/apps/banglerun/src/activity.ts b/apps/banglerun/activity.ts similarity index 100% rename from apps/banglerun/src/activity.ts rename to apps/banglerun/activity.ts diff --git a/apps/banglerun/src/app.ts b/apps/banglerun/app.ts similarity index 100% rename from apps/banglerun/src/app.ts rename to apps/banglerun/app.ts diff --git a/apps/banglerun/src/display.ts b/apps/banglerun/display.ts similarity index 100% rename from apps/banglerun/src/display.ts rename to apps/banglerun/display.ts diff --git a/apps/banglerun/src/gps.ts b/apps/banglerun/gps.ts similarity index 100% rename from apps/banglerun/src/gps.ts rename to apps/banglerun/gps.ts diff --git a/apps/banglerun/src/hrm.ts b/apps/banglerun/hrm.ts similarity index 100% rename from apps/banglerun/src/hrm.ts rename to apps/banglerun/hrm.ts diff --git a/apps/banglerun/src/log.ts b/apps/banglerun/log.ts similarity index 80% rename from apps/banglerun/src/log.ts rename to apps/banglerun/log.ts index b6714e407..282115e1a 100644 --- a/apps/banglerun/src/log.ts +++ b/apps/banglerun/log.ts @@ -1,17 +1,19 @@ -import { AppState } from './state'; +import { AppState, AppStateWithLog } from './state'; declare var require: any; -function initLog(state: AppState): void { +function initLog(state: AppState): AppStateWithLog { const datetime = new Date().toISOString().replace(/[-:]/g, ''); const date = datetime.substr(2, 6); const time = datetime.substr(9, 6); const filename = `banglerun_${date}_${time}`; + state = state; state.file = require('Storage').open(filename, 'w'); state.fileWritten = false; + return state; } -function updateLog(state: AppState): void { +function updateLog(state: AppStateWithLog): void { if (!state.fileWritten) { state.file.write([ 'timestamp', diff --git a/apps/banglerun/package.json b/apps/banglerun/package.json deleted file mode 100644 index 1f5cc677b..000000000 --- a/apps/banglerun/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "banglerun", - "version": "0.5.0", - "description": "Bangle.js app for running sessions", - "main": "app.js", - "types": "app.d.ts", - "scripts": { - "build": "rollup -c", - "test": "ts-node -P tsconfig.spec.json node_modules/jasmine/bin/jasmine --config=jasmine.json" - }, - "author": { - "name": "Stefano Baldan", - "email": "singintime@gmail.com" - }, - "license": "ISC", - "devDependencies": { - "@rollup/plugin-typescript": "^4.1.1", - "@types/jasmine": "^3.5.10", - "jasmine": "^3.5.0", - "rollup": "^2.10.2", - "rollup-plugin-terser": "^5.3.0", - "terser": "^4.7.0", - "ts-node": "^8.10.2", - "tslib": "^2.0.0", - "typescript": "^3.9.2" - } -} diff --git a/apps/banglerun/src/state.ts b/apps/banglerun/state.ts similarity index 80% rename from apps/banglerun/src/state.ts rename to apps/banglerun/state.ts index 14ef2dc5d..1ba9bca26 100644 --- a/apps/banglerun/src/state.ts +++ b/apps/banglerun/state.ts @@ -4,7 +4,7 @@ enum ActivityStatus { Running = 'RUN', } -interface AppState { +interface BasicAppState { // GPS NMEA data fix: number; lat: number; @@ -28,14 +28,12 @@ interface AppState { hrError: number, // Logger data - file: File; fileWritten: boolean; // Drawing data drawing: boolean; // Activity data - status: ActivityStatus; duration: number; distance: number; speed: number; @@ -43,6 +41,17 @@ interface AppState { cadence: number; } +interface AppStateWithoutLog extends BasicAppState { + status: 'STOP'; +} + +interface AppStateWithLog extends BasicAppState { + file: File; + status: ActivityStatus; +} + +type AppState = AppStateWithLog | AppStateWithoutLog; + interface File { read: Function; write: Function; @@ -68,7 +77,6 @@ function initState(): AppState { hr: 60, hrError: 100, - file: null, fileWritten: false, drawing: false, @@ -82,4 +90,4 @@ function initState(): AppState { } } -export { ActivityStatus, AppState, File, initState }; +export { ActivityStatus, AppState, AppStateWithLog, File, initState }; diff --git a/apps/banglerun/src/step.ts b/apps/banglerun/step.ts similarity index 100% rename from apps/banglerun/src/step.ts rename to apps/banglerun/step.ts diff --git a/apps/banglerun/tsconfig.json b/apps/banglerun/tsconfig.json deleted file mode 100644 index a341a5a5e..000000000 --- a/apps/banglerun/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "module": "es2015", - "noImplicitAny": true, - "target": "es2015" - }, - "include": [ - "src" - ] -} diff --git a/apps/banglerun/tsconfig.spec.json b/apps/banglerun/tsconfig.spec.json deleted file mode 100644 index 136ae137b..000000000 --- a/apps/banglerun/tsconfig.spec.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "noImplicitAny": true, - "target": "es2015" - }, - "include": [ - "test" - ] -} diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 40537c680..e9327be68 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -14,6 +14,6 @@ "strict": true }, "include": ["../apps/**/*", "./**/*"], - // these apps have been excluded because they were built before this configuration was created and are using their own - "exclude": ["../apps/banglerun", "../apps/hebrew_calendar"] + // this app is excluded because it was built before this configuration was created and is using its own + "exclude": ["../apps/hebrew_calendar"] } From 7b37391553c654f03a29a95f4f29b9c1849a3925 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 20:58:26 +0100 Subject: [PATCH 24/35] remove unused files from /banglerun, replace banglerun js code with newly compiled code --- apps/banglerun/.gitignore | 1 - apps/banglerun/README.md | 8 --- apps/banglerun/activity.js | 35 ++++++++++++ apps/banglerun/app.js | 14 ++++- apps/banglerun/display.js | 95 +++++++++++++++++++++++++++++++++ apps/banglerun/gps.js | 66 +++++++++++++++++++++++ apps/banglerun/hrm.js | 15 ++++++ apps/banglerun/jasmine.json | 6 --- apps/banglerun/log.js | 36 +++++++++++++ apps/banglerun/rollup.config.js | 15 ------ apps/banglerun/state.js | 33 ++++++++++++ apps/banglerun/step.js | 10 ++++ typescript/tsconfig.json | 4 +- 13 files changed, 304 insertions(+), 34 deletions(-) delete mode 100644 apps/banglerun/.gitignore delete mode 100644 apps/banglerun/README.md create mode 100644 apps/banglerun/activity.js create mode 100644 apps/banglerun/display.js create mode 100644 apps/banglerun/gps.js create mode 100644 apps/banglerun/hrm.js delete mode 100644 apps/banglerun/jasmine.json create mode 100644 apps/banglerun/log.js delete mode 100644 apps/banglerun/rollup.config.js create mode 100644 apps/banglerun/state.js create mode 100644 apps/banglerun/step.js diff --git a/apps/banglerun/.gitignore b/apps/banglerun/.gitignore deleted file mode 100644 index c2658d7d1..000000000 --- a/apps/banglerun/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/apps/banglerun/README.md b/apps/banglerun/README.md deleted file mode 100644 index 99fbaaf1a..000000000 --- a/apps/banglerun/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# BangleRun - -An app for running sessions. Displays info and logs your run for later viewing. - -## Compilation - -The app is written in Typescript, and needs to be transpiled in order to be -run on the BangleJS. See ../../typescript/README.md for instructions. diff --git a/apps/banglerun/activity.js b/apps/banglerun/activity.js new file mode 100644 index 000000000..818f9cf2a --- /dev/null +++ b/apps/banglerun/activity.js @@ -0,0 +1,35 @@ +import { draw } from './display'; +import { initLog } from './log'; +import { ActivityStatus } from './state'; +function startActivity(state) { + if (state.status === ActivityStatus.Stopped) { + initLog(state); + } + if (state.status === ActivityStatus.Running) { + state.status = ActivityStatus.Paused; + } + else { + state.status = ActivityStatus.Running; + } + draw(state); +} +function stopActivity(state) { + if (state.status === ActivityStatus.Paused) { + clearActivity(state); + } + if (state.status === ActivityStatus.Running) { + state.status = ActivityStatus.Paused; + } + else { + state.status = ActivityStatus.Stopped; + } + draw(state); +} +function clearActivity(state) { + state.duration = 0; + state.distance = 0; + state.speed = 0; + state.steps = 0; + state.cadence = 0; +} +export { clearActivity, startActivity, stopActivity }; diff --git a/apps/banglerun/app.js b/apps/banglerun/app.js index b79255171..af5413cc0 100644 --- a/apps/banglerun/app.js +++ b/apps/banglerun/app.js @@ -1 +1,13 @@ -!function(){"use strict";var t;!function(t){t.Stopped="STOP",t.Paused="PAUSE",t.Running="RUN"}(t||(t={}));const n={STOP:63488,PAUSE:65504,RUN:2016};function e(t,n,e){g.setColor(0),g.fillRect(n-60,e,n+60,e+30),g.setColor(65535),g.drawString(t,n,e)}function i(i){var s;g.setFontVector(30),g.setFontAlign(0,-1,0),e((i.distance/1e3).toFixed(2),60,55),e(function(t){const n=Math.round(t),e=Math.floor(n/3600),i=Math.floor(n/60)%60,s=n%60;return(e?e+":":"")+("0"+i).substr(-2)+":"+("0"+s).substr(-2)}(i.duration),172,55),e(function(t){if(t<.1667)return"__'__\"";const n=Math.round(1e3/t),e=Math.floor(n/60),i=n%60;return("0"+e).substr(-2)+"'"+("0"+i).substr(-2)+'"'}(i.speed),60,115),e(i.hr.toFixed(0),172,115),e(i.steps.toFixed(0),60,175),e(i.cadence.toFixed(0),172,175),g.setFont("6x8",2),g.setColor(i.gpsValid?2016:63488),g.fillRect(0,216,80,240),g.setColor(0),g.drawString("GPS",40,220),g.setColor(65535),g.fillRect(80,216,160,240),g.setColor(0),g.drawString(("0"+(s=new Date).getHours()).substr(-2)+":"+("0"+s.getMinutes()).substr(-2),120,220),g.setColor(n[i.status]),g.fillRect(160,216,230,240),g.setColor(0),g.drawString(i.status,200,220),g.setFont("6x8").setFontAlign(0,0,1).setColor(-1),i.status===t.Paused?g.drawString("START",236,60,1).drawString(" CLEAR ",236,180,1):i.status===t.Running?g.drawString(" PAUSE ",236,60,1).drawString(" PAUSE ",236,180,1):g.drawString("START",236,60,1).drawString(" ",236,180,1)}function s(t){g.clear(),g.setColor(50712),g.setFont("6x8",2),g.setFontAlign(0,-1,0),g.drawString("DIST (KM)",60,32),g.drawString("TIME",180,32),g.drawString("PACE",60,92),g.drawString("HEART",180,92),g.drawString("STEPS",60,152),g.drawString("CADENCE",180,152),i(t),Bangle.drawWidgets()}function a(n){n.status===t.Stopped&&function(t){const n=(new Date).toISOString().replace(/[-:]/g,""),e=`banglerun_${n.substr(2,6)}_${n.substr(9,6)}`;t.file=require("Storage").open(e,"w"),t.fileWritten=!1}(n),n.status===t.Running?n.status=t.Paused:n.status=t.Running,i(n)}const r={fix:NaN,lat:NaN,lon:NaN,alt:NaN,vel:NaN,dop:NaN,gpsValid:!1,x:NaN,y:NaN,z:NaN,t:NaN,timeSinceLog:0,hr:60,hrError:100,file:null,fileWritten:!1,drawing:!1,status:t.Stopped,duration:0,distance:0,speed:0,steps:0,cadence:0};var o;o=r,Bangle.on("GPS",n=>function(n,e){n.lat=e.lat,n.lon=e.lon,n.alt=e.alt,n.vel=e.speed/3.6,n.fix=e.fix,n.dop=e.hdop,n.gpsValid=n.fix>0,function(n){const e=Date.now();let i=(e-n.t)/1e3;if(isFinite(i)||(i=0),n.t=e,n.timeSinceLog+=i,n.status===t.Running&&(n.duration+=i),!n.gpsValid)return;const s=6371008.8+n.alt,a=n.lat*Math.PI/180,r=n.lon*Math.PI/180,o=s*Math.cos(a)*Math.cos(r),g=s*Math.cos(a)*Math.sin(r),d=s*Math.sin(a);if(!n.x)return n.x=o,n.y=g,void(n.z=d);const u=o-n.x,l=g-n.y,c=d-n.z,f=Math.sqrt(u*u+l*l+c*c);n.x=o,n.y=g,n.z=d,n.status===t.Running&&(n.distance+=f,n.speed=n.distance/n.duration||0,n.cadence=60*n.steps/n.duration||0)}(n),i(n),n.gpsValid&&n.status===t.Running&&n.timeSinceLog>5&&(n.timeSinceLog=0,function(t){t.fileWritten||(t.file.write(["timestamp","latitude","longitude","altitude","duration","distance","heartrate","steps"].join(",")+"\n"),t.fileWritten=!0),t.file.write([Date.now().toFixed(0),t.lat.toFixed(6),t.lon.toFixed(6),t.alt.toFixed(2),t.duration.toFixed(0),t.distance.toFixed(2),t.hr.toFixed(0),t.steps.toFixed(0)].join(",")+"\n")}(n))}(o,n)),Bangle.setGPSPower(1),function(t){Bangle.on("HRM",n=>function(t,n){if(0===n.confidence)return;const e=n.bpm-t.hr,i=Math.abs(e)+101-n.confidence,s=t.hrError/(t.hrError+i)||0;t.hr+=e*s,t.hrError+=(i-t.hrError)*s}(t,n)),Bangle.setHRMPower(1)}(r),function(n){Bangle.on("step",()=>function(n){n.status===t.Running&&(n.steps+=1)}(n))}(r),function(t){Bangle.loadWidgets(),Bangle.on("lcdPower",n=>{t.drawing=n,n&&s(t)}),s(t)}(r),setWatch(()=>a(r),BTN1,{repeat:!0,edge:"falling"}),setWatch(()=>function(n){n.status===t.Paused&&function(t){t.duration=0,t.distance=0,t.speed=0,t.steps=0,t.cadence=0}(n),n.status===t.Running?n.status=t.Paused:n.status=t.Stopped,i(n)}(r),BTN3,{repeat:!0,edge:"falling"})}(); +import { startActivity, stopActivity } from './activity'; +import { initDisplay } from './display'; +import { initGps } from './gps'; +import { initHrm } from './hrm'; +import { initState } from './state'; +import { initStep } from './step'; +const appState = initState(); +initGps(appState); +initHrm(appState); +initStep(appState); +initDisplay(appState); +setWatch(() => startActivity(appState), BTN1, { repeat: true, edge: 'falling' }); +setWatch(() => stopActivity(appState), BTN3, { repeat: true, edge: 'falling' }); diff --git a/apps/banglerun/display.js b/apps/banglerun/display.js new file mode 100644 index 000000000..2768e8973 --- /dev/null +++ b/apps/banglerun/display.js @@ -0,0 +1,95 @@ +import { ActivityStatus } from './state'; +const STATUS_COLORS = { + 'STOP': 0xF800, + 'PAUSE': 0xFFE0, + 'RUN': 0x07E0, +}; +function initDisplay(state) { + Bangle.loadWidgets(); + Bangle.on('lcdPower', (on) => { + state.drawing = on; + if (on) { + drawAll(state); + } + }); + drawAll(state); +} +function drawBackground() { + g.clear(); + g.setColor(0xC618); + g.setFont('6x8', 2); + g.setFontAlign(0, -1, 0); + g.drawString('DIST (KM)', 60, 32); + g.drawString('TIME', 172, 32); + g.drawString('PACE', 60, 92); + g.drawString('HEART', 172, 92); + g.drawString('STEPS', 60, 152); + g.drawString('CADENCE', 172, 152); +} +function drawValue(value, x, y) { + g.setColor(0x0000); + g.fillRect(x - 60, y, x + 60, y + 30); + g.setColor(0xFFFF); + g.drawString(value, x, y); +} +function draw(state) { + g.setFontVector(30); + g.setFontAlign(0, -1, 0); + drawValue(formatDistance(state.distance), 60, 55); + drawValue(formatTime(state.duration), 172, 55); + drawValue(formatPace(state.speed), 60, 115); + drawValue(state.hr.toFixed(0), 172, 115); + drawValue(state.steps.toFixed(0), 60, 175); + drawValue(state.cadence.toFixed(0), 172, 175); + g.setFont('6x8', 2); + g.setColor(state.gpsValid ? 0x07E0 : 0xF800); + g.fillRect(0, 216, 80, 240); + g.setColor(0x0000); + g.drawString('GPS', 40, 220); + g.setColor(0xFFFF); + g.fillRect(80, 216, 160, 240); + g.setColor(0x0000); + g.drawString(formatClock(new Date()), 120, 220); + g.setColor(STATUS_COLORS[state.status]); + g.fillRect(160, 216, 230, 240); + g.setColor(0x0000); + g.drawString(state.status, 200, 220); + g.setFont("6x8").setFontAlign(0, 0, 1).setColor(-1); + if (state.status === ActivityStatus.Paused) { + g.drawString("START", 236, 60, 1).drawString(" CLEAR ", 236, 180, 1); + } + else if (state.status === ActivityStatus.Running) { + g.drawString(" PAUSE ", 236, 60, 1).drawString(" PAUSE ", 236, 180, 1); + } + else { + g.drawString("START", 236, 60, 1).drawString(" ", 236, 180, 1); + } +} +function drawAll(state) { + drawBackground(); + draw(state); + Bangle.drawWidgets(); +} +function formatClock(date) { + return ('0' + date.getHours()).substr(-2) + ':' + ('0' + date.getMinutes()).substr(-2); +} +function formatDistance(meters) { + return (meters / 1000).toFixed(2); +} +function formatPace(speed) { + if (speed < 0.1667) { + return `__'__"`; + } + const pace = Math.round(1000 / speed); + const min = Math.floor(pace / 60); + const sec = pace % 60; + return ('0' + min).substr(-2) + `'` + ('0' + sec).substr(-2) + `"`; +} +function formatTime(time) { + const seconds = Math.round(time); + const hrs = Math.floor(seconds / 3600); + const min = Math.floor(seconds / 60) % 60; + const sec = seconds % 60; + return (hrs ? hrs + ':' : '') + ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2); +} +export { draw, drawAll, drawBackground, drawValue, formatClock, formatDistance, formatPace, formatTime, initDisplay, }; diff --git a/apps/banglerun/gps.js b/apps/banglerun/gps.js new file mode 100644 index 000000000..d06215cd5 --- /dev/null +++ b/apps/banglerun/gps.js @@ -0,0 +1,66 @@ +import { draw } from './display'; +import { updateLog } from './log'; +import { ActivityStatus } from './state'; +const EARTH_RADIUS = 6371008.8; +function initGps(state) { + Bangle.on('GPS', (gps) => readGps(state, gps)); + Bangle.setGPSPower(1); +} +function readGps(state, gps) { + state.lat = gps.lat; + state.lon = gps.lon; + state.alt = gps.alt; + state.vel = gps.speed / 3.6; + state.fix = gps.fix; + state.dop = gps.hdop; + state.gpsValid = state.fix > 0; + updateGps(state); + draw(state); + /* Only log GPS data every 5 secs if we + have a fix and we're running. */ + if (state.gpsValid && + state.status === ActivityStatus.Running && + state.timeSinceLog > 5) { + state.timeSinceLog = 0; + updateLog(state); + } +} +function updateGps(state) { + const t = Date.now(); + let dt = (t - state.t) / 1000; + if (!isFinite(dt)) + dt = 0; + state.t = t; + state.timeSinceLog += dt; + if (state.status === ActivityStatus.Running) { + state.duration += dt; + } + if (!state.gpsValid) { + return; + } + const r = EARTH_RADIUS + state.alt; + const lat = state.lat * Math.PI / 180; + const lon = state.lon * Math.PI / 180; + const x = r * Math.cos(lat) * Math.cos(lon); + const y = r * Math.cos(lat) * Math.sin(lon); + const z = r * Math.sin(lat); + if (!state.x) { + state.x = x; + state.y = y; + state.z = z; + return; + } + const dx = x - state.x; + const dy = y - state.y; + const dz = z - state.z; + const dpMag = Math.sqrt(dx * dx + dy * dy + dz * dz); + state.x = x; + state.y = y; + state.z = z; + if (state.status === ActivityStatus.Running) { + state.distance += dpMag; + state.speed = (state.distance / state.duration) || 0; + state.cadence = (60 * state.steps / state.duration) || 0; + } +} +export { initGps, readGps, updateGps }; diff --git a/apps/banglerun/hrm.js b/apps/banglerun/hrm.js new file mode 100644 index 000000000..35804f5e8 --- /dev/null +++ b/apps/banglerun/hrm.js @@ -0,0 +1,15 @@ +function initHrm(state) { + Bangle.on('HRM', (hrm) => updateHrm(state, hrm)); + Bangle.setHRMPower(1); +} +function updateHrm(state, hrm) { + if (hrm.confidence === 0) { + return; + } + const dHr = hrm.bpm - state.hr; + const hrError = Math.abs(dHr) + 101 - hrm.confidence; + const hrGain = (state.hrError / (state.hrError + hrError)) || 0; + state.hr += dHr * hrGain; + state.hrError += (hrError - state.hrError) * hrGain; +} +export { initHrm, updateHrm }; diff --git a/apps/banglerun/jasmine.json b/apps/banglerun/jasmine.json deleted file mode 100644 index 813363b27..000000000 --- a/apps/banglerun/jasmine.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spec_dir": "test", - "spec_files": [ - "**/*.spec.ts" - ] -} \ No newline at end of file diff --git a/apps/banglerun/log.js b/apps/banglerun/log.js new file mode 100644 index 000000000..b11409de6 --- /dev/null +++ b/apps/banglerun/log.js @@ -0,0 +1,36 @@ +function initLog(state) { + const datetime = new Date().toISOString().replace(/[-:]/g, ''); + const date = datetime.substr(2, 6); + const time = datetime.substr(9, 6); + const filename = `banglerun_${date}_${time}`; + state = state; + state.file = require('Storage').open(filename, 'w'); + state.fileWritten = false; + return state; +} +function updateLog(state) { + if (!state.fileWritten) { + state.file.write([ + 'timestamp', + 'latitude', + 'longitude', + 'altitude', + 'duration', + 'distance', + 'heartrate', + 'steps', + ].join(',') + '\n'); + state.fileWritten = true; + } + state.file.write([ + Date.now().toFixed(0), + state.lat.toFixed(6), + state.lon.toFixed(6), + state.alt.toFixed(2), + state.duration.toFixed(0), + state.distance.toFixed(2), + state.hr.toFixed(0), + state.steps.toFixed(0), + ].join(',') + '\n'); +} +export { initLog, updateLog }; diff --git a/apps/banglerun/rollup.config.js b/apps/banglerun/rollup.config.js deleted file mode 100644 index f7027eb2b..000000000 --- a/apps/banglerun/rollup.config.js +++ /dev/null @@ -1,15 +0,0 @@ -import typescript from '@rollup/plugin-typescript'; -import { terser } from 'rollup-plugin-terser'; - -export default { - input: './src/app.ts', - output: { - dir: '.', - format: 'iife', - name: 'banglerun' - }, - plugins: [ - typescript(), - terser(), - ] -}; diff --git a/apps/banglerun/state.js b/apps/banglerun/state.js new file mode 100644 index 000000000..8629d69a7 --- /dev/null +++ b/apps/banglerun/state.js @@ -0,0 +1,33 @@ +var ActivityStatus; +(function (ActivityStatus) { + ActivityStatus["Stopped"] = "STOP"; + ActivityStatus["Paused"] = "PAUSE"; + ActivityStatus["Running"] = "RUN"; +})(ActivityStatus || (ActivityStatus = {})); +function initState() { + return { + fix: NaN, + lat: NaN, + lon: NaN, + alt: NaN, + vel: NaN, + dop: NaN, + gpsValid: false, + x: NaN, + y: NaN, + z: NaN, + t: NaN, + timeSinceLog: 0, + hr: 60, + hrError: 100, + fileWritten: false, + drawing: false, + status: ActivityStatus.Stopped, + duration: 0, + distance: 0, + speed: 0, + steps: 0, + cadence: 0, + }; +} +export { ActivityStatus, initState }; diff --git a/apps/banglerun/step.js b/apps/banglerun/step.js new file mode 100644 index 000000000..b258a853d --- /dev/null +++ b/apps/banglerun/step.js @@ -0,0 +1,10 @@ +import { ActivityStatus } from './state'; +function initStep(state) { + Bangle.on('step', () => updateStep(state)); +} +function updateStep(state) { + if (state.status === ActivityStatus.Running) { + state.steps += 1; + } +} +export { initStep, updateStep }; diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index e9327be68..7def102b7 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -13,7 +13,5 @@ "noUnusedParameters": true, "strict": true }, - "include": ["../apps/**/*", "./**/*"], - // this app is excluded because it was built before this configuration was created and is using its own - "exclude": ["../apps/hebrew_calendar"] + "include": ["../apps/**/*", "./**/*"], } From 643c304a1ee4ad4d0c196f3467811e279b8356f9 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:00:04 +0100 Subject: [PATCH 25/35] trigger github actions on PR as well --- .github/workflows/nodejs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c268c884c..0c256c97b 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -1,6 +1,6 @@ name: Node CI -on: [push] +on: [push, pull_request] jobs: build: From da0e2a79096e1898d9da29cd3300f424196e9dae Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:04:42 +0100 Subject: [PATCH 26/35] Update metadata.json --- apps/widChargingStatus/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/widChargingStatus/metadata.json b/apps/widChargingStatus/metadata.json index f68ccf5b4..573c594e7 100644 --- a/apps/widChargingStatus/metadata.json +++ b/apps/widChargingStatus/metadata.json @@ -2,7 +2,7 @@ "name": "Charging Status", "shortName":"ChargingStatus", "icon": "widget.png", - "version":"0.01", + "version":"0.02", "type": "widget", "description": "A simple widget that shows a yellow lightning icon to indicate whenever the watch is charging. This way one can see the charging status at a glance, no matter which battery widget is being used.", "tags": "widget", From 4727652627ce864ea6148cae87002847fd2c43dd Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:09:57 +0100 Subject: [PATCH 27/35] rename build step to be less confusing for widgets --- .github/workflows/nodejs.yml | 4 ++-- typescript/README.md | 8 ++++---- typescript/package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 0c256c97b..bb27b367e 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -22,6 +22,6 @@ jobs: - name: build types working-directory: ./typescript run: npm run build:types - - name: build all TS apps + - name: build all TS apps and widgets working-directory: ./typescript - run: npm run build:apps + run: npm run build diff --git a/typescript/README.md b/typescript/README.md index d1f60fd0b..13800aeec 100644 --- a/typescript/README.md +++ b/typescript/README.md @@ -11,8 +11,8 @@ The typing is an ongoing process. If anything is still missing, you can add it! ## Compilation -Install [npm](https://www.npmjs.com/get-npm) if you haven't already. -Make sure you are using version ^8 by running `npm -v`. If the version is incorrect, run `npm i -g npm@^8`. +Install [npm](https://www.npmjs.com/get-npm) and node.js if you haven't already. We recommend using a version manager like nvm, which is also referenced in the linked documentation. +Make sure you are using node version 16 by running `nvm use 16` and npm version ^8 by running `npm -v`. If the latter version is incorrect, run `npm i -g npm@^8`. After having installed npm for your platform, open a terminal, and navigate into the `/typescript` folder. Then run: @@ -23,7 +23,7 @@ npm ci to install the project's build tools, and: ``` -npm run build:apps +npm run build ``` -To build all Typescript apps. The last command will generate the `app.js` files containing the transpiled code for the BangleJS. +To build all Typescript apps and widgets. The last command will generate the `app.js` files containing the transpiled code for the BangleJS. diff --git a/typescript/package.json b/typescript/package.json index 4bfb88d27..8cd38ce63 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -7,7 +7,7 @@ "typescript": "4.5.2" }, "scripts": { - "build:apps": "tsc", + "build": "tsc", "build:types": "tsc ./types/globals.d.ts" } } From ebbbf696701c01af8f31992d2e97862d4fcaa5b4 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:23:17 +0100 Subject: [PATCH 28/35] adjust module target version during build --- apps/banglerun/activity.js | 35 ++++++++++++++++++++--------------- apps/banglerun/app.js | 28 +++++++++++++++------------- apps/banglerun/display.js | 19 +++++++++++++++---- apps/banglerun/gps.js | 23 ++++++++++++++--------- apps/banglerun/hrm.js | 6 +++++- apps/banglerun/log.js | 6 +++++- apps/banglerun/state.js | 6 +++++- apps/banglerun/step.js | 10 +++++++--- typescript/tsconfig.json | 4 ++-- 9 files changed, 88 insertions(+), 49 deletions(-) diff --git a/apps/banglerun/activity.js b/apps/banglerun/activity.js index 818f9cf2a..94512094c 100644 --- a/apps/banglerun/activity.js +++ b/apps/banglerun/activity.js @@ -1,30 +1,35 @@ -import { draw } from './display'; -import { initLog } from './log'; -import { ActivityStatus } from './state'; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.stopActivity = exports.startActivity = exports.clearActivity = void 0; +const display_1 = require("./display"); +const log_1 = require("./log"); +const state_1 = require("./state"); function startActivity(state) { - if (state.status === ActivityStatus.Stopped) { - initLog(state); + if (state.status === state_1.ActivityStatus.Stopped) { + (0, log_1.initLog)(state); } - if (state.status === ActivityStatus.Running) { - state.status = ActivityStatus.Paused; + if (state.status === state_1.ActivityStatus.Running) { + state.status = state_1.ActivityStatus.Paused; } else { - state.status = ActivityStatus.Running; + state.status = state_1.ActivityStatus.Running; } - draw(state); + (0, display_1.draw)(state); } +exports.startActivity = startActivity; function stopActivity(state) { - if (state.status === ActivityStatus.Paused) { + if (state.status === state_1.ActivityStatus.Paused) { clearActivity(state); } - if (state.status === ActivityStatus.Running) { - state.status = ActivityStatus.Paused; + if (state.status === state_1.ActivityStatus.Running) { + state.status = state_1.ActivityStatus.Paused; } else { - state.status = ActivityStatus.Stopped; + state.status = state_1.ActivityStatus.Stopped; } - draw(state); + (0, display_1.draw)(state); } +exports.stopActivity = stopActivity; function clearActivity(state) { state.duration = 0; state.distance = 0; @@ -32,4 +37,4 @@ function clearActivity(state) { state.steps = 0; state.cadence = 0; } -export { clearActivity, startActivity, stopActivity }; +exports.clearActivity = clearActivity; diff --git a/apps/banglerun/app.js b/apps/banglerun/app.js index af5413cc0..84d03820a 100644 --- a/apps/banglerun/app.js +++ b/apps/banglerun/app.js @@ -1,13 +1,15 @@ -import { startActivity, stopActivity } from './activity'; -import { initDisplay } from './display'; -import { initGps } from './gps'; -import { initHrm } from './hrm'; -import { initState } from './state'; -import { initStep } from './step'; -const appState = initState(); -initGps(appState); -initHrm(appState); -initStep(appState); -initDisplay(appState); -setWatch(() => startActivity(appState), BTN1, { repeat: true, edge: 'falling' }); -setWatch(() => stopActivity(appState), BTN3, { repeat: true, edge: 'falling' }); +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const activity_1 = require("./activity"); +const display_1 = require("./display"); +const gps_1 = require("./gps"); +const hrm_1 = require("./hrm"); +const state_1 = require("./state"); +const step_1 = require("./step"); +const appState = (0, state_1.initState)(); +(0, gps_1.initGps)(appState); +(0, hrm_1.initHrm)(appState); +(0, step_1.initStep)(appState); +(0, display_1.initDisplay)(appState); +setWatch(() => (0, activity_1.startActivity)(appState), BTN1, { repeat: true, edge: 'falling' }); +setWatch(() => (0, activity_1.stopActivity)(appState), BTN3, { repeat: true, edge: 'falling' }); diff --git a/apps/banglerun/display.js b/apps/banglerun/display.js index 2768e8973..648482676 100644 --- a/apps/banglerun/display.js +++ b/apps/banglerun/display.js @@ -1,4 +1,7 @@ -import { ActivityStatus } from './state'; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.initDisplay = exports.formatTime = exports.formatPace = exports.formatDistance = exports.formatClock = exports.drawValue = exports.drawBackground = exports.drawAll = exports.draw = void 0; +const state_1 = require("./state"); const STATUS_COLORS = { 'STOP': 0xF800, 'PAUSE': 0xFFE0, @@ -14,6 +17,7 @@ function initDisplay(state) { }); drawAll(state); } +exports.initDisplay = initDisplay; function drawBackground() { g.clear(); g.setColor(0xC618); @@ -26,12 +30,14 @@ function drawBackground() { g.drawString('STEPS', 60, 152); g.drawString('CADENCE', 172, 152); } +exports.drawBackground = drawBackground; function drawValue(value, x, y) { g.setColor(0x0000); g.fillRect(x - 60, y, x + 60, y + 30); g.setColor(0xFFFF); g.drawString(value, x, y); } +exports.drawValue = drawValue; function draw(state) { g.setFontVector(30); g.setFontAlign(0, -1, 0); @@ -55,27 +61,31 @@ function draw(state) { g.setColor(0x0000); g.drawString(state.status, 200, 220); g.setFont("6x8").setFontAlign(0, 0, 1).setColor(-1); - if (state.status === ActivityStatus.Paused) { + if (state.status === state_1.ActivityStatus.Paused) { g.drawString("START", 236, 60, 1).drawString(" CLEAR ", 236, 180, 1); } - else if (state.status === ActivityStatus.Running) { + else if (state.status === state_1.ActivityStatus.Running) { g.drawString(" PAUSE ", 236, 60, 1).drawString(" PAUSE ", 236, 180, 1); } else { g.drawString("START", 236, 60, 1).drawString(" ", 236, 180, 1); } } +exports.draw = draw; function drawAll(state) { drawBackground(); draw(state); Bangle.drawWidgets(); } +exports.drawAll = drawAll; function formatClock(date) { return ('0' + date.getHours()).substr(-2) + ':' + ('0' + date.getMinutes()).substr(-2); } +exports.formatClock = formatClock; function formatDistance(meters) { return (meters / 1000).toFixed(2); } +exports.formatDistance = formatDistance; function formatPace(speed) { if (speed < 0.1667) { return `__'__"`; @@ -85,6 +95,7 @@ function formatPace(speed) { const sec = pace % 60; return ('0' + min).substr(-2) + `'` + ('0' + sec).substr(-2) + `"`; } +exports.formatPace = formatPace; function formatTime(time) { const seconds = Math.round(time); const hrs = Math.floor(seconds / 3600); @@ -92,4 +103,4 @@ function formatTime(time) { const sec = seconds % 60; return (hrs ? hrs + ':' : '') + ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2); } -export { draw, drawAll, drawBackground, drawValue, formatClock, formatDistance, formatPace, formatTime, initDisplay, }; +exports.formatTime = formatTime; diff --git a/apps/banglerun/gps.js b/apps/banglerun/gps.js index d06215cd5..35e0f8769 100644 --- a/apps/banglerun/gps.js +++ b/apps/banglerun/gps.js @@ -1,11 +1,15 @@ -import { draw } from './display'; -import { updateLog } from './log'; -import { ActivityStatus } from './state'; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateGps = exports.readGps = exports.initGps = void 0; +const display_1 = require("./display"); +const log_1 = require("./log"); +const state_1 = require("./state"); const EARTH_RADIUS = 6371008.8; function initGps(state) { Bangle.on('GPS', (gps) => readGps(state, gps)); Bangle.setGPSPower(1); } +exports.initGps = initGps; function readGps(state, gps) { state.lat = gps.lat; state.lon = gps.lon; @@ -15,16 +19,17 @@ function readGps(state, gps) { state.dop = gps.hdop; state.gpsValid = state.fix > 0; updateGps(state); - draw(state); + (0, display_1.draw)(state); /* Only log GPS data every 5 secs if we have a fix and we're running. */ if (state.gpsValid && - state.status === ActivityStatus.Running && + state.status === state_1.ActivityStatus.Running && state.timeSinceLog > 5) { state.timeSinceLog = 0; - updateLog(state); + (0, log_1.updateLog)(state); } } +exports.readGps = readGps; function updateGps(state) { const t = Date.now(); let dt = (t - state.t) / 1000; @@ -32,7 +37,7 @@ function updateGps(state) { dt = 0; state.t = t; state.timeSinceLog += dt; - if (state.status === ActivityStatus.Running) { + if (state.status === state_1.ActivityStatus.Running) { state.duration += dt; } if (!state.gpsValid) { @@ -57,10 +62,10 @@ function updateGps(state) { state.x = x; state.y = y; state.z = z; - if (state.status === ActivityStatus.Running) { + if (state.status === state_1.ActivityStatus.Running) { state.distance += dpMag; state.speed = (state.distance / state.duration) || 0; state.cadence = (60 * state.steps / state.duration) || 0; } } -export { initGps, readGps, updateGps }; +exports.updateGps = updateGps; diff --git a/apps/banglerun/hrm.js b/apps/banglerun/hrm.js index 35804f5e8..c002de2f6 100644 --- a/apps/banglerun/hrm.js +++ b/apps/banglerun/hrm.js @@ -1,7 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateHrm = exports.initHrm = void 0; function initHrm(state) { Bangle.on('HRM', (hrm) => updateHrm(state, hrm)); Bangle.setHRMPower(1); } +exports.initHrm = initHrm; function updateHrm(state, hrm) { if (hrm.confidence === 0) { return; @@ -12,4 +16,4 @@ function updateHrm(state, hrm) { state.hr += dHr * hrGain; state.hrError += (hrError - state.hrError) * hrGain; } -export { initHrm, updateHrm }; +exports.updateHrm = updateHrm; diff --git a/apps/banglerun/log.js b/apps/banglerun/log.js index b11409de6..ee2af3091 100644 --- a/apps/banglerun/log.js +++ b/apps/banglerun/log.js @@ -1,3 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateLog = exports.initLog = void 0; function initLog(state) { const datetime = new Date().toISOString().replace(/[-:]/g, ''); const date = datetime.substr(2, 6); @@ -8,6 +11,7 @@ function initLog(state) { state.fileWritten = false; return state; } +exports.initLog = initLog; function updateLog(state) { if (!state.fileWritten) { state.file.write([ @@ -33,4 +37,4 @@ function updateLog(state) { state.steps.toFixed(0), ].join(',') + '\n'); } -export { initLog, updateLog }; +exports.updateLog = updateLog; diff --git a/apps/banglerun/state.js b/apps/banglerun/state.js index 8629d69a7..349ef1954 100644 --- a/apps/banglerun/state.js +++ b/apps/banglerun/state.js @@ -1,9 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.initState = exports.ActivityStatus = void 0; var ActivityStatus; (function (ActivityStatus) { ActivityStatus["Stopped"] = "STOP"; ActivityStatus["Paused"] = "PAUSE"; ActivityStatus["Running"] = "RUN"; })(ActivityStatus || (ActivityStatus = {})); +exports.ActivityStatus = ActivityStatus; function initState() { return { fix: NaN, @@ -30,4 +34,4 @@ function initState() { cadence: 0, }; } -export { ActivityStatus, initState }; +exports.initState = initState; diff --git a/apps/banglerun/step.js b/apps/banglerun/step.js index b258a853d..e4acfd66a 100644 --- a/apps/banglerun/step.js +++ b/apps/banglerun/step.js @@ -1,10 +1,14 @@ -import { ActivityStatus } from './state'; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateStep = exports.initStep = void 0; +const state_1 = require("./state"); function initStep(state) { Bangle.on('step', () => updateStep(state)); } +exports.initStep = initStep; function updateStep(state) { - if (state.status === ActivityStatus.Running) { + if (state.status === state_1.ActivityStatus.Running) { state.steps += 1; } } -export { initStep, updateStep }; +exports.updateStep = updateStep; diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 7def102b7..d36465a01 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "module": "es2015", + "module": "commonjs", "noImplicitAny": true, - "target": "es2015", + "target": "es6", "allowUnreachableCode": false, "allowUnusedLabels": false, "noImplicitOverride": true, From 2faa870e7e7dd87f44c7ae9162b4f5e889c40d47 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:30:44 +0100 Subject: [PATCH 29/35] adjust banglerun/app.ts to not do some stupid self assign logic --- apps/banglerun/log.js | 5 +--- apps/banglerun/log.ts | 53 +++++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/apps/banglerun/log.js b/apps/banglerun/log.js index ee2af3091..0cdeaa964 100644 --- a/apps/banglerun/log.js +++ b/apps/banglerun/log.js @@ -6,10 +6,7 @@ function initLog(state) { const date = datetime.substr(2, 6); const time = datetime.substr(9, 6); const filename = `banglerun_${date}_${time}`; - state = state; - state.file = require('Storage').open(filename, 'w'); - state.fileWritten = false; - return state; + return Object.assign(Object.assign({}, state), { file: require('Storage').open(filename, 'w'), fileWritten: false }); } exports.initLog = initLog; function updateLog(state) { diff --git a/apps/banglerun/log.ts b/apps/banglerun/log.ts index 282115e1a..ba1c1f00e 100644 --- a/apps/banglerun/log.ts +++ b/apps/banglerun/log.ts @@ -7,36 +7,41 @@ function initLog(state: AppState): AppStateWithLog { const date = datetime.substr(2, 6); const time = datetime.substr(9, 6); const filename = `banglerun_${date}_${time}`; - state = state; - state.file = require('Storage').open(filename, 'w'); - state.fileWritten = false; - return state; + return { + ...state, + file: require('Storage').open(filename, 'w'), + fileWritten: false, + } as AppStateWithLog; } function updateLog(state: AppStateWithLog): void { if (!state.fileWritten) { - state.file.write([ - 'timestamp', - 'latitude', - 'longitude', - 'altitude', - 'duration', - 'distance', - 'heartrate', - 'steps', - ].join(',') + '\n'); + state.file.write( + [ + 'timestamp', + 'latitude', + 'longitude', + 'altitude', + 'duration', + 'distance', + 'heartrate', + 'steps', + ].join(',') + '\n' + ); state.fileWritten = true; } - state.file.write([ - Date.now().toFixed(0), - state.lat.toFixed(6), - state.lon.toFixed(6), - state.alt.toFixed(2), - state.duration.toFixed(0), - state.distance.toFixed(2), - state.hr.toFixed(0), - state.steps.toFixed(0), - ].join(',') + '\n'); + state.file.write( + [ + Date.now().toFixed(0), + state.lat.toFixed(6), + state.lon.toFixed(6), + state.alt.toFixed(2), + state.duration.toFixed(0), + state.distance.toFixed(2), + state.hr.toFixed(0), + state.steps.toFixed(0), + ].join(',') + '\n' + ); } export { initLog, updateLog }; From df7c92080fd4de54509924f04d7ab80b64cef112 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:34:28 +0100 Subject: [PATCH 30/35] add steps that travis CI does to the github actions pipeline --- .github/workflows/nodejs.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index bb27b367e..08849c073 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -25,3 +25,7 @@ jobs: - name: build all TS apps and widgets working-directory: ./typescript run: npm run build + - name: install testing dependencies + run: npm i + - name: test all apps and widgets + run: npm run test From f869b5373031cbac89b9ec37f8e6573bef125719 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:41:41 +0100 Subject: [PATCH 31/35] move app testing in front of TS build steps to see if that makes any difference --- .github/workflows/nodejs.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 08849c073..234e3d455 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -16,7 +16,11 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: npm ci + - name: install testing dependencies + run: npm i + - name: test all apps and widgets + run: npm run test + - name: install typescript dependencies working-directory: ./typescript run: npm ci - name: build types @@ -24,8 +28,4 @@ jobs: run: npm run build:types - name: build all TS apps and widgets working-directory: ./typescript - run: npm run build - - name: install testing dependencies - run: npm i - - name: test all apps and widgets - run: npm run test + run: npm run build \ No newline at end of file From 455c89cbec9e331d37c7f1566eb989bfd673ca5e Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 21:55:20 +0100 Subject: [PATCH 32/35] add some debugging logs as to why the module cant be found in the pipeline, but locally --- .github/workflows/nodejs.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 234e3d455..166700e2f 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -18,6 +18,12 @@ jobs: node-version: ${{ matrix.node-version }} - name: install testing dependencies run: npm i + - name: list content of folders + run: ls -l + - name: list content of folders 2 + run: ls -l ./core + - name: list content of folders 3 + run: ls -l ./core/lib - name: test all apps and widgets run: npm run test - name: install typescript dependencies From 391fbc20950083eb7a11c4f7c474fe5ae65f623b Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 22:01:34 +0100 Subject: [PATCH 33/35] use checkout v2 and import submodules for github actions --- .github/workflows/nodejs.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 166700e2f..fe438bae1 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -11,7 +11,10 @@ jobs: node-version: [16.x] steps: - - uses: actions/checkout@v1 + - name: Checkout repository and submodules + uses: actions/checkout@v2 + with: + submodules: recursive - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: From 016a0c89ea5d0208c02b33c0ff8adff10551a4ac Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 22:03:55 +0100 Subject: [PATCH 34/35] fix indenting in github actions yaml --- .github/workflows/nodejs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index fe438bae1..42aced6a9 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,9 +12,9 @@ jobs: steps: - name: Checkout repository and submodules - uses: actions/checkout@v2 - with: - submodules: recursive + uses: actions/checkout@v2 + with: + submodules: recursive - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: From e6d23cbc7e83e9aa61b588c933db21fe7758adee Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 20 Jan 2022 22:05:03 +0100 Subject: [PATCH 35/35] remove unnecessary steps from github actions --- .github/workflows/nodejs.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 42aced6a9..1eb009153 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -21,12 +21,6 @@ jobs: node-version: ${{ matrix.node-version }} - name: install testing dependencies run: npm i - - name: list content of folders - run: ls -l - - name: list content of folders 2 - run: ls -l ./core - - name: list content of folders 3 - run: ls -l ./core/lib - name: test all apps and widgets run: npm run test - name: install typescript dependencies