Skip to content

Commit 6778db2

Browse files
jawshooahsds
authored andcommitted
Add NpmInstall post-{commit,checkout,merge,rewrite} hooks
1 parent 3b41109 commit 6778db2

File tree

9 files changed

+200
-0
lines changed

9 files changed

+200
-0
lines changed

config/default.yml

+40
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ PostCheckout:
527527
quiet: true
528528
required_executable: 'ctags'
529529

530+
NpmInstall:
531+
enabled: false
532+
description: 'Installing NPM dependencies'
533+
requires_files: true
534+
required_executable: 'npm'
535+
flags: ['install']
536+
include:
537+
- 'package.json'
538+
- 'npm-shrinkwrap.json'
539+
530540
SubmoduleStatus:
531541
enabled: false
532542
description: 'Checking submodule status'
@@ -554,6 +564,16 @@ PostCommit:
554564
quiet: true
555565
required_executable: 'ctags'
556566

567+
NpmInstall:
568+
enabled: false
569+
description: 'Installing NPM dependencies'
570+
requires_files: true
571+
required_executable: 'npm'
572+
flags: ['install']
573+
include:
574+
- 'package.json'
575+
- 'npm-shrinkwrap.json'
576+
557577
SubmoduleStatus:
558578
enabled: false
559579
description: 'Checking submodule status'
@@ -572,6 +592,16 @@ PostMerge:
572592
quiet: true
573593
required_executable: 'ctags'
574594

595+
NpmInstall:
596+
enabled: false
597+
description: 'Installing NPM dependencies'
598+
requires_files: true
599+
required_executable: 'npm'
600+
flags: ['install']
601+
include:
602+
- 'package.json'
603+
- 'npm-shrinkwrap.json'
604+
575605
SubmoduleStatus:
576606
enabled: false
577607
description: 'Checking submodule status'
@@ -590,6 +620,16 @@ PostRewrite:
590620
quiet: true
591621
required_executable: 'ctags'
592622

623+
NpmInstall:
624+
enabled: false
625+
description: 'Installing NPM dependencies'
626+
requires_files: true
627+
required_executable: 'npm'
628+
flags: ['install']
629+
include:
630+
- 'package.json'
631+
- 'npm-shrinkwrap.json'
632+
593633
SubmoduleStatus:
594634
enabled: false
595635
description: 'Checking submodule status'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/npm_install'
2+
3+
module Overcommit::Hook::PostCheckout
4+
# Runs `npm install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::NpmInstall}
8+
class NpmInstall < Base
9+
include Overcommit::Hook::Shared::NpmInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/npm_install'
2+
3+
module Overcommit::Hook::PostCommit
4+
# Runs `npm install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::NpmInstall}
8+
class NpmInstall < Base
9+
include Overcommit::Hook::Shared::NpmInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/npm_install'
2+
3+
module Overcommit::Hook::PostMerge
4+
# Runs `npm install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::NpmInstall}
8+
class NpmInstall < Base
9+
include Overcommit::Hook::Shared::NpmInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/npm_install'
2+
3+
module Overcommit::Hook::PostRewrite
4+
# Runs `npm install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::NpmInstall}
8+
class NpmInstall < Base
9+
include Overcommit::Hook::Shared::NpmInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostCheckout::NpmInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when npm install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when npm install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostCommit::NpmInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when npm install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when npm install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostMerge::NpmInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when npm install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when npm install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostRewrite::NpmInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when npm install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when npm install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stderr: "npm ERR! install Couldn't read dependencies")
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end

0 commit comments

Comments
 (0)