From 2d8d013a1cdac6121c38d943fbcc21a9128b4eb3 Mon Sep 17 00:00:00 2001 From: Kyle MacDonald Date: Thu, 11 Dec 2014 14:06:01 -0500 Subject: [PATCH 1/2] ensure template's deps are installed --- lib/api/init.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/api/init.coffee b/lib/api/init.coffee index 79ec40f..605943a 100644 --- a/lib/api/init.coffee +++ b/lib/api/init.coffee @@ -19,6 +19,7 @@ class Init extends Base execute: (opts) -> configure_options.call(@, opts).with(@) + .then(install_template_dependencies) .then(get_user_init_file) .then(run_user_before_function) .then(remove_overrides_from_prompt) @@ -78,6 +79,10 @@ class Init extends Base match = name.match(/@+([^@]*)$/) if match then match[1] else false + install_template_dependencies = -> + pkg = path.join(@sprout_path, 'package.json') + if fs.existsSync(pkg) then nodefn.call(exec, "npm install", cwd: @sprout_path) + get_user_init_file = -> init_file = path.join(@sprout_path, 'init.coffee') if not fs.existsSync(init_file) then return @config = {} From b9e06909270b39da67f4cb6c6f40e86249e730d7 Mon Sep 17 00:00:00 2001 From: Josh Rowley Date: Fri, 12 Dec 2014 14:17:38 -0500 Subject: [PATCH 2/2] add test for deps installation --- .gitignore | 1 + lib/api/init.coffee | 4 ++-- test/fixtures/install_deps/init.coffee | 9 +++++++++ test/fixtures/install_deps/package.json | 14 ++++++++++++++ test/fixtures/install_deps/root/index.html | 1 + test/test.coffee | 12 ++++++++++++ 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/install_deps/init.coffee create mode 100644 test/fixtures/install_deps/package.json create mode 100644 test/fixtures/install_deps/root/index.html diff --git a/.gitignore b/.gitignore index a58c6c4..b38fdf6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store node_modules test/testproj +coverage diff --git a/lib/api/init.coffee b/lib/api/init.coffee index 605943a..2c97767 100644 --- a/lib/api/init.coffee +++ b/lib/api/init.coffee @@ -80,8 +80,8 @@ class Init extends Base if match then match[1] else false install_template_dependencies = -> - pkg = path.join(@sprout_path, 'package.json') - if fs.existsSync(pkg) then nodefn.call(exec, "npm install", cwd: @sprout_path) + p = path.join(@sprout_path, 'package.json') + if fs.existsSync(p) then nodefn.call(exec, "npm install", cwd: @sprout_path) get_user_init_file = -> init_file = path.join(@sprout_path, 'init.coffee') diff --git a/test/fixtures/install_deps/init.coffee b/test/fixtures/install_deps/init.coffee new file mode 100644 index 0000000..0ee2ab7 --- /dev/null +++ b/test/fixtures/install_deps/init.coffee @@ -0,0 +1,9 @@ +_ = require 'lodash' + +exports.configure = [ + { + type: 'input', + name: 'foo', + message: 'What is basic foo from basic/init.coffee?' + } +] diff --git a/test/fixtures/install_deps/package.json b/test/fixtures/install_deps/package.json new file mode 100644 index 0000000..f06e96e --- /dev/null +++ b/test/fixtures/install_deps/package.json @@ -0,0 +1,14 @@ +{ + "name": "install_deps", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT", + "dependencies": { + "lodash": "2.4.x" + } +} diff --git a/test/fixtures/install_deps/root/index.html b/test/fixtures/install_deps/root/index.html new file mode 100644 index 0000000..a58c610 --- /dev/null +++ b/test/fixtures/install_deps/root/index.html @@ -0,0 +1 @@ +

basic template: <%= foo %>

diff --git a/test/test.coffee b/test/test.coffee index 4031edc..8cbfa50 100644 --- a/test/test.coffee +++ b/test/test.coffee @@ -150,6 +150,18 @@ describe 'js api', -> .then -> sprout.remove('foobar') .should.be.fulfilled + it 'installs template dependencies', (done) -> + name = 'install_deps' + test_template = path.join(_path, name) + + sprout.add(name: name, uri: test_template, path: test_path) + .then -> sprout.init(name: name, path: test_path, overrides: {foo: 'bar'}) + .then -> + p = path.join(test_template, 'node_modules') + fs.existsSync(p).should.be.ok + .catch (e) -> done(e) + .done -> done() + it 'executes before function', -> test_template = path.join(_path, 'before') new_path = path.join(__dirname, 'newproj')