Skip to content

Commit

Permalink
Merge pull request #38 from carrot/ensure-deps
Browse files Browse the repository at this point in the history
ensure template's deps are installed
  • Loading branch information
Jeff Escalante committed Dec 12, 2014
2 parents f11677b + b9e0690 commit 1ab79e9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
test/testproj
coverage
5 changes: 5 additions & 0 deletions lib/api/init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -78,6 +79,10 @@ class Init extends Base
match = name.match(/@+([^@]*)$/)
if match then match[1] else false

install_template_dependencies = ->
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')
if not fs.existsSync(init_file) then return @config = {}
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/install_deps/init.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_ = require 'lodash'

exports.configure = [
{
type: 'input',
name: 'foo',
message: 'What is basic foo from basic/init.coffee?'
}
]
14 changes: 14 additions & 0 deletions test/fixtures/install_deps/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions test/fixtures/install_deps/root/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>basic template: <%= foo %></p>
12 changes: 12 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 1ab79e9

Please sign in to comment.