Beispiel #1
0
def scaffold(name, actions):
    camel_case_name = to_camel_case(name)
    templ_vars = {
        'class_name': to_camel_case(name).capitalize(),
        'less_name': name.replace('_', '-'),
        'redux_name': first_to_lower(name),
        'type_name': name.upper()
    }
    files = {
        "./constants/" + camel_case_name + "Types.js": types_template,
        "./actions/" + camel_case_name + "Actions.js": action,
        "./reducers/" + camel_case_name + "Reducer.js": reducer
    }

    for filename, template in files.iteritems():
        with open(filename, "w+") as gen_file:
            gen_file.write(template % templ_vars)
            gen_file.close()

    with open('./reducers/rootReducer.js', 'r+') as c_file:
        text = c_file.read()

        export_index = re.search(r'const rootReducer', text).start()
        text = text[:export_index] + 'import ' + templ_vars['redux_name'] + "Reducer from './" + templ_vars['redux_name'] + "Reducer';\n\n" + text[export_index:]

        index = re.search(r'routing:', text).start()
        text = text[:index] + templ_vars['redux_name'] + 'Reducer' + ',\n\t' + text[index:]

        c_file.seek(0)
        c_file.truncate()
        c_file.write(text)
        c_file.close()
Beispiel #2
0
def container(name):
    templ_vars = {
        'class_name': to_camel_case(name.capitalize()),
        'less_name': name.replace('_', '-'),
        'redux_name': first_to_lower(name)
    }
    files = {
        "./src/containers/" + templ_vars['class_name'] + ".js": container_template,
        "./src/less/" + templ_vars['class_name'] + ".less": less
    }

    if os.path.exists("./src/containers/" + templ_vars['class_name'] + ".js"): print('Component already exists'); sys.exit()

    for filename, template in files.iteritems():
        with open(filename, "w+") as gen_file:
            gen_file.write(template % templ_vars)
            gen_file.close()