aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonan Amicel <ronan.amicel@gmail.com>2012-10-13 16:44:45 +0200
committerRonan Amicel <ronan.amicel@gmail.com>2012-10-13 17:01:49 +0200
commit375db7288418df603a814564751ee36546e03a0a (patch)
tree88c19f2e5eaa0d2f74850814707d06003e120d97
parentRename functions in Node.js module (diff)
downloadfabtools-375db7288418df603a814564751ee36546e03a0a.tar.xz
Factor out install_dependencies() in Node.js module
-rw-r--r--fabtools/nodejs.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/fabtools/nodejs.py b/fabtools/nodejs.py
index 00d0cd8..d59a74d 100644
--- a/fabtools/nodejs.py
+++ b/fabtools/nodejs.py
@@ -48,7 +48,7 @@ def install_from_source(version=DEFAULT_VERSION):
run('rm -rf %(filename)s %(foldername)s' % locals())
-def install_package(package=None, version=None, local=False):
+def install_package(package, version=None, local=False):
"""
Install a Node.js package.
@@ -64,20 +64,34 @@ def install_package(package=None, version=None, local=False):
# Install package locally
fabtools.nodejs.install_package('underscore', local=False)
- If no package name is given, then ``npm install`` will be run,
- which will locally install all packages specified in the
- ``package.json`` file in the current directory.
"""
- if package:
- if version:
- package += '@%s' % version
-
- if local:
- run('npm install -l %s' % package)
- else:
- sudo('HOME=/root npm install -g %s' % package)
+ if version:
+ package += '@%s' % version
+
+ if local:
+ run('npm install -l %s' % package)
else:
- run('npm install')
+ sudo('HOME=/root npm install -g %s' % package)
+
+
+def install_dependencies():
+ """
+ Install Node.js package dependencies.
+
+ This function calls ``npm install``, which will locally install all
+ packages specified as dependencies in the ``package.json`` file
+ found in the current directory.
+
+ ::
+
+ from fabric.api import cd
+ from fabtools import nodejs
+
+ with cd('/path/to/nodejsapp/'):
+ nodejs.install_dependencies()
+
+ """
+ run('npm install')
def update_package(package, local=False):