Commit 395e6476 authored by ∞'s avatar 💻

Rename before inclusion in CRUDLFA+ docs

parent 91f4cb0e
Monitor sub directories of INSTALLED_APPS: django-appwatch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Django-CollectDir: general purpose collectstatic alternative
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose you want to build a js directory from the js directory in all
INSTALLED_APPS::
This app provides a command named collectdir, which works like collectstatic
but general purpose, so you need to add ``'collectdir'`` to your
``settings.INSTALLED_APPS``. It can be used to mix Django with frontend
frameworks or build tools in NodeJS.
manage.py appwatch js:./js
Consider such a project directory tree:
- project/
- someapp/frontend # <- frontend dir in someapp module of project
- otherapp/frontend # <- frontend dir in another INSTALLED_APPS
- frontend/ # <- non commited directory, autogenerated from above
You can rebuild ``project/frontend`` with command::
# collect all app's frontend/ dir into ./frontend
manage.py collectdir frontend:./frontend
If it detects a TTY, and watchdog is installed, it will keep running and
synchronizing the target directory. To install collectdir with watchdog
example::
pip install --user django-collectdir[dev]
Note that in CRUDLFA+, we use ``js`` instead of frontend, so if you want to add
your own StimulusJS controllers to your bundle you can just add them in your
app. And before executing the frontend toolchain, run::
manage.py collectdir js:./js
Or, for NextJS support::
manage.py appwatch pages:./pages
Or, for NextJS support and also have a components sub dir::
Or, for NextJS and React support and also have a components sub dir::
manage.py appwatch pages:./pages components:./pages/components
Install with:
- ``pip install django-appwatch``
- Add ``appwatch`` to ``INSTALLED_APPS``
Have fun provisionning other frameworks with Django :)
Have fun provisionning other frameworks with Django apps :)
.. image:: screenshot.png
from appwatch.command import Command
from colored import fg, bg, attr
import sys
from datetime import datetime
import filecmp
......@@ -184,6 +185,32 @@ class Handler(FileSystemEventHandler):
class Command(BaseCommand):
help = '''
This command builds a target directory using a named sub directory from
each INSTALLED_APPS as source in a similar way collectstatic does, but
general purpose.
To populate the ./js directory with the js/ directory inside each app, just
run the command with argument: js:./js
'''.strip()
def add_arguments(self, parser):
parser.add_argument(
'directory:destination',
help='Collect dir and target as such: app:/path/to/target',
nargs='+',
)
parser.add_argument(
'-b',
'--build-only',
'--buildonly',
action='store_true',
dest='noninteractive',
default=not sys.stdout.isatty(),
help='Run and exit without spawning any observer.',
)
def handle(self, *args, **options):
self.observers = {}
......@@ -203,9 +230,16 @@ class Command(BaseCommand):
shutil.rmtree(dest)
print()
# Execute it first
run(source, destination)
if options.get('noninteractive', False):
print(
bg('green_1'),
'Built !',
attr('reset'),
)
sys.exit(0)
for arg in args:
source, destination = arg.split(':')
# Add observers to execute it on file change
......
......@@ -11,13 +11,13 @@ def read(fname):
setup(
name='django-appwatch',
version='0.0.0',
description='Watch Django INSTALLED_APPS and copy files',
name='django-collectdir',
version='1.0.0',
description='Generic purpose collecstatic alternative, with lovely colors',
author='James Pic',
author_email='jamespic@gmail.com',
url='https://git.yourlabs.org/oss/django-appwatch',
packages=['appwatch'],
url='https://git.yourlabs.org/oss/django-collectdir',
packages=['collectdir'],
include_package_data=True,
long_description=read('README.rst'),
license='MIT',
......@@ -27,7 +27,7 @@ setup(
tests_require=['tox'],
extras_require=dict(
dev=[
'django>=2.0',
'watchdog>=0.8.3,<0.9',
],
),
classifiers=[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment