Skip to content

Commit

Permalink
fix: make it build. also more friendly.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockarchitech committed Jan 12, 2025
1 parent c8a479e commit 04160cd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 48 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# Pebble Typescript

A somewhat foolproof way to write Pebble apps with PebbleKit JS using TypeScript.
A somewhat foolproof way to write Pebble apps with TypeScript.

## Usage

1. Clone this repository
2. Open `pebble.py`, and edit `PEBBLE_TOOL_LOCATION` to point to your Pebble Tool location. This can be a wrapper script, or point directly to the `pebble` executable.
3. Run `npm install`
4. Write your TypeScript code in `src/pkts/`
5. Run `npm run build`
6. Your compiled Pebble app will be in `build/pebble-ts.pbw`
- Clone this repository
- Run `npm install` to install dependencies
- Edit `bundler.sh` to point to your `pebble` tool location.
- If you installed the SDK locally, this is probably somewhere in ~/pebble-dev.
- Run `npm run build`
- This will build your Pebble project, build your TypeScript files, and chuck the TS files into PBW.

To clean, simply run `npm run clean`. This will delete the webpack caches and run `pebble clean` as to not leave any pebble build artifacts behind.
You can also run `npm run clean`, which will remove all build artifacts as well as run `pebble build`.

## How it works

The Pebble SDK natively supports JavaScript, thru PebbleKit JS. This is great, however there's a few issues:

- The SDK uses an ancient JavaScript version, almost ES5 but missing some features.
- The SDK doesn't support TypeScript, which is a superset of JavaScript that adds types and other features.
- The SDK doesn't allow you to customize Webpack settings.
- The SDK doesn't allow you to use many popular npm packages.

This project aims to solve these issues by providing a way to write TypeScript code, and telling the Pebble SDK to _only_ build the C code. We then take the compiled C code, as well as our Webpack-compiled TypeScript code, and chuck it into a PBW file. However, this is not a perfect solution, and there are some caveats:

- As of current, the PebbleKit library has no type definitions. The keen-eyed will notice that the `pebble.d.ts` file simply maps `Pebble` to `any`. This is not ideal, but it's better than nothing. (which, is what you'd get otherwise)
- This **only works on Android**. The iOS Pebble app does not support the modern versions of JavaScript that we use. This is a limitation of the Pebble app, and there's nothing we can do about it as we cannot update the Pebble app.
39 changes: 39 additions & 0 deletions bundler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

PEBBLE_TOOL_LOCATION="./pebble-wrapper.sh" # Change this to the path of your pebble-tool. Probably in ~/pebble-dev if SDK is locally installed
function build() {
$PEBBLE_TOOL_LOCATION build
npm run webpack

mkdir -p tmp
mv build/pebble.pbw tmp/oldpebble.zip
unzip tmp/oldpebble.zip -d tmp
rm tmp/oldpebble.zip
cp dist/bundle.js tmp/pebble-js-app.js
cp dist/bundle.js.map tmp/pebble-js-app.js.map
(cd tmp && zip -o -r pebble.pbw *)
cp tmp/pebble.pbw build/pebble.pbw
rm -rf tmp
}

function clean() {
$PEBBLE_TOOL_LOCATION clean
rm -rf dist
rm -rf tmp
}

if [ "$#" -gt 0 ]; then
case "$1" in
build)
build
;;
clean)
clean
;;
*)
echo "Usage: $0 [build|clean]"
;;
esac
else
echo "Usage: $0 [build|clean]"
fi
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
],
"scripts": {
"webpack": "webpack",
"build": "python3 pebble.py build",
"clean": "python3 pebble.py clean"
"build": "./bundler.sh build",
"clean": "./bundler.sh clean"
},
"private": true,
"pebble": {
Expand Down
37 changes: 0 additions & 37 deletions pebble.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/pkts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Pebble.addEventListener("ready",
function(e) {
console.log("Hello world! - Sent from your javascript application.");
console.log("Hello world! - Sent from your TypeScript application.");
}
);
1 change: 1 addition & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def build(ctx):
ctx.env = cached_env

ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries)



Expand Down

0 comments on commit 04160cd

Please sign in to comment.