Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --skip-gulp parameter to collectstatic to disable running gulp #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ INSTALLED_APPS = (
Now when you run `./manage.py runserver` or `./manage.py collectstatic` your
`gulp` tasks will run as well!

Furthermore, you can use `./manage.py collectstatic --skip-gulp` to run `collectstatic` without running gulp. This may be useful during development if your gulp build takes a lot of time.

### Settings

`GULP_CWD` defaults to the current working directory. Override it if your `gulpfile.js` does not reside within the Django project's toplevel directory.
Expand Down
52 changes: 30 additions & 22 deletions django_gulp/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,41 @@ class Command(BaseCommand):
A version of collectstatic that runs `gulp build --production` first.
"""

def add_arguments(self, parser):
parser.add_argument('--skip-gulp',
action='store_true',
help="Do not run gulp, collectstatic will have vanilla behavior")
super().add_arguments(parser)

def handle(self, *args, **options):
if options['dry_run']:
return

popen_kwargs = {
'shell': True,
'stdin': subprocess.PIPE,
'stdout': self.stdout._out,
'stderr': self.stderr._out
}

# HACK: This command is executed without node_modules in the PATH
# when it's executed from Heroku... Ideally we wouldn't need any
# Heroku-specific code for this to work.
if os.path.exists('/app/requirements.txt'):
popen_kwargs['env'] = {
'PATH': (os.environ['PATH'] +
':/app/node_modules/.bin' +
':/app/.heroku/node/bin')
# Use --skip-gulp to skip running gulp on collectstatic
if not options['skip_gulp']:
popen_kwargs = {
'shell': True,
'stdin': subprocess.PIPE,
'stdout': self.stdout._out,
'stderr': self.stderr._out
}

gulp_cwd = getattr(settings, 'GULP_CWD', os.getcwd())
gulp_command = getattr(
settings, 'GULP_PRODUCTION_COMMAND', 'gulp build --cwd %s --production' % gulp_cwd)
try:
subprocess.check_call(gulp_command, **popen_kwargs)
except subprocess.CalledProcessError as e:
raise CommandError(e)
# HACK: This command is executed without node_modules in the PATH
# when it's executed from Heroku... Ideally we wouldn't need any
# Heroku-specific code for this to work.
if os.path.exists('/app/requirements.txt'):
popen_kwargs['env'] = {
'PATH': (os.environ['PATH'] +
':/app/node_modules/.bin' +
':/app/.heroku/node/bin')
}

gulp_cwd = getattr(settings, 'GULP_CWD', os.getcwd())
gulp_command = getattr(
settings, 'GULP_PRODUCTION_COMMAND', 'gulp build --cwd %s --production' % gulp_cwd)
try:
subprocess.check_call(gulp_command, **popen_kwargs)
except subprocess.CalledProcessError as e:
raise CommandError(e)

super(Command, self).handle(*args, **options)