Exemplo n.º 1
0
def build_header_bundle(version, minify, dev, sandbox, platform):
    """
    Takes a version of a base project, compiles a header bundle and writes it
    to stout.

    :param version: A string corresponding to the base version e.g. '0.1'
    """

    # Switch to the directory containing the correct version of our packager
    version_dir = version_dir_path(version)

    commands = ['node', 'index', '--header', '--platform', platform]

    if minify:
        commands.append('--minify')

    if dev:
        commands.append('--dev')

    if sandbox:
        commands.append('--sandbox')

    with cd(version_dir):
        header = subprocess.check_output(commands)
        print(header.decode('utf-8'))
def main():
    print('Installing packager dependencies...')
    with cd(SERVER_DIR):
        print('\n[Installing dependencies for packager server]')
        subprocess.call(['npm', 'install', '--loglevel', 'http'])

    versions = get_versions()
    for v in versions:
        # Check if a node_modules_dir exists in the version dir.
        # If it does, then this version has been installed
        print('\n[Installing dependencies for packager v%s]' % v)
        version_directory = version_dir_path(v)
        with cd(version_directory):
            subprocess.call(['npm', 'install', '--loglevel', 'http'])

        production_env_dir = version_production_env_path(v)
        with cd(production_env_dir):
            subprocess.call(['npm', 'install', '--loglevel', 'http'])
Exemplo n.º 3
0
def main():
    print('Installing packager dependencies...')
    with cd(SERVER_DIR):
        print('\n[Installing dependencies for packager server]')
        subprocess.call(['npm', 'install', '--loglevel', 'http'])

    versions = get_versions()
    for v in versions:
        # Check if a node_modules_dir exists in the version dir.
        # If it does, then this version has been installed
        print('\n[Installing dependencies for packager v%s]' % v)
        version_directory = version_dir_path(v)
        with cd(version_directory):
            subprocess.call(['npm', 'install', '--loglevel', 'http'])

        production_env_dir = version_production_env_path(v)
        with cd(production_env_dir):
            subprocess.call(['npm', 'install', '--loglevel', 'http'])
def npm_install(dir):
    # Runs 'npm install' in a given directory
    with cd(dir):
        subprocess.call(['npm', 'install'])
Exemplo n.º 5
0
def main():
    # Takes a project root and destination as arguments and writes the zipped
    # assets to that location.

    # If a conf has been provided, collect the specified params
    conf = {}
    if '--conf' in sys.argv:
        try:
            conf_name = sys.argv[sys.argv.index('--conf') + 1]
        except (ValueError, IndexError):
            print_usage()
            sys.exit(1)

        with open(CONF, 'r') as f:
            conf_file = json.loads(f.read())

        conf = conf_file['assets'].get(conf_name)
        if not conf:
            print('Specified config not found in conf.json')
            sys.exit(1)

    # Required args
    try:
        if conf.get('project_path'):
            project_root = conf.get('project_path')
        else:
            project_root = sys.argv[sys.argv.index('--project-path') + 1]

        project_root = os.path.abspath(project_root)

        if conf.get('dest'):
            dest = conf.get('dest')
        else:
            dest = sys.argv[sys.argv.index('--dest') + 1]

        if conf.get('platform'):
            platform = conf.get('platform')
        else:
            platform = sys.argv[sys.argv.index('--platform') + 1]

    except (ValueError, IndexError):
        print_usage()
        sys.exit(1)

    cmd = [
        'python',
        'siphon-packager.py',
        '--footer',
        '--project-path',
        project_root
    ]

    # Optional args
    if '--minify' in sys.argv:
        cmd.append('--minify')

    if '--base-version' in sys.argv:
        try:
            base_version = sys.argv[sys.argv.index('--base-version') + 1]
            cmd.append('--base-version')
            cmd.append(base_version)
        except IndexError:
            print_usage()
            sys.exit(1)

    print('Generating footer...')
    out = subprocess.check_output(cmd, env=os.environ.copy())
    result = json.loads(out.decode())

    platform_result = result.get(platform)
    if not platform_result:
        print('ERROR: Entry file not found for platform.')
    else:
        print('Done')
        try:
            with make_temp_dir() as tmp:
                # Add assets-listing file
                print('Collecting assets...')
                asset_paths = assets_list(project_root)
                assets_listing = os.path.join(tmp, 'assets-listing')
                footer = os.path.join(tmp, 'bundle-footer')
                shutil.copyfile(platform_result, footer)

                # Copy the assets into our tmp dir and add them to the
                # assets-listing file
                with open(assets_listing, 'w') as f:
                    for a in asset_paths:
                        relative_path = a.replace(project_root, '')
                        if relative_path[0] == '/':
                            relative_path = relative_path[1:]

                        asset_dest = os.path.join(tmp, '__siphon_assets',
                                                  'images',
                                                  relative_path)
                        os.makedirs(os.path.dirname(asset_dest),
                                    exist_ok=True)
                        shutil.copyfile(a, asset_dest)
                        f.write('%s\n' % relative_path)

                # Add items to zip archive
                zip_path = os.path.join(tmp, 'assets.zip')
                with cd(tmp):
                    with ZipFile(zip_path, 'w') as zf:
                        write_directory_zip('__siphon_assets/images', zf)
                        zf.write('assets-listing')
                        zf.write('bundle-footer')
                # Copy the zip archive to the destination
                ensure_dir_exists(dest)
                shutil.copyfile(zip_path, os.path.join(dest, 'assets.zip'))
        finally:
            # Clean up the tmp directory generated by the packager if it exists
            tmp = tempfile.gettempdir()
            for f in os.listdir(tmp):
                if f.startswith('siphon-packager-tmp-'):
                    shutil.rmtree(os.path.join(tmp, f))
            print('Done')
def npm_install(dir):
    # Runs 'npm install' in a given directory
    with cd(dir):
        subprocess.call(['npm', 'install'])
Exemplo n.º 7
0
def main():
    # Takes a project root and destination as arguments and writes the zipped
    # assets to that location.

    # If a conf has been provided, collect the specified params
    conf = {}
    if '--conf' in sys.argv:
        try:
            conf_name = sys.argv[sys.argv.index('--conf') + 1]
        except (ValueError, IndexError):
            print_usage()
            sys.exit(1)

        with open(CONF, 'r') as f:
            conf_file = json.loads(f.read())

        conf = conf_file['assets'].get(conf_name)
        if not conf:
            print('Specified config not found in conf.json')
            sys.exit(1)

    # Required args
    try:
        if conf.get('project_path'):
            project_root = conf.get('project_path')
        else:
            project_root = sys.argv[sys.argv.index('--project-path') + 1]

        project_root = os.path.abspath(project_root)

        if conf.get('dest'):
            dest = conf.get('dest')
        else:
            dest = sys.argv[sys.argv.index('--dest') + 1]

        if conf.get('platform'):
            platform = conf.get('platform')
        else:
            platform = sys.argv[sys.argv.index('--platform') + 1]

    except (ValueError, IndexError):
        print_usage()
        sys.exit(1)

    cmd = [
        'python', 'siphon-packager.py', '--footer', '--project-path',
        project_root
    ]

    # Optional args
    if '--minify' in sys.argv:
        cmd.append('--minify')

    if '--base-version' in sys.argv:
        try:
            base_version = sys.argv[sys.argv.index('--base-version') + 1]
            cmd.append('--base-version')
            cmd.append(base_version)
        except IndexError:
            print_usage()
            sys.exit(1)

    print('Generating footer...')
    out = subprocess.check_output(cmd, env=os.environ.copy())
    result = json.loads(out.decode())

    platform_result = result.get(platform)
    if not platform_result:
        print('ERROR: Entry file not found for platform.')
    else:
        print('Done')
        try:
            with make_temp_dir() as tmp:
                # Add assets-listing file
                print('Collecting assets...')
                asset_paths = assets_list(project_root)
                assets_listing = os.path.join(tmp, 'assets-listing')
                footer = os.path.join(tmp, 'bundle-footer')
                shutil.copyfile(platform_result, footer)

                # Copy the assets into our tmp dir and add them to the
                # assets-listing file
                with open(assets_listing, 'w') as f:
                    for a in asset_paths:
                        relative_path = a.replace(project_root, '')
                        if relative_path[0] == '/':
                            relative_path = relative_path[1:]

                        asset_dest = os.path.join(tmp, '__siphon_assets',
                                                  'images', relative_path)
                        os.makedirs(os.path.dirname(asset_dest), exist_ok=True)
                        shutil.copyfile(a, asset_dest)
                        f.write('%s\n' % relative_path)

                # Add items to zip archive
                zip_path = os.path.join(tmp, 'assets.zip')
                with cd(tmp):
                    with ZipFile(zip_path, 'w') as zf:
                        write_directory_zip('__siphon_assets/images', zf)
                        zf.write('assets-listing')
                        zf.write('bundle-footer')
                # Copy the zip archive to the destination
                ensure_dir_exists(dest)
                shutil.copyfile(zip_path, os.path.join(dest, 'assets.zip'))
        finally:
            # Clean up the tmp directory generated by the packager if it exists
            tmp = tempfile.gettempdir()
            for f in os.listdir(tmp):
                if f.startswith('siphon-packager-tmp-'):
                    shutil.rmtree(os.path.join(tmp, f))
            print('Done')