Skip to content

Commit

Permalink
Cleanup doit targets
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Oct 5, 2024
1 parent cd02403 commit d0db9f9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:
packages: python3-doit

- name: Build apk
run: doit build_apk
run: doit build:apk
98 changes: 60 additions & 38 deletions dodo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from doit.tools import title_with_actions, LongRunning
from doit.tools import title_with_actions, LongRunning, Interactive
from doit import get_var
import atexit
import glob
import os
import platform
import shutil
import signal
import sys

atexit.register(
lambda: shutil.rmtree('__pycache__', ignore_errors=True))
Expand All @@ -14,9 +18,23 @@
'verbosity': 2,
}

VARIANT = get_var('variant', 'release')
WATCH = get_var('watch', 'false')

# Delete all files matching glob pattern.
def _delete_files(pattern):
def task():
for path in glob.glob(pattern):
print(f'Removing {path}', file=sys.stderr)
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
return task

# doit analyze
def task_analyze():
"""run analyzer"""
"""run dart analyzer"""
return {
'actions': ['flutter analyze --fatal-infos --fatal-warnings'],
'title': title_with_actions,
Expand All @@ -30,84 +48,88 @@ def task_test():
'title': title_with_actions,
}

# doit exec
def task_exec():
"""run on device"""
# doit launch [variant=debug|release]
def task_launch():
"""deploy and run on device"""
return {
'actions': [LongRunning('flutter run --release')],
'actions': [Interactive(f'flutter run --{VARIANT}')],
'title': title_with_actions,
}

# doit build_apk
# doit build [variant=debug|release]
def task_build():
"""build for all platforms"""
return {
'basename': 'build',
'actions': None,
'task_dep': ['build:apk'],
}

# doit build:apk [variant=debug|release]
def task_build_apk():
"""build android apk"""
return {
'actions': ['flutter build apk --release'],
'basename': 'build:apk',
'actions': [f'flutter build apk --{VARIANT}'],
'title': title_with_actions,
}

# doit wipe
def task_wipe():
"""clean build artifacts"""
"""remove all build artifacts"""
return {
'actions': ['flutter clean'],
'actions': [
'flutter clean',
_delete_files('android/.gradle'),
],
'title': title_with_actions,
}

# doit gen
def task_gen():
"""run all flutter code generation"""
"""run all code generators"""
return {
'actions': [get_action(task_gen_model()),
get_action(task_gen_agent())],
'title': title_with_actions,
'basename': 'gen',
'actions': None,
'task_dep': ['gen:model', 'gen:agent'],
}

# doit gen_model
# doit gen:model [watch=true|false]
def task_gen_model():
"""run flutter build_runner Model code generation"""
if WATCH == 'true':
subcmd = 'watch'
else:
subcmd = 'build'
return {
'actions': ['dart run build_runner build --delete-conflicting-outputs'],
'basename': 'gen:model',
'actions': [f'dart run build_runner {subcmd} --delete-conflicting-outputs'],
'title': title_with_actions,
}

# doit gen_model_watch
def task_gen_model_watch():
"""run flutter build_runner Moddel code watch generation"""
return {
'actions': [LongRunning('dart run build_runner watch --delete-conflicting-outputs')],
'title': title_with_actions,
}

# doit gen_agent
# doit gen:agent
def task_gen_agent():
"""run flutter pigeon Agent code generation"""
return {
'basename': 'gen:agent',
'actions': ['dart run pigeon --input lib/src/agent/android_connector.dart'],
'title': title_with_actions,
}

# doit icons
def task_icons():
# doit gen:icons
def task_gen_icons():
"""run flutter icons generation (flutter_launcher_icons)"""
return {
'basename': 'gen:icons',
'actions': ['dart run flutter_launcher_icons'],
'title': title_with_actions,
}

# doit splash
def task_splash():
# doit gen:splash
def task_gen_splash():
"""run flutter splash screens generation (flutter_native_splash)"""
return {
'basename': 'gen:splash',
'actions': ['dart run flutter_native_splash:create '],
'title': title_with_actions,
}

# Get first doit method 'actions' value
def get_action(dic):

for key, value in dic.items():
if key == 'actions':
return value[0]

return "action doesn't exist"

0 comments on commit d0db9f9

Please sign in to comment.