mirror of https://github.com/espruino/BangleApps
Port banglerun to new typescript system
parent
2d9080da72
commit
4dbec88b7f
|
@ -5,21 +5,4 @@ An app for running sessions. Displays info and logs your run for later viewing.
|
||||||
## Compilation
|
## Compilation
|
||||||
|
|
||||||
The app is written in Typescript, and needs to be transpiled in order to be
|
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
|
run on the BangleJS. See ../../typescript/README.md for instructions.
|
||||||
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.
|
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
import { AppState } from './state';
|
import { AppState, AppStateWithLog } from './state';
|
||||||
|
|
||||||
declare var require: any;
|
declare var require: any;
|
||||||
|
|
||||||
function initLog(state: AppState): void {
|
function initLog(state: AppState): AppStateWithLog {
|
||||||
const datetime = new Date().toISOString().replace(/[-:]/g, '');
|
const datetime = new Date().toISOString().replace(/[-:]/g, '');
|
||||||
const date = datetime.substr(2, 6);
|
const date = datetime.substr(2, 6);
|
||||||
const time = datetime.substr(9, 6);
|
const time = datetime.substr(9, 6);
|
||||||
const filename = `banglerun_${date}_${time}`;
|
const filename = `banglerun_${date}_${time}`;
|
||||||
|
state = <AppStateWithLog> state;
|
||||||
state.file = require('Storage').open(filename, 'w');
|
state.file = require('Storage').open(filename, 'w');
|
||||||
state.fileWritten = false;
|
state.fileWritten = false;
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLog(state: AppState): void {
|
function updateLog(state: AppStateWithLog): void {
|
||||||
if (!state.fileWritten) {
|
if (!state.fileWritten) {
|
||||||
state.file.write([
|
state.file.write([
|
||||||
'timestamp',
|
'timestamp',
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,7 @@ enum ActivityStatus {
|
||||||
Running = 'RUN',
|
Running = 'RUN',
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AppState {
|
interface BasicAppState {
|
||||||
// GPS NMEA data
|
// GPS NMEA data
|
||||||
fix: number;
|
fix: number;
|
||||||
lat: number;
|
lat: number;
|
||||||
|
@ -28,14 +28,12 @@ interface AppState {
|
||||||
hrError: number,
|
hrError: number,
|
||||||
|
|
||||||
// Logger data
|
// Logger data
|
||||||
file: File;
|
|
||||||
fileWritten: boolean;
|
fileWritten: boolean;
|
||||||
|
|
||||||
// Drawing data
|
// Drawing data
|
||||||
drawing: boolean;
|
drawing: boolean;
|
||||||
|
|
||||||
// Activity data
|
// Activity data
|
||||||
status: ActivityStatus;
|
|
||||||
duration: number;
|
duration: number;
|
||||||
distance: number;
|
distance: number;
|
||||||
speed: number;
|
speed: number;
|
||||||
|
@ -43,6 +41,17 @@ interface AppState {
|
||||||
cadence: number;
|
cadence: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AppStateWithoutLog extends BasicAppState {
|
||||||
|
status: 'STOP';
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AppStateWithLog extends BasicAppState {
|
||||||
|
file: File;
|
||||||
|
status: ActivityStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppState = AppStateWithLog | AppStateWithoutLog;
|
||||||
|
|
||||||
interface File {
|
interface File {
|
||||||
read: Function;
|
read: Function;
|
||||||
write: Function;
|
write: Function;
|
||||||
|
@ -68,7 +77,6 @@ function initState(): AppState {
|
||||||
hr: 60,
|
hr: 60,
|
||||||
hrError: 100,
|
hrError: 100,
|
||||||
|
|
||||||
file: null,
|
|
||||||
fileWritten: false,
|
fileWritten: false,
|
||||||
|
|
||||||
drawing: false,
|
drawing: false,
|
||||||
|
@ -82,4 +90,4 @@ function initState(): AppState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ActivityStatus, AppState, File, initState };
|
export { ActivityStatus, AppState, AppStateWithLog, File, initState };
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "es2015",
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"target": "es2015"
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"src"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"target": "es2015"
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"test"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -14,6 +14,6 @@
|
||||||
"strict": true
|
"strict": true
|
||||||
},
|
},
|
||||||
"include": ["../apps/**/*", "./**/*"],
|
"include": ["../apps/**/*", "./**/*"],
|
||||||
// these apps have been excluded because they were built before this configuration was created and are using their own
|
// this app is excluded because it was built before this configuration was created and is using its own
|
||||||
"exclude": ["../apps/banglerun", "../apps/hebrew_calendar"]
|
"exclude": ["../apps/hebrew_calendar"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue