Skip to content

Commit

Permalink
Fixed hooks work: now hooks is running synchronous.
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rmat1k committed Jan 30, 2016
1 parent 07fbbd4 commit 45eb6ff
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 33 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules/
temp/
.idea
demo/
atlassian-ide-plugin.xml

.DS_Store
Expand Down
47 changes: 29 additions & 18 deletions bemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs');
var fse = require('fs-extra');
var minimist = require('minimist');
var path = require('path');
var exec = require('child_process').exec;
var execSync = require('child_process').execSync;
var depsNormalize = require('deps-normalize');

var options = minimist(process.argv.slice(2)),
Expand Down Expand Up @@ -365,17 +365,20 @@ function createFile(file, type, trg, modVal, cursorPos, hook){
if (hook) {
hook = hook.replace('{{filePath}}', p);

exec(hook, function (error, stdout, stderr) {
if (stderr) {
console.error("Created. But hook didn't work, because:");
console.error(stderr);
}
try {
console.log(hook);
console.log(fs.readdirSync('.'));

if (stdout) {
var hookStdout = execSync(hook).toString('utf-8');

if (hookStdout) {
console.log('Hook output:');
console.log(stdout);
console.log(hookStdout);
}
});
} catch(e) {
console.error("Created. But hook had error.");
console.error(e);
}
}

if (options.g) gitQueue.push(p);
Expand All @@ -390,9 +393,17 @@ function createFile(file, type, trg, modVal, cursorPos, hook){
.replace('{{file-path}}', p)
.replace('{{line-number}}', cursorPos);

exec(editorCmd, function (error, stdout, stderr) {
if (stderr) console.error(stderr);
});
try {
var stdout = execSync(editorCmd).toString('utf-8');

if (stdout) {
console.log('Editor\'s stdout:');
console.log(stdout);
}

} catch(e) {
console.log(e);
}
}
}

Expand All @@ -409,13 +420,13 @@ function gitAdd(files){

var dir = path.dirname(files[0]);

exec('cd ' + dir + ' && git add ' + fileList, function (error, stdout, stderr) {
if (stderr) console.error(stderr);
var stdout = execSync('cd ' + dir + ' && git add ' + fileList).toString('utf-8');

if (isDebug) {
console.log('Added to git: \n' + files.join('\n'));
}
});
if (stdout) console.error(stdout);

if (isDebug) {
console.log('Added to git: \n' + files.join('\n'));
}
}

function getCursorPosition(file){
Expand Down
4 changes: 0 additions & 4 deletions demo/mac/__elem/_mod/mac__elem_mod.css

This file was deleted.

4 changes: 0 additions & 4 deletions demo/mac/__elem/mac__elem.css

This file was deleted.

4 changes: 0 additions & 4 deletions demo/mac/mac.css

This file was deleted.

2 changes: 2 additions & 0 deletions examples/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
var fs = require('fs');

var filePath = process.argv.slice(2)[0];
console.log('PATH');
console.log(filePath);
fs.writeFileSync(filePath, 'test-content');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/f0rmat1k/bemy.git"
},
"version": "3.5.4",
"version": "3.5.5",
"keywords": [
"bem",
"BEM Tools"
Expand Down
3 changes: 2 additions & 1 deletion test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ describe('Hooks', function(){

it('Replacing file content', function(){
var configPath = path.resolve('test', 'config-hooks.json');
console.log('node bemy.js -t create -f test/hook-block -p "j" -c ' + configPath);

execSync('node bemy.js -t create -f test/hook-block -p "j" -c ' + configPath);
execSync('node bemy.js -t create -f test/hook-block -p "j" -c ' + configPath).toString('utf-8');

fs.readFileSync('test/hook-block/hook-block.js', 'utf-8').should.be.eql('test-content');
});
Expand Down

0 comments on commit 45eb6ff

Please sign in to comment.