Exemplo n.º 1
0
def _render_app(request, extra={}):
    request.response.text = client.render_app_html(
        api_url=request.route_url("api"),
        service_url=request.route_url("index"),
        extra=extra,
        ga_tracking_id=request.registry.settings.get("ga_tracking_id"),
        sentry_public_dsn=request.sentry.get_public_dsn(),
        webassets_env=request.webassets_env,
        websocket_url=client.websocketize(request.route_url("ws")),
    )
    return request.response
Exemplo n.º 2
0
def build_chrome(args):
    """
    Build the Chrome extension. You can supply the base URL of an h
    installation with which this extension will communicate, such as
    "http://localhost:5000" when developing locally or
    "https://hypothes.is" to talk to the production Hypothesis application.
    """
    service_url = args.service_url
    if not service_url.endswith('/'):
        service_url = '{}/'.format(service_url)

    webassets_env = get_webassets_env(base_dir='./build/chrome/public',
                                      assets_url='/public',
                                      debug=args.debug)

    # Prepare a fresh build.
    clean('build/chrome')
    os.makedirs('build/chrome')
    content_dir = webassets_env.directory
    os.makedirs(content_dir)

    # Bundle the extension assets.
    copytree('h/browser/chrome/content', 'build/chrome/content')
    copytree('h/browser/chrome/help', 'build/chrome/help')
    copytree('h/browser/chrome/images', 'build/chrome/images')
    copytree('h/static/images', 'build/chrome/public/images')

    os.makedirs('build/chrome/lib')

    subprocess_args = ['node_modules/.bin/browserify',
                       'h/browser/chrome/lib/extension.js', '--outfile',
                       'build/chrome/lib/extension-bundle.js']
    if args.debug:
        subprocess_args.append('--debug')
    subprocess.call(subprocess_args)

    # Render the sidebar html
    api_url = '{}api/'.format(service_url)
    websocket_url = websocketize('{}ws'.format(service_url))

    if args.bundle_sidebar:
        build_extension_common(webassets_env, service_url, bundle_app=True)
        with codecs.open(content_dir + '/app.html', 'w', 'utf-8') as fp:
            data = client.render_app_html(
                api_url=api_url,
                service_url=service_url,

                # Google Analytics tracking is currently not enabled
                # for the extension
                ga_tracking_id=None,
                webassets_env=webassets_env,
                websocket_url=websocket_url,
                sentry_public_dsn=args.sentry_public_dsn)
            fp.write(data)
    else:
        build_extension_common(webassets_env, service_url)

    # Render the manifest.
    with codecs.open('build/chrome/manifest.json', 'w', 'utf-8') as fp:
        script_url = urlparse.urlparse(webassets_env.url)
        if script_url.scheme and script_url.netloc:
            script_host_url = '{}://{}'.format(script_url.scheme,
                                               script_url.netloc)
        else:
            script_host_url = None
        data = chrome_manifest(script_host_url)
        fp.write(data)

    # Write build settings to a JSON file
    with codecs.open('build/chrome/settings-data.js', 'w', 'utf-8') as fp:
        settings = settings_dict(service_url, api_url, args.sentry_public_dsn)
        fp.write('window.EXTENSION_CONFIG = ' + json.dumps(settings))