-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make it build. also more friendly.
- Loading branch information
1 parent
c8a479e
commit 04160cd
Showing
6 changed files
with
65 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ def build(ctx): | |
ctx.env = cached_env | ||
|
||
ctx.set_group('bundle') | ||
ctx.pbl_bundle(binaries=binaries) | ||
|
||
|
||
|
||
|