-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clean and messages management script and update build script
- Loading branch information
1 parent
85ebe0d
commit cba45de
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import subprocess | ||
import sys | ||
|
||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
call_command('npm', 'ci') | ||
call_command('npm', 'run', 'build:prod') | ||
subprocess.call(['/bin/bash', '-c', f'{sys.executable} -m build']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import shutil | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('command', choices=[ | ||
'all', | ||
'dist', | ||
'media', | ||
'npm', | ||
'python', | ||
'static', | ||
]) | ||
|
||
def handle(self, *args, **options): | ||
if options['command'] in ['all', 'dist']: | ||
self.clean_dir('dist') | ||
self.clean_dir('rdmo.egg-info') | ||
if options['command'] in ['all', 'media']: | ||
self.clean_dir(settings.MEDIA_ROOT) | ||
if options['command'] in ['all', 'npm']: | ||
self.clean_dir('node_modules') | ||
if options['command'] in ['all', 'static']: | ||
self.clean_static() | ||
if options['command'] in ['all', 'python']: | ||
self.clean_python() | ||
|
||
def clean_python(self): | ||
for root, dirs, files in os.walk('.'): | ||
for dir_name in dirs: | ||
if dir_name == '__pycache__': | ||
self.clean_dir(os.path.join(root, dir_name), quiet=True) | ||
|
||
def clean_static(self): | ||
self.clean_dir(settings.STATIC_ROOT) | ||
|
||
for path in [ | ||
# 'rdmo/core/static', # TODO: enable after cleanup | ||
'rdmo/management/static', | ||
# 'rdmo/projects/static' # TODO: enable after cleanup | ||
]: | ||
self.clean_dir(path) | ||
|
||
def clean_dir(self, path, quiet=False): | ||
if path and os.path.exists(path): | ||
shutil.rmtree(path) | ||
if not quiet: | ||
print(f'Directory "{path}" has been removed!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import subprocess | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('command', choices=['make', 'compile']) | ||
|
||
def handle(self, *args, **options): | ||
if options['command'] == 'make': | ||
subprocess.check_call(['django-admin', 'makemessages', '--all'], cwd='rdmo') | ||
subprocess.check_call(['django-admin', 'makemessages', '--all', '-d', 'djangojs'], cwd='rdmo') | ||
|
||
elif options['command'] == 'compile': | ||
subprocess.check_call(['django-admin', 'compilemessages'], cwd='rdmo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
ROOT_URLCONF = '' | ||
|
||
DATABASES = {} | ||
|
||
STATIC_ROOT = 'static_root' |