Skip to content

Commit

Permalink
Merge pull request #70 from nimblehq/feature/66-update-init-script
Browse files Browse the repository at this point in the history
[#66] As a developer, I can update the init script to generate a new project from `.template` directory
  • Loading branch information
manh-t authored Apr 15, 2022
2 parents 770c0fc + 1bba152 commit 5b46979
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PYTHON3 := $(shell command -v python3 2> /dev/null)
VENV_ACTIVATE=$(VENV_NAME)/bin/activate
PYTHON=$(VENV_NAME)/bin/python3

PROJECT_PATH=$(PWD)/.template
PACKAGE_NAME=
PROJECT_NAME=
APP_NAME=
Expand Down Expand Up @@ -40,7 +41,7 @@ prepare-dev:
$(PYTHON) -m pip install enquiries

init: prepare-dev
$(PYTHON) ./scripts/setup.py --project_path $(PWD) --package_name "$(PACKAGE_NAME)" --project_name "$(PROJECT_NAME)" --app_name "$(APP_NAME)" --app_version "$(APP_VERSION)" --build_number "$(BUILD_NUMBER)"
$(PYTHON) ./scripts/setup.py --project_path "$(PROJECT_PATH)" --package_name "$(PACKAGE_NAME)" --project_name "$(PROJECT_NAME)" --app_name "$(APP_NAME)" --app_version "$(APP_VERSION)" --build_number "$(BUILD_NUMBER)"

test: prepare-dev
$(PYTHON) ./scripts/test.py
Expand Down
24 changes: 21 additions & 3 deletions scripts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def handleParameters():
return parser.parse_args()


def validateParameters(project):
def validate_parameters(project):
# Check the mandatory fields should not be empty
if not project.new_package or not project.new_project_name or not project.new_app_name:
print("❌ PACKAGE_NAME, PROJECT_NAME and APP_NAME are required. Please fill the missing variables and try again!")
Expand All @@ -384,6 +384,19 @@ def validateParameters(project):
f"❌ Invalid App Version or Build Number: {project.app_version}+{project.build_number} (needs to follow standard pattern `app_version+build_number`. Eg: `1.0+1` or `0.1.0+1`)")
sys.exit()

def move_project_to_root(project):
cur_dir = os.getcwd()
shutil.copytree(project.project_path, cur_dir, copy_function=shutil.move, dirs_exist_ok=True)

def clean_up(files: list[str]):
cur_dir = os.getcwd()
for file in files:
file_path = cur_dir + os.sep + file
if os.path.exists(file_path):
if (os.path.isdir(file_path)):
shutil.rmtree(file_path)
else:
os.remove(file_path)

if __name__ == "__main__":
args = handleParameters()
Expand All @@ -396,7 +409,7 @@ def validateParameters(project):
args.app_version,
args.build_number
)
validateParameters(project)
validate_parameters(project)

options = {
'none' : 'none',
Expand All @@ -414,4 +427,9 @@ def validateParameters(project):
ios.run()
flutter = Flutter(project)
flutter.run()
print("=> 🚀 Done! App is ready to be tested 🙌")
print('🤖 Generating project...')
# Remove the `.github` folder to avoid redundant workflow
clean_up(['.github'])
move_project_to_root(project)
clean_up(['.template', 'LICENSE', 'Makefile'])
print("=> 🚀 Done! Project is ready for the next development 🙌")

0 comments on commit 5b46979

Please sign in to comment.