Created
February 22, 2016 05:01
-
-
Save exiva/63be5958a50397e1185f to your computer and use it in GitHub Desktop.
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
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' #app loaded after libs. | |
] | |
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) | |
# always delete the old JS files. | |
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