8fca3208c75343f7f978468231041b4f2de9b406
[redakcja.git] / apps / build / management / commands / build.py
1 import os
2 from subprocess import call
3 from optparse import make_option
4
5 from django.core.management.base import BaseCommand, CommandError
6 from django.core.management import call_command
7
8
9 class Command(BaseCommand):
10     
11     option_list = BaseCommand.option_list + (
12         make_option('--node-bin-path',
13             action='store',
14             dest='node_bin_path',
15             type='string',
16             default=None,
17             help='Path to node binary'),
18         make_option('--npm-bin',
19             action='store',
20             dest='npm_bin',
21             type='string',
22             default='npm',
23             help='Path to npm binary'),
24         )
25
26     def handle(self, **options):
27         wiki_base_dir = os.path.join(os.getcwd(), 'apps', 'wiki', 'static', 'wiki')
28         rng_base_dir = os.path.join(wiki_base_dir, 'editor')
29         build_dir = os.path.join(wiki_base_dir, 'build')
30
31         self.stdout.write('Installing editor dependencies')
32         try:
33             call([options['npm_bin'], 'install'], cwd = rng_base_dir)
34         except OSError:
35             raise CommandError('Something went wrong, propably npm binary not found. Tried: %s' % options['npm_bin'])
36
37         self.stdout.write('Building editor')
38         if options['node_bin_path']:
39             # grunt needs npm binary to be foundable in PATH
40             os.environ['PATH'] = '%s:%s' % (options['node_bin_path'], os.environ['PATH'])
41         call(['./node_modules/.bin/grunt', 'build', '--output-dir=%s' % build_dir], cwd = rng_base_dir)
42
43         call_command('collectstatic', interactive = False, ignore_patterns = ['editor'])