Port banglerun to new typescript system

pull/1052/head
Adam Schmalhofer 2021-12-14 21:42:58 +01:00
parent 2d9080da72
commit 4dbec88b7f
13 changed files with 21 additions and 75 deletions

View File

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

View File

@ -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 = <AppStateWithLog> 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',

View File

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

View File

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

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"module": "es2015",
"noImplicitAny": true,
"target": "es2015"
},
"include": [
"src"
]
}

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"target": "es2015"
},
"include": [
"test"
]
}

View File

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