Skip to content

Commit

Permalink
Merge pull request #24 from team-aliens/feat/23-in-makefile-feature-c…
Browse files Browse the repository at this point in the history
…reate-command

merge :: feature 생성 자동화 + Dependency extension 자동화
  • Loading branch information
baekteun authored Sep 26, 2022
2 parents 56b63f8 + 4210636 commit 33843f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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')

0 comments on commit 33843f9

Please sign in to comment.