Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge :: feature 생성 자동화 + Dependency extension 자동화 #24

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ reset:
tuist clean
rm -rf **/*.xcodeproj
rm -rf *.xcworkspace

feature:
python3 Scripts/generate_new_feature.py
32 changes: 30 additions & 2 deletions Scripts/generate_new_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def make_dirs(paths):
def make_project_file(feature_name, file_path, has_demo=False, dependencies=[]):
project_path = file_path + '/Project.swift'
file_name = file_path.split('/')[-1]
file_content = f"""
import ProjectDescription
file_content = f"""import ProjectDescription
import ProjectDescriptionHelpers

let project = Project.makeModule(
Expand Down Expand Up @@ -131,7 +130,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
'''
write_code_in_file(app_delegate_path, app_delegate)

def write_created_feature_on_dependency_project(feature_name):
file_path = f'{root_path}/Plugin/UtilityPlugin/ProjectDescriptionHelpers/Dependency+Project.swift'
read_file = read_file_at(file_path)
updated_file = update_file_at(read_file, feature_name)
write_file_at(file_path, updated_file)

def read_file_at(file_path):
with open(file_path, 'r') as file:
return file.readlines()

def update_file_at(dependency_file, feature_name):
dependency_file_len = len(dependency_file)
for index, elem in enumerate(dependency_file):
if "public extension TargetDependency.Project.Features" in elem:
insert_line = index + 1
break

append_code = f' static let {feature_name}Feature = TargetDependency.feature(name: "{feature_name}Feature")\n'

if dependency_file_len > int(insert_line):
dependency_file.insert(insert_line, append_code)

return dependency_file

def write_file_at(file_path, update_file):
with open(file_path, 'w') as file:
file.writelines(update_file)


print('Input new feature name ', end=': ', flush=True)
Expand All @@ -149,3 +174,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
os.chdir(root_path + '/Projects/Features')

make_new_feature(feature_name, has_demo)
write_created_feature_on_dependency_project(feature_name)

print(f'Created {feature_name}Feature Module')