acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
439 stars 48 forks source link

Update FF WebExtension API config #73

Closed Sxderp closed 6 years ago

Sxderp commented 6 years ago

I used a script to grab the stable-api-ff.json which is probably why the diff is so large.

Here's the script.. I should probably gist this or something. Oh well.

import json
import re
from httplib import HTTPSConnection
from operator import itemgetter

moz = 'hg.mozilla.org'
# Find the revision for latest release
# https://hg.mozilla.org/releases/mozilla-release/tags
rev = '8bb8f895a740'
base_path = '/releases/mozilla-release/raw-file/' + rev
toolkit_path = base_path + '/toolkit/components/extensions/schemas/'
browser_path = base_path + '/browser/components/extensions/schemas/'

def main():
    conn = HTTPSConnection(moz)
    sch_items = fetch_json_links(conn, toolkit_path)
    sch_items.extend(fetch_json_links(conn, browser_path))
    # Sort items
    sch_items.sort(key=itemgetter(0))

    schemas = []
    for file_name, path in sch_items:
        fetch_json_schema(conn, path + file_name, schemas)
    print json.dumps(schemas, sort_keys=True, indent=2)

def fetch_json_links(conn, path):
    """
    Given a directory path create a list of json files
    """
    conn.request('GET', path)
    response = conn.getresponse()
    links = []

    for file_entry in response.read().split('\n'):
        if file_entry:
            # File should be safe (that is, no spaces)
            file_name = file_entry.split(' ')[2]
            if '.json' == file_name[-5:]:
                links.append((file_name, path))
    return links

def fetch_json_schema(conn, path, schemas):
    """
    Given a file path fetch the schema object
    """
    conn.request('GET', path)
    response = conn.getresponse()
    remove_comments = re.sub('(?m)^(//|/\*| \*).*$', '', response.read())
    for sch in json.loads(remove_comments):
        # TODO: Figure out how to properly implement 'extend' properties
        if 'native_manifest.json' in path or \
            ('manifest.json' not in path and sch['namespace'] == 'manifest'):
            continue
        else:
            schemas.append(sch)

main()