From 04160cdd9ef29f4718ab090930ee282fc1612b91 Mon Sep 17 00:00:00 2001 From: blockarchitech Date: Sun, 12 Jan 2025 15:31:00 -0700 Subject: [PATCH] fix: make it build. also more friendly. --- README.md | 30 ++++++++++++++++++++++-------- bundler.sh | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 4 ++-- pebble.py | 37 ------------------------------------- src/pkts/index.ts | 2 +- wscript | 1 + 6 files changed, 65 insertions(+), 48 deletions(-) create mode 100755 bundler.sh delete mode 100644 pebble.py diff --git a/README.md b/README.md index 005e41e..bcbdcdb 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bundler.sh b/bundler.sh new file mode 100755 index 0000000..5917415 --- /dev/null +++ b/bundler.sh @@ -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 diff --git a/package.json b/package.json index 2dbaea2..2f3b28b 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pebble.py b/pebble.py deleted file mode 100644 index 7093594..0000000 --- a/pebble.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import sys - -PEBBLE_TOOL_LOCATION = "./pebble-wrapper.sh" - -if __name__ == '__main__': - if len(sys.argv) > 1 and sys.argv[1] == "build": - os.system(PEBBLE_TOOL_LOCATION + ' build') - - binaries = [ - {'platform': 'aplite'}, - {'platform': 'basalt'}, - {'platform': 'chalk'}, - {'platform': 'diorite'}, - ] - - os.system('npm run webpack') - os.system('cp dist/bundle.js build/pebble-js-app.js') - os.system('cp dist/bundle.js.map build/pebble-js-app.js.map') - - zip_file = 'build/pebble-ts.pbw' - zip_args = [ - 'zip', - '-j', - zip_file, - 'build/pebble-js-app.js', - 'build/pebble-js-app.js.map', - 'build/appinfo.json', - ] - for binary in binaries: - zip_args.append(binary['platform']) - os.system(' '.join(zip_args)) - elif len(sys.argv) > 1 and sys.argv[1] == "clean": - os.system(PEBBLE_TOOL_LOCATION + ' clean') - os.system("rm -rf dist") - else: - print("Usage: python pebble.py [build|clean]") diff --git a/src/pkts/index.ts b/src/pkts/index.ts index ef8217a..d5e0559 100644 --- a/src/pkts/index.ts +++ b/src/pkts/index.ts @@ -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."); } ); \ No newline at end of file diff --git a/wscript b/wscript index b72897d..07fd202 100644 --- a/wscript +++ b/wscript @@ -47,6 +47,7 @@ def build(ctx): ctx.env = cached_env ctx.set_group('bundle') + ctx.pbl_bundle(binaries=binaries)