Skip to content

Instantly share code, notes, and snippets.

@exiva
Created November 9, 2015 19:50
Show Gist options
  • Save exiva/9c8f4c544014d431d147 to your computer and use it in GitHub Desktop.
Save exiva/9c8f4c544014d431d147 to your computer and use it in GitHub Desktop.
import os
try:
from sh import CommandNotFound, jshint, cat, uglifyjs, ErrorReturnCode_2
hint = True
except (ImportError, CommandNotFound):
hint = None
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
def build(ctx):
ctx.path.make_node('src/js/').mkdir()
js_files = [
'src/js/config.js',
'src/js/keys.js',
'src/js/utils.js',
'src/js/app.js'
]
if hint is not None:
try:
jshint('src/js/app.js', _tty_out=False)
except ErrorReturnCode_2 as e:
ctx.fatal("\nJavaScript linting failed\n" + e.stdout)
try:
os.remove('build/app.js')
os.remove('build/pebble-js-app.js')
except OSError:
pass
#concatenate all the JS together
for path in js_files:
ctx(rule='cat ${SRC} >> ${TGT}', source=path, target='app.js')
# minify and mangle the JS.
# probably not the best way to execute it.
ctx(rule='uglifyjs ${SRC} -m -c -r \'Pebble\' -o ${TGT}', source='app.js', target='pebble-js-app.js')
ctx.load('pebble_sdk')
build_worker = os.path.exists('worker_src')
binaries = []
for p in ctx.env.TARGET_PLATFORMS:
ctx.set_env(ctx.all_envs[p])
ctx.set_group(ctx.env.PLATFORM_NAME)
app_elf='{}/pebble-app.elf'.format(p)
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
target=app_elf)
if build_worker:
worker_elf='{}/pebble-worker.elf'.format(p)
binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf})
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'),
target=worker_elf)
else:
binaries.append({'platform': p, 'app_elf': app_elf})
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries, js='pebble-js-app.js')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment