Build can now use configurable path to node_modules
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 20 Dec 2013 13:49:18 +0000 (14:49 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 12 Aug 2014 09:47:11 +0000 (11:47 +0200)
This allows for sharing node_modules directory across
deployment releases.

apps/build/management/commands/build.py
deployment/base.py

index 8fca320..d87d3b4 100644 (file)
@@ -21,6 +21,12 @@ class Command(BaseCommand):
             type='string',
             default='npm',
             help='Path to npm binary'),
+        make_option('--editor-npm-env',
+            action='store',
+            dest='editor_npm_env',
+            type='string',
+            default=None,
+            help='Destination path of npm environment, defaults to ./node_modules'),
         )
 
     def handle(self, **options):
@@ -29,6 +35,12 @@ class Command(BaseCommand):
         build_dir = os.path.join(wiki_base_dir, 'build')
 
         self.stdout.write('Installing editor dependencies')
+        if options['editor_npm_env']:
+            npm_env = os.path.join(rng_base_dir, options['editor_npm_env'])
+            if not os.path.exists(npm_env):
+                os.makedirs(npm_env)
+            assert os.path.isdir(npm_env)
+            os.symlink(npm_env, os.path.join(rng_base_dir, 'node_modules'))
         try:
             call([options['npm_bin'], 'install'], cwd = rng_base_dir)
         except OSError:
index 5433325..3c1de90 100644 (file)
@@ -1,4 +1,6 @@
-from fabric.api import env
+import os
+
+from fabric.api import env, require
 from fabric.tasks import Task
 from fnpdjango.deploy import Command
 
@@ -17,7 +19,10 @@ class Environment(Task):
         for k,v in self.env_vars.items():
             env[k] = v
 
-        build_cmd = '../../ve/bin/python manage.py build --npm-bin=%s' % self.npm_bin
+        require('app_path')
+
+        build_cmd = '../../ve/bin/python manage.py build --npm-bin=%s --editor-npm-env=%s' \
+            % (self.npm_bin, os.path.join(env['app_path'], 'npm_env'))
         if 'node_bin_path' in self.env_vars:
             build_cmd += ' --node-bin-path=%s' % self.env_vars['node_bin_path']