2 from subprocess import call
3 from optparse import make_option
5 from django.core.management.base import BaseCommand, CommandError
6 from django.core.management import call_command
9 class Command(BaseCommand):
11 option_list = BaseCommand.option_list + (
12 make_option('--node-bin-path',
17 help='Path to node binary'),
18 make_option('--npm-bin',
23 help='Path to npm binary'),
24 make_option('--editor-npm-env',
26 dest='editor_npm_env',
29 help='Destination path of npm environment, defaults to ./node_modules'),
32 def handle(self, **options):
33 wiki_base_dir = os.path.join(os.getcwd(), 'apps', 'wiki', 'static', 'wiki')
34 rng_base_dir = os.path.join(wiki_base_dir, 'editor')
35 build_dir = os.path.join(wiki_base_dir, 'build')
37 self.stdout.write('Installing editor dependencies')
38 if options['editor_npm_env']:
39 npm_env = os.path.join(rng_base_dir, options['editor_npm_env'])
40 if not os.path.exists(npm_env):
42 assert os.path.isdir(npm_env)
43 os.symlink(npm_env, os.path.join(rng_base_dir, 'node_modules'))
45 call([options['npm_bin'], 'install'], cwd = rng_base_dir)
47 raise CommandError('Something went wrong, propably npm binary not found. Tried: %s' % options['npm_bin'])
49 self.stdout.write('Building editor')
50 if options['node_bin_path']:
51 # grunt needs npm binary to be foundable in PATH
52 os.environ['PATH'] = '%s:%s' % (options['node_bin_path'], os.environ['PATH'])
53 call(['./node_modules/.bin/grunt', 'build', '--output-dir=%s' % build_dir], cwd = rng_base_dir)
55 call_command('collectstatic', interactive = False, ignore_patterns = ['editor'])