Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ PostCheckout:
quiet: true
required_executable: 'ctags'

NpmInstall:
enabled: false
description: 'Installing NPM dependencies'
requires_files: true
required_executable: 'npm'
flags: ['install']
include:
- 'package.json'
- 'npm-shrinkwrap.json'

SubmoduleStatus:
enabled: false
description: 'Checking submodule status'
Expand Down Expand Up @@ -554,6 +564,16 @@ PostCommit:
quiet: true
required_executable: 'ctags'

NpmInstall:
enabled: false
description: 'Installing NPM dependencies'
requires_files: true
required_executable: 'npm'
flags: ['install']
include:
- 'package.json'
- 'npm-shrinkwrap.json'

SubmoduleStatus:
enabled: false
description: 'Checking submodule status'
Expand All @@ -572,6 +592,16 @@ PostMerge:
quiet: true
required_executable: 'ctags'

NpmInstall:
enabled: false
description: 'Installing NPM dependencies'
requires_files: true
required_executable: 'npm'
flags: ['install']
include:
- 'package.json'
- 'npm-shrinkwrap.json'

SubmoduleStatus:
enabled: false
description: 'Checking submodule status'
Expand All @@ -590,6 +620,16 @@ PostRewrite:
quiet: true
required_executable: 'ctags'

NpmInstall:
enabled: false
description: 'Installing NPM dependencies'
requires_files: true
required_executable: 'npm'
flags: ['install']
include:
- 'package.json'
- 'npm-shrinkwrap.json'

SubmoduleStatus:
enabled: false
description: 'Checking submodule status'
Expand Down
11 changes: 11 additions & 0 deletions lib/overcommit/hook/post_checkout/npm_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'overcommit/hook/shared/npm_install'

module Overcommit::Hook::PostCheckout
# Runs `npm install` when a change is detected in the repository's
# dependencies.
#
# @see {Overcommit::Hook::Shared::NpmInstall}
class NpmInstall < Base
include Overcommit::Hook::Shared::NpmInstall
end
end
11 changes: 11 additions & 0 deletions lib/overcommit/hook/post_commit/npm_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'overcommit/hook/shared/npm_install'

module Overcommit::Hook::PostCommit
# Runs `npm install` when a change is detected in the repository's
# dependencies.
#
# @see {Overcommit::Hook::Shared::NpmInstall}
class NpmInstall < Base
include Overcommit::Hook::Shared::NpmInstall
end
end
11 changes: 11 additions & 0 deletions lib/overcommit/hook/post_merge/npm_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'overcommit/hook/shared/npm_install'

module Overcommit::Hook::PostMerge
# Runs `npm install` when a change is detected in the repository's
# dependencies.
#
# @see {Overcommit::Hook::Shared::NpmInstall}
class NpmInstall < Base
include Overcommit::Hook::Shared::NpmInstall
end
end
11 changes: 11 additions & 0 deletions lib/overcommit/hook/post_rewrite/npm_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'overcommit/hook/shared/npm_install'

module Overcommit::Hook::PostRewrite
# Runs `npm install` when a change is detected in the repository's
# dependencies.
#
# @see {Overcommit::Hook::Shared::NpmInstall}
class NpmInstall < Base
include Overcommit::Hook::Shared::NpmInstall
end
end
13 changes: 13 additions & 0 deletions lib/overcommit/hook/shared/npm_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Overcommit::Hook::Shared
# Shared code used by all NpmInstall hooks. Runs `npm install` when a change
# is detected in the repository's dependencies.
#
# @see https://www.npmjs.com/
module NpmInstall
def run
result = execute(command)
return :fail, result.stderr unless result.success?
:pass
end
end
end
29 changes: 29 additions & 0 deletions spec/overcommit/hook/post_checkout/npm_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe Overcommit::Hook::PostCheckout::NpmInstall do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

let(:result) { double('result') }

before do
subject.stub(:execute).and_return(result)
end

context 'when npm install exits successfully' do
before do
result.stub(:success?).and_return(true)
end

it { should pass }
end

context 'when npm install exits unsuccessfully' do
before do
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
end

it { should fail_hook }
end
end
29 changes: 29 additions & 0 deletions spec/overcommit/hook/post_commit/npm_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe Overcommit::Hook::PostCommit::NpmInstall do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

let(:result) { double('result') }

before do
subject.stub(:execute).and_return(result)
end

context 'when npm install exits successfully' do
before do
result.stub(:success?).and_return(true)
end

it { should pass }
end

context 'when npm install exits unsuccessfully' do
before do
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
end

it { should fail_hook }
end
end
29 changes: 29 additions & 0 deletions spec/overcommit/hook/post_merge/npm_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe Overcommit::Hook::PostMerge::NpmInstall do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

let(:result) { double('result') }

before do
subject.stub(:execute).and_return(result)
end

context 'when npm install exits successfully' do
before do
result.stub(:success?).and_return(true)
end

it { should pass }
end

context 'when npm install exits unsuccessfully' do
before do
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
end

it { should fail_hook }
end
end
29 changes: 29 additions & 0 deletions spec/overcommit/hook/post_rewrite/npm_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe Overcommit::Hook::PostRewrite::NpmInstall do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

let(:result) { double('result') }

before do
subject.stub(:execute).and_return(result)
end

context 'when npm install exits successfully' do
before do
result.stub(:success?).and_return(true)
end

it { should pass }
end

context 'when npm install exits unsuccessfully' do
before do
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
end

it { should fail_hook }
end
end