hotpocket/services/extension/tasks.py
Tomek Wójcik ab84f685c0 BTHLABS-51: Chrome Web Extension
Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl>
Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
2025-09-14 06:34:43 +00:00

133 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
# type: ignore
from __future__ import annotations
from invoke import task
from invoke.exceptions import UnexpectedExit
from hotpocket_workspace_tools import get_workspace_mode
WORKSPACE_MODE = get_workspace_mode()
@task
def clean(ctx):
ctx.run('rm -rf dist/')
@task
def test(ctx):
# ctx.run('pytest -v --disable-warnings')
print('NOOP')
@task
def flake8(ctx):
ctx.run('flake8')
@task
def isort(ctx, check=False, diff=False):
command_parts = [
'isort',
]
if check is True:
command_parts.append('--check')
if diff is True:
command_parts.append('--diff')
command_parts.append('.')
ctx.run(' '.join(command_parts))
@task
def eslint(ctx):
ctx.run('yarn run eslint')
@task
def lint(ctx):
ihazsuccess = True
try:
flake8(ctx)
except UnexpectedExit:
ihazsuccess = False
try:
isort(ctx, check=True)
except UnexpectedExit:
ihazsuccess = False
try:
eslint(ctx)
except UnexpectedExit:
ihazsuccess = False
if ihazsuccess is False:
raise RuntimeError('FIAL')
@task
def typecheck(ctx):
ctx.run('mypy .')
@task
def django_shell(ctx):
raise NotImplementedError()
@task
def ci(ctx):
ihazsuccess = True
ci_tasks = [test, lint, typecheck]
for ci_task in ci_tasks:
try:
ci_task(ctx)
except UnexpectedExit:
ihazsuccess = False
if ihazsuccess is False:
raise RuntimeError('FIAL')
@task
def setup(ctx):
print('NOOP')
@task
def start_web(ctx):
raise NotImplementedError()
@task
def start_safari(ctx):
ctx.run('yarn watch:safari')
@task(pre=[clean])
def start_chrome(ctx):
ctx.run('yarn watch:chrome')
@task
def build_safari(ctx):
ctx.run('yarn build:safari')
@task(pre=[clean])
def build_chrome(ctx):
ctx.run('yarn build:chrome')
ctx.run(' '.join([
r'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',
'--pack-extension=dist/chrome-production/',
'--pack-extension-key=secrets/chrome.pem',
]))