#!/usr/bin/env python
#
# Copyright 2017 Christopher Haverman
# All Rights Reserved
#
import logging
import re
import sys

from jinja2 import Environment, FileSystemLoader

__author__ = 'Christopher Haverman'

_exports_regex = re.compile(r'// IGNORE.*// ENDIGNORE', re.MULTILINE | re.DOTALL)
_logger = logging.getLogger(__name__)

FILE_DEST = 'main.js'
FILE_TEMPLATE = 'main.js.tpl'


def no_exports(value):
    return _exports_regex.sub('', value)


def main():
    environment = Environment(loader=FileSystemLoader('template/'))
    environment.filters['no_exports'] = no_exports
    template = environment.get_template(FILE_TEMPLATE)

    context = {}
    with open('src/log.js', 'rb') as f:
        context['log_definition'] = f.read()

    template_stream = template.stream(context)
    template_stream.dump(FILE_DEST)

if __name__ == '__main__':
    sys.exit(main())