forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
76 lines (62 loc) · 2.09 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
from invoke import task, run
from website import settings
HERE = os.path.dirname(os.path.abspath(__file__))
WHEELHOUSE_PATH = os.environ.get('WHEELHOUSE')
@task()
def manage(cmd_str):
"""Take command string and target (-t) for manage commands
:param args: ex. runserver, migrate
"""
manage_cmd = os.path.join(HERE, '..', 'manage.py')
env = 'DJANGO_SETTINGS_MODULE="admin.base.settings"'
cmd = '{} python {} {}'.format(env, manage_cmd, cmd_str)
run(cmd, echo=True, pty=True)
@task()
def assets(dev=False, watch=False):
"""Install and build static assets for admin."""
if os.getcwd() != HERE:
os.chdir(HERE)
npm = 'npm install'
if not dev:
npm += ' --production'
run(npm, echo=True)
bower_install()
# Always set clean=False to prevent possible mistakes
# on prod
webpack(clean=False, watch=watch, dev=dev)
@task(aliases=['pack'])
def webpack(clean=False, watch=False, dev=False):
"""Build static assets with webpack."""
if clean:
clean_assets()
if os.getcwd() != HERE:
os.chdir(HERE)
webpack_bin = os.path.join(HERE, 'node_modules', 'webpack', 'bin',
'webpack.js')
args = [webpack_bin]
if settings.DEBUG_MODE and dev:
args += ['--colors']
else:
args += ['--progress']
if watch:
args += ['--watch']
config_file = 'webpack.admin.config.js' if dev else 'webpack.prod.config.js'
args += ['--config {0}'.format(config_file)]
command = ' '.join(args)
run(command, echo=True)
@task
def clean_assets():
"""Remove built JS files."""
public_path = os.path.join(HERE, 'static', 'public')
js_path = os.path.join(public_path, 'js')
run('rm -rf {0}'.format(js_path), echo=True)
@task(aliases=['bower'])
def bower_install():
if os.getcwd() != HERE:
os.chdir(HERE)
bower_bin = os.path.join(HERE, 'node_modules', 'bower', 'bin', 'bower')
run('{} prune'.format(bower_bin), echo=True)
run('{} install'.format(bower_bin), echo=True)