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
pull/1052/head
Sebastian Di Luzio 2021-12-08 20:22:39 +01:00
parent 61cc93b0b6
commit 63b26f5d1f
10 changed files with 124 additions and 129 deletions

View File

@ -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"}
]
},
{

31
apps/widChargingStatus/dist/widget.js vendored Normal file
View File

@ -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();
});
})();

View File

@ -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();
});
})();
Bangle.on('charging', (charging) => {
if (charging) {
Bangle.buzz();
WIDGETS.chargingStatus.width = iconWidth;
} else {
WIDGETS.chargingStatus.width = 0;
}
Bangle.drawWidgets(); // re-layout widgets
g.flip();
});
})();

View File

@ -4,12 +4,16 @@
"author": "Gordon Williams <gw@pur3.co.uk> (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"

7
tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "es2015",
"noImplicitAny": true,
"target": "es2015"
}
}

View File

@ -1,2 +0,0 @@
node_modules/
!package-lock.json

View File

@ -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
}
}
}

View File

@ -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"
}
}

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"module": "es2015",
"noImplicitAny": true,
"target": "es2015",
"outDir": "../dist",
"isolatedModules": false
},
"include": ["./globals.d.ts"]
}

View File

@ -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 };
}