def extension(args, console, settings): """Build the browser extensions. The first argument is the base URL of an h installation: http://localhost:5000 An optional second argument can be used to specify the location for static assets. Examples: http://static.example.com/ chrome-extension://extensionid/public """ if len(args) == 1: console.error('You must supply a url to the hosted backend.') return 2 elif len(args) == 2: assets_url = settings['webassets.base_url'] else: settings['webassets.base_url'] = args[2] assets_url = args[2] base_url = args[1] # Fully-qualify the static asset url parts = urlparse(assets_url) if not parts.netloc: base = urlparse(base_url) parts = (base.scheme, base.netloc, parts.path, parts.params, parts.query, parts.fragment) assets_url = urlunparse(parts) # Set up the assets url and source path mapping settings['webassets.base_dir'] = abspath('./build/chrome/public') settings['webassets.base_url'] = assets_url settings['webassets.paths'] = json.dumps( {resolve('h:').abspath(): assets_url}) # Remove any existing build if exists('./build/chrome'): rmtree('./build/chrome') # Copy over all the assets assets(settings) makedirs('./build/chrome/public/lib/images') merge('./pdf.js/build/chromium', './build/chrome') merge('./h/browser/chrome', './build/chrome') merge('./h/images', './build/chrome/public/images') merge('./h/lib/images', './build/chrome/public/lib/images') config = Configurator(settings=settings) config.include('h') config.add_subscriber(add_base_url, BeforeRender) config.commit() # Build it request = Request.blank('/app', base_url=base_url) chrome(prepare(registry=config.registry, request=request))
def extension(args, console, settings): """Build the browser extensions. The first argument is the base URL of an h installation: http://localhost:5000 An optional second argument can be used to specify the location for static assets. Examples: http://static.example.com/ chrome-extension://extensionid/public """ if len(args) == 1: console.error('You must supply a url to the hosted backend.') return 2 elif len(args) == 2: assets_url = settings['webassets.base_url'] else: settings['webassets.base_url'] = args[2] assets_url = args[2] base_url = args[1] # Fully-qualify the static asset url parts = urlparse(assets_url) if not parts.netloc: base = urlparse(base_url) parts = (base.scheme, base.netloc, parts.path, parts.params, parts.query, parts.fragment) assets_url = urlunparse(parts) # Set up the assets url and source path mapping settings['webassets.base_dir'] = abspath('./build/chrome/public') settings['webassets.base_url'] = assets_url settings['webassets.paths'] = json.dumps({ resolve('h:').abspath(): assets_url }) # Remove any existing build if exists('./build/chrome'): rmtree('./build/chrome') # Copy over all the assets assets(settings) makedirs('./build/chrome/public/lib/images') merge('./pdf.js/build/chromium', './build/chrome') merge('./h/browser/chrome', './build/chrome') merge('./h/images', './build/chrome/public/images') merge('./h/lib/images', './build/chrome/public/lib/images') config = Configurator(settings=settings) config.include('h') config.add_subscriber(add_base_url, BeforeRender) config.commit() # Build it request = Request.blank('/app', base_url=base_url) chrome(prepare(registry=config.registry, request=request))
def assets(settings): """Build the static assets.""" config = Configurator(settings=settings) config.include('h.assets') for bundle in config.get_webassets_env(): bundle.urls()