def create_brewjs_project(folder_path, name, author): """ Copies the files from templates/js to folder_path and modifies Source.js and package.json to include the app and author name. :param folder_path: Path to copy the files to :param name: Name of the project :param author: Name of the author """ template_folder = get_full_path(os.path.join("templates", "brewjs")) copy_tree(template_folder, folder_path) main_js_file = os.path.join(folder_path, "Source.js") main_js_replacements = { "APP_AUTHOR_PLACEHOLDER": author, "APP_NAME_PLACEHOLDER": name, "DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"), } replace_in_file(main_js_file, main_js_replacements) package_json_file = os.path.join(folder_path, "package.json") package_json_replacements = { "APP_AUTHOR_PLACEHOLDER": author, "APP_NAME_PLACEHOLDER": name, "DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"), } replace_in_file(package_json_file, package_json_replacements) check_and_create_directory(os.path.join(folder_path, "assets"))
def create_libnx_project(folder_path, name, author): """ Copies the files from templates/base to folder_path and modifies Makefile and source/main.cpp to include the project name, author name and current date. :param folder_path: Path to copy the files to :param name: Name of the project :param author: Name of the author """ template_folder = get_full_path(os.path.join('templates', 'cpp')) copy_tree(template_folder, folder_path) main_cpp_file = os.path.join(folder_path, 'source', 'main.cpp') main_cpp_replacements = { 'APP_AUTHOR_PLACEHOLDER': author, 'APP_NAME_PLACEHOLDER': name, 'DATE_PLACEHOLDER': datetime.datetime.now().strftime("%Y-%m-%d") } replace_in_file(main_cpp_file, main_cpp_replacements) makefile = os.path.join(folder_path, 'Makefile') makefile_replacements = { 'APP_NAME_PLACEHOLDER': name, 'APP_AUTHOR_PLACEHOLDER': author } replace_in_file(makefile, makefile_replacements)
def create_libt_project(folder_path, name, author): """ Copies the files from templates/base to folder_path and modifies Makefile and source/main.cpp to include the project name, author name and current date. :param folder_path: Path to copy the files to :param name: Name of the project :param author: Name of the author """ template_folder = get_full_path(os.path.join("templates", "libt")) copy_tree(template_folder, folder_path) main_c_file = os.path.join(folder_path, "main.c") main_c_replacements = { "APP_AUTHOR_PLACEHOLDER": author, "APP_NAME_PLACEHOLDER": name, "DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"), } replace_in_file(main_c_file, main_c_replacements) makefile = os.path.join(folder_path, "Makefile") makefile_replacements = { "APP_NAME_PLACEHOLDER": name, "APP_AUTHOR_PLACEHOLDER": author, } replace_in_file(makefile, makefile_replacements)
def create_readme_file(folder_path, name): """ Copies the README.md file from the templates folder to folder_path, and will use name as the title of the document. :param folder_path: Path to copy the file to :param name: Project name to use as the title """ template_readme_file = get_full_path(os.path.join('templates', 'README.md')) shutil.copy2(template_readme_file, folder_path) new_readme_file = os.path.join(folder_path, 'README.md') new_readme_file_replacements = {'APP_NAME_PLACEHOLDER': name} replace_in_file(new_readme_file, new_readme_file_replacements)
def create_cmake_lists_file(folder_path, folder_name): """ Copies the CMakeLists.txt file from the templates folder to folder_path, and will use folder_name as the project name. This is useful for people who use CLion as their IDE. :param folder_path: Path to copy the file to :param folder_name: Project folder name """ template_cmake_lists_file = get_full_path(os.path.join('templates', 'CMakeLists.txt')) shutil.copy2(template_cmake_lists_file, folder_path) cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt') cmake_lists_file_replacements = { 'FOLDER_NAME_PLACEHOLDER': folder_name } replace_in_file(cmake_lists_file, cmake_lists_file_replacements)
def test_replace_in_file(tmpdir): new_test_file_path = str(tmpdir.join("testfile.txt")) with open(new_test_file_path, "w") as f: f.write("TEXT_PLACEHOLDER") replace_in_file(new_test_file_path, {"TEXT_PLACEHOLDER": "NEW_TEXT"}) assert file_contains_strings(new_test_file_path, ["NEW_TEXT"])