Skip to content

Commit

Permalink
Optimized pre-commit-hook action.
Browse files Browse the repository at this point in the history
 - Added template inorder  to run grunt lint only if there are staged changes.
 - Added grunt lint-nofix task to run linter in no-fix mode.
 - Fixed some linting changes too.
  • Loading branch information
frappelatte28 committed Jan 5, 2021
1 parent f9e1885 commit 86476a4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
13 changes: 12 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ module.exports = function(grunt) {
fix: true
},
src: ['src/**/*.js', 'test/tests/**/*.js']
},
sourceNofix: {
options: {
configFile: './.eslintrc',
fix: false
},
src: ['src/**/*.js', 'test/tests/**/*.js']
}
},
webpack: {
Expand Down Expand Up @@ -59,7 +66,10 @@ module.exports = function(grunt) {
},
githooks: {
all: {
'pre-commit':'lint' //runs linting test before every git commit
options:{
template:"templates/pre-commit-hook.js"
},
'pre-commit':'lint-nofix' //runs linting test before every git commit
}
}
});
Expand All @@ -73,6 +83,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-githooks');

grunt.registerTask('lint', ['eslint:source']);
grunt.registerTask('lint-nofix', ['eslint:sourceNofix']);
grunt.registerTask('default', ['webpack:prod', 'decomment']);
grunt.registerTask('dev', ['eslint','connect','webpack:dev', 'decomment']);
grunt.registerTask('serve', 'connect:server:keepalive');
Expand Down
24 changes: 1 addition & 23 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ p5.prototype.userStartAudio = userStartAudio;

import './master';


import {
sampleRate,
freqToMidi,
Expand All @@ -21,10 +20,7 @@ import {
interleave,
writeUTFBytes,
safeBufferSize,

saveSound


saveSound,
} from './helpers';
p5.prototype.sampleRate = sampleRate;
p5.prototype.freqToMidi = freqToMidi;
Expand All @@ -44,7 +40,6 @@ p5.prototype.saveSound = saveSound;
// Oscillators etc when sketch ends
p5.prototype.registerMethod('remove', p5.prototype.disposeSound);


import './errorHandler';
import './audioWorklet';

Expand All @@ -57,7 +52,6 @@ p5.prototype.loadSound = loadSound;
// register preload handling of loadSound
p5.prototype.registerPreloadMethod('loadSound', p5.prototype);


import Amplitude from './amplitude';
p5.Amplitude = Amplitude;

Expand All @@ -75,15 +69,12 @@ p5.SqrOsc = SqrOsc;

import './envelope';


import Noise from './noise';
p5.Noise = Noise;

import Pulse from './pulse';
p5.Pulse = Pulse;



import AudioIn from './audioin';
p5.AudioIn = AudioIn;

Expand All @@ -108,42 +99,29 @@ p5.Panner3D = Panner3D;
import Delay from './delay';
p5.Delay = Delay;




import { Reverb, Convolver, createConvolver } from './reverb';
p5.Reverb = Reverb;
p5.Convolver = Convolver;
p5.prototype.createConvolver = createConvolver;
p5.prototype.registerPreloadMethod('createConvolver', p5.prototype);



import Metro from './metro';
p5.Metro = Metro;


import { Phrase, Part, Score } from './looper';
p5.Phrase = Phrase;
p5.Part = Part;
p5.Score = Score;


import SoundLoop from './soundLoop';
p5.SoundLoop = SoundLoop;


import Compressor from './compressor';
p5.Compressor = Compressor;



import peakDetect from './peakDetect';
p5.peakDetect = peakDetect;




import SoundRecorder from './soundRecorder';
p5.SoundRecorder = SoundRecorder;

Expand Down
4 changes: 1 addition & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ function safeBufferSize(idealBufferSize) {
return bufferSize;
}


/**
* Save a p5.SoundFile as a .wav file. The browser will prompt the user
* to download the file to their device.
Expand All @@ -349,7 +348,6 @@ function saveSound(soundFile, fileName) {
p5.prototype.writeFile([dataView], fileName, 'wav');
}


export {
sampleRate,
freqToMidi,
Expand All @@ -363,5 +361,5 @@ export {
interleave,
writeUTFBytes,
safeBufferSize,
saveSound
saveSound,
};
2 changes: 0 additions & 2 deletions src/panner.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,4 @@ if (typeof ac.createStereoPanner !== 'undefined') {
panner = Panner;
}


export default panner;

32 changes: 32 additions & 0 deletions templates/pre-commit-hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// hooks/pre-commit.js

var exec = require('child_process').exec;
// Executes shell commands synchronously
var sh = require('child_process').execSync;

exec('git diff --cached --quiet', function (err, stdout, stderr) {

// only run if there are staged changes
// i.e. what you would be committing if you ran "git commit" without "-a" option.
if (err) {

// stash unstaged changes - only test what's being committed
sh('git stash --keep-index --quiet');

exec('grunt {{task}}', function (err, stdout, stderr) {

console.log(stdout);

// restore stashed changes
sh('git stash pop --quiet');

var exitCode = 0;
if (err) {
console.log(stderr);
exitCode = -1;
}
process.exit(exitCode);
});
}

});

0 comments on commit 86476a4

Please sign in to comment.