示例#1
0
def pack(request, file_list, output, minify=False):
	str_js = ""

	if not settings.RAPE_PACK:
		str_js = "/* File list:\n%s\n*/\n\n" % json.dumps(file_list, indent=4, sort_keys=True)

	for res_name in file_list:
		fp = open(res_name, "r")
		data = unicode(fp.read(), 'utf-8')
		str_js += helpers.replace_resource_urls(request, data)
		fp.close()

	if settings.RAPE_PACK:
		str_js = uglipyjs.compile(str_js)

	helpers.check_dir(os.path.dirname(output))
	ofp = open(output, "w+")
	ofp.write(str_js.encode('utf-8'))
	ofp.close()
示例#2
0
def read_javascript(static_paths, minify=False):
    if minify:
        return uglipyjs.compile(read_cat(static_paths))
    else:
        return read_cat(static_paths)
示例#3
0
def minify_js(js_text):
    return uglipyjs.compile(js_text)
示例#4
0
def read_javascript(static_paths, minify=False):
    if minify:
        return uglipyjs.compile(read_cat(static_paths))
    else:
        return read_cat(static_paths)
示例#5
0
    def evaluate(self, scope, locals, block=None):
        if not hasattr(self, 'output') or not self.output:
            import uglipyjs
            self.output = uglipyjs.compile(self.data)

        return self.output
示例#6
0
def main(*args):
    tracking = False
    gitHubUser = False
    repo = False
    rootDir = os.getcwd()
    gitHubUrl = 'https://github.com/%s'
    # FIXME: Add git hash/version as in
    # "Sync with https://github.com/FOO/BAR (v9.9.9 or HASH)"
    gitHubSummary = 'Sync with %s'
    # FIXME: Add UglifyJS version as in
    # "minify with UglifyJS v9.9.9"
    uglifyjsSummary = 'minify with UgliPyJS %s'
    for arg in pywikibot.handle_args():
        if arg == "-all":
            allowNullEdits = True
        elif arg == "-track":
            # The file link is unnecessary on GitHub but useful on wiki
            tracking = '[[File:%s]] (workaround for [[phab:T35355]])'
        elif arg.startswith('-prefix:'):
            userPrefix = arg[len('-prefix:'):]
        elif arg.startswith('-repo:'):
            repo = arg[len('-repo:'):]
        elif arg.startswith('-mypath:'):
            rootDir = arg[len('-mypath:'):]
        elif arg.startswith('-github:'):
            gitHubUser = arg[len('-github:'):]
    if not gitHubUser:
        print('Missing required paramenter -github:<username>.')
        return
    gitHubUrl = (gitHubUrl % gitHubUser) + '/%s'
    site = pywikibot.Site()  # pywikibot.Site( 'meta', 'meta' )
    for dirpath, dirnames, files in os.walk(rootDir):
        for name in files:
            ext = name.rsplit('.', 1)[-1].lower()
            # Assume the structure is <mypath>/<repo>/src/<title.(js|css)>
            if (ext in ['js', 'css'] and
                    dirpath.endswith('/src') and
                    (not repo or repo in name)):
                # FIXME: Skip unchanged files (use git status?)
                # Check for allowNullEdits
                title = userPrefix + name
                repoName = dirpath.rsplit('/', 2)[-2]
                summary = gitHubSummary % (gitHubUrl % repoName)
                code = open(os.path.join(dirpath, name), 'r').read()
                if ext == 'js':
                    try:
                        minCode = uglipyjs.compile(
                            code, {'preserveComments': 'some'})
                        minCode = minCode.decode('utf-8')
                        # summary = summary + '; ' + uglifyjsSummary %
                        # (pkg_resources.get_distribution("uglipyjs").version)
                        uv = pkg_resources.get_distribution("uglipyjs").version
                        summary = '{}; {}'.format(
                            summary, uglifyjsSummary % uv)
                    except execjs.ProgramError:
                        minCode = code.decode('utf-8')
                    newMinCode = re.sub(
                        r'(/\*\*\n \*.+? \*/\n)',
                        r'\1// <nowiki>\n',
                        minCode,
                        flags=re.DOTALL)
                    if newMinCode == minCode:
                        newMinCode = '// <nowiki>\n' + minCode
                    minCode = newMinCode + '\n// </nowiki>'
                    if tracking:
                        minCode = '// ' + (tracking % title) + '\n' + minCode
                else:
                    minCode = '/* <nowiki> */\n' + code + '\n/* </nowiki> */'
                    if tracking:
                        # minCode = '/* ' + (tracking % title) +
                        # ' */\n' + minCode
                        minCode = '/* {} */\n{}'.format(
                            tracking % title, minCode)
                page = pywikibot.Page(site, title)
                page.text = minCode
                page.save(summary)
    page = pywikibot.Page(site, 'User:He7d3r/global.js')
    page.text = ('// [[File:User:He7d3r/global.js]] (workaround for'
                 ' [[phab:T35355]])\n//{ {subst:User:He7d3r/Tools.js}}\n'
                 '{{subst:User:He7d3r/Tools.js}}')
    page.save('Update')
示例#7
0
bar = Bar('Collecting and compressing script files',
          max=len(js_files) + len(libs) - 2)

for lib in libs:
    curr = open(os.path.join('static', 'js', 'lib', lib), 'r')
    js_text += curr.read()
    curr.close()
    bar.next()

for file_name in js_files:
    if file_name == 'script.min.js' or not os.path.isfile(
            os.path.join('static', 'js', file_name)):
        continue
    curr = open(os.path.join('static', 'js', file_name), 'r')
    curr_text = curr.read()
    js_text += uglipyjs.compile(curr_text)
    curr.close()
    bar.next()

bar.finish()
print '=> Writing minified JS file'
js_file.write(js_text)
js_file.close()

print '\nStart CSS compression'
print '=====================\n'
css_files = os.listdir('static/css')
css_file = open('static/css/style.min.css', 'w')
css_text = ''
bar = Bar('Collecting CSS files', max=len(css_files) - 1)
for file_name in css_files:
示例#8
0
def minify_js(js_text):
    return uglipyjs.compile(js_text)
示例#9
0
	def evaluate(self,scope, locals, block=None):
		if not hasattr(self,'output') or not self.output:
			import uglipyjs
			self.output = uglipyjs.compile(self.data)

		return self.output
示例#10
0
def main(*args):
    tracking = False
    gitHubUser = False
    repo = False
    rootDir = os.getcwd()
    gitHubUrl = 'https://github.com/%s'
    # FIXME: Add git hash/version as in
    # "Sync with https://github.com/FOO/BAR (v9.9.9 or HASH)"
    gitHubSummary = u'Sync with %s'
    # FIXME: Add UglifyJS version as in
    # "minify with UglifyJS v9.9.9"
    uglifyjsSummary = u'minify with UgliPyJS %s'
    for arg in pywikibot.handleArgs():
        if arg == "-all":
            allowNullEdits = True
        elif arg == "-track":
            # The file link is unnecessary on GitHub but useful on wiki
            tracking = u'[[File:%s]] (workaround for [[phab:T35355]])'
        elif arg.startswith('-prefix:'):
            userPrefix = arg[len('-prefix:'):]
        elif arg.startswith('-repo:'):
            repo = arg[len('-repo:'):]
        elif arg.startswith('-mypath:'):
            rootDir = arg[len('-mypath:'):]
        elif arg.startswith('-github:'):
            gitHubUser = arg[len('-github:'):]
    if not gitHubUser:
        print( 'Missing required paramenter -github:<username>.' )
        return
    gitHubUrl = ( gitHubUrl % gitHubUser ) + '/%s'
    site = pywikibot.Site() # pywikibot.Site( 'meta', 'meta' )
    for dirpath, dirnames, files in os.walk(rootDir):
        for name in files:
            ext = name.rsplit( '.', 1 )[-1].lower()
            # Assume the structure is <mypath>/<repo>/src/<title.(js|css)>
            if ext in [ 'js', 'css' ] and dirpath.endswith( '/src' ) and ( not repo or repo in name ):
                # FIXME: Skip unchanged files (use git status?)
                # Check for allowNullEdits
                title = userPrefix + name
                repoName = dirpath.rsplit( '/', 2 )[-2]
                summary = gitHubSummary % ( gitHubUrl % repoName )
                code = open( os.path.join( dirpath, name ), 'r' ).read()
                if ext == 'js':
                    try:
                        minCode = uglipyjs.compile( code ).decode('utf-8')
                        summary = summary + '; ' + uglifyjsSummary % ( pkg_resources.get_distribution("uglipyjs").version )
                    except execjs.ProgramError:
                        minCode = code.decode('utf-8')
                    newMinCode = re.sub(
                        r'(/\*\*\n \*.+? \*/\n)',
                        r'\1// <nowiki>\n',
                        minCode,
                        flags=re.DOTALL)
                    if newMinCode == minCode:
                        newMinCode = '// <nowiki>\n' + minCode
                    minCode = newMinCode + '\n// </nowiki>'
                    if tracking:
                        minCode = u'// ' + ( tracking % title ) + u'\n' + minCode
                else:
                    minCode = '/* <nowiki> */\n' + code.decode('utf-8') + '\n/* </nowiki> */'
                    if tracking:
                        minCode = u'/* ' + ( tracking % title ) + u' */\n' + minCode
                page = pywikibot.Page( site, title )
                page.text = minCode
                page.save( summary )