示例#1
0
文件: modules.py 项目: clexit/CaterJS
def create( args, options ):
    fe_chain = format.fe_chain( args )
    modules_names = args[1:]
    names_lng = len( modules_names )

    if ( names_lng == 0 ):
        if ( options.verbose_flag != False ):
            print 'Info: No module names were passed'
        return

    for module_name in modules_names:
        methods = module_name.split(':')[1:]
        module_name = module_name.split(':')[0]
        module_name = format.name( 'lower', module_name )

        if ( check.is_file_exists( module_name+'.js', options ) == False ):
            write_file( fe_chain, module_name, methods, options )
示例#2
0
文件: init.py 项目: clexit/CaterJS
def append_to_existed( fe_chain, modules_names, options ):
    cfile = open( '__init__.js', 'r' )
    cfile_content = cfile.read()

    start_marker = '//CaterJS init marker'
    start_marker_len = 0

    content_start_index = cfile_content.find( start_marker )

    if content_start_index is -1:
        cfile.close()
        print colorama.Fore.RED + 'Info: Cannot append module inits, because cannot find "//CaterJS init marker" in __init__.js',
        print colorama.Fore.RESET
        return
    
    content_start_index += start_marker_len

    part_top = cfile_content[ 0 : content_start_index ]
    part_bottom = cfile_content[ content_start_index : len( cfile_content ) ]

    append = ''

    for module_name in modules_names:
        module_name = module_name.split(':')[0]
        module_name = format.name( 'lower', module_name )
        content = fe_chain+'.'+module_name    # repo.Map.markers

        if ( content in cfile_content ):
            pass
        else:
            append += 'CaterJS.'+content+'.init();\n        '

    cfile = open( '__init__.js', 'w' )
    cfile.write( part_top + append + part_bottom )
    cfile.close()

    if ( options.verbose_flag != False ):
        print colorama.Fore.GREEN + '__init__.js modified: ',
示例#3
0
文件: init.py 项目: clexit/CaterJS
def create_new( fe_chain, modules_names ):
    FE = fe_chain.split('.')[0]

    init = open( '__init__.js', 'w' )
    content = '/**\n'
    content += ' * @description\n'
    content += ' */\n'
    content += 'window.CaterJS.'+fe_chain+' = (function() {\n'
    content += '    function init() {\n'

    for module_name in modules_names:
        module_name = module_name.split(':')[0]
        module_name = format.name( 'lower', module_name )
        content += '        CaterJS.'+fe_chain+'.'+module_name+'.init();\n'

    content += '        //CaterJS init marker\n'
    content += '    };\n\n'

    if ( FE == 'widgets' ):
        content += '    function shouldRun() {\n'
        content += '        if ( 0 === 1 ) {\n'
        content += '            return true;\n'
        content += '        } else {\n'
        content += '            return false;\n'
        content += '        };\n'
        content += '    };\n\n'

    content += '    return {\n'
    content += '        init: init\n'

    if ( FE == 'widgets' ):
        content += '      , shouldRun: shouldRun\n'

    content += '    };\n'
    content += '})();\n'

    init.write( content )
    init.close()