From 63b38daeba50edd5df21e61209cc586986e3269e Mon Sep 17 00:00:00 2001 From: Paul B Date: Mon, 8 Sep 2014 15:06:21 +0200 Subject: [PATCH 1/2] Add npm support with a simple npm:install task --- Readme.md | 22 ++++++++++++++++++++++ lib/mina/npm.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/mina/npm.rb diff --git a/Readme.md b/Readme.md index 623fe8dd..4a3f3a7a 100644 --- a/Readme.md +++ b/Readme.md @@ -975,6 +975,28 @@ end Adds settings and tasks for managing projects with [whenever]. [whenever]: http://rubygems.org/gems/whenever +# Modules: NPM +Adds settings and tasks for managing NodeJS projects. + +~~~ ruby +require 'mina/npm' +~~~ + +## Settings +Any and all of these settings can be overriden in your `deploy.rb`. + +### npm_options +Parameters to pass to the npm binary. Default to `--production`. + +---- + +## Deploy tasks +These tasks are meant to be invoked inside deploy scripts, not invoked on +their own. + +### npm:install + + Acknowledgements ---------------- diff --git a/lib/mina/npm.rb b/lib/mina/npm.rb new file mode 100644 index 00000000..be190666 --- /dev/null +++ b/lib/mina/npm.rb @@ -0,0 +1,36 @@ +# # Modules: Npm +# Adds settings and tasks for managing Node packages. +# +# require 'mina/npm' + +# ## Settings +# Any and all of these settings can be overriden in your `deploy.rb`. + +# ### npm_bin +# Sets the npm binary. + +set_default :npm_bin, 'npm' + +# ### npm_options +# Sets the options for installing modules via npm. + +set_default :npm_options, lambda { %{--production} } + +# ## Deploy tasks +# These tasks are meant to be invoked inside deploy scripts, not invoked on +# their own. + +namespace :npm do + # ### npm:install + # Installs node modules. Takes into account if executed `in_directory` and namespaces the installed modules in the shared folder. + desc "Install node modules using Npm." + task :install => :environment do + queue %{ + echo "-----> Installing node modules using Npm" + sub_directory=$(pwd | sed -r "s/.*?$(basename $build_path)//g") + #{echo_cmd %[mkdir -p "#{deploy_to}/#{shared_path}/$sub_directory/node_modules"]} + #{echo_cmd %[ln -s "#{deploy_to}/#{shared_path}/$sub_directory/node_modules/" "node_modules"]} + #{echo_cmd %[#{npm_bin} install #{npm_options}]} + } + end +end From d2fc4894b6f099a5f7c33eb907f2a5f593997121 Mon Sep 17 00:00:00 2001 From: Paul B Date: Fri, 31 Oct 2014 17:23:36 +0100 Subject: [PATCH 2/2] Add bower and grunt tasks for npm support --- lib/mina/npm.rb | 57 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/mina/npm.rb b/lib/mina/npm.rb index be190666..44498fb7 100644 --- a/lib/mina/npm.rb +++ b/lib/mina/npm.rb @@ -11,10 +11,36 @@ set_default :npm_bin, 'npm' +# ### bower_bin +# Sets the bower binary. + +set_default :bower_bin, 'bower' + +# ### grunt_bin +# Sets the grunt binary. + +set_default :grunt_bin, 'grunt' + # ### npm_options # Sets the options for installing modules via npm. -set_default :npm_options, lambda { %{--production} } +set_default :npm_options, '--production' + +# ### bower_options +# Sets the options for installing modules via bower. + +set_default :bower_options, '--allow-root' + +# ### grunt_options +# Sets the options for grunt. + +set_default :grunt_options, '' + +# ### grunt_task +# Sets the task parameters for grunt. + +set_default :grunt_task, 'build' + # ## Deploy tasks # These tasks are meant to be invoked inside deploy scripts, not invoked on @@ -29,8 +55,35 @@ echo "-----> Installing node modules using Npm" sub_directory=$(pwd | sed -r "s/.*?$(basename $build_path)//g") #{echo_cmd %[mkdir -p "#{deploy_to}/#{shared_path}/$sub_directory/node_modules"]} - #{echo_cmd %[ln -s "#{deploy_to}/#{shared_path}/$sub_directory/node_modules/" "node_modules"]} + #{echo_cmd %[ln -s "#{deploy_to}/#{shared_path}/$sub_directory/node_modules" "node_modules"]} #{echo_cmd %[#{npm_bin} install #{npm_options}]} } end end + +namespace :bower do + # ### bower:install + # Installs bower modules. Takes into account if executed `in_directory` and namespaces the installed modules in the shared folder. + desc "Install bower modules." + task :install => :environment do + queue %{ + echo "-----> Installing bower modules" + sub_directory=$(pwd | sed -r "s/.*?$(basename $build_path)//g") + #{echo_cmd %[mkdir -p "#{deploy_to}/#{shared_path}/$sub_directory/bower_components"]} + #{echo_cmd %[ln -s "#{deploy_to}/#{shared_path}/$sub_directory/bower_components" "bower_components"]} + #{echo_cmd %[[ -f bower.json ] && (#{bower_bin} install #{bower_options}) || ! [ -f bower.json ]]} + } + end +end + +namespace :grunt do + # ### bower:install + # Installs bower modules. Takes into account if executed `in_directory` and namespaces the installed modules in the shared folder. + desc "Launch a task with grunt. Set the grunt_task (defaults to \"build\") variable before calling this." + task :task => :environment do + queue %{ + echo "-----> Launch a build with Grunt" + #{echo_cmd %[[ -f Gruntfile.js ] && (#{grunt_bin} #{grunt_task} #{grunt_options}) || ! [ -f Gruntfile.js ]]} + } + end +end