Permalink
Browse files

[watcher] Respect shebangs

  • Loading branch information...
alejandro committed Mar 25, 2012
1 parent 952982b commit 097d47de196151e2b0be4453d5baca84630c95b5
Showing with 10 additions and 4 deletions.
  1. +1 −3 bin/create_user_dir.js
  2. +9 −1 lib/lib.js
View
@@ -5,9 +5,7 @@ var config = require('../config.js').opt;
var dirs_string = config.git_home_dir + '/' + process.argv[2] + ' ' + config.apps_home_dir + '/' + process.argv[2];
-var cmds = ['mkdir ' + dirs_string, 'chown ' + config.git_user + ':' + config.app_uid + ' ' + dirs_string, 'chmod 0777 ' + dirs_string
-
-];
+var cmds = ['mkdir ' + dirs_string, 'chgrp -R '+config.chgrp+' ' +dirs_string, 'chmod 0777 ' + dirs_string];
var do_cmd = function () {
if (cmds.length > 0) {
View
@@ -368,7 +368,15 @@ var insert_code = function(location,file,code, cb){
old = old.split('\n').filter(function(line){
return line !== code;
}).join('\n')
- newfile = code+'\n\n'+old
+ )
+ var lines = old.split('\n');
+ if (/\#!\//gi.test(lines[0])){
+ var shebang = lines[0]
+ lines.shift();
+ newfile = shebang+'\n'+code+'\n'+lines.join('\n');
+ } else {
+ newfile = code+'\n'+old
+ }
var inserted = fs.createWriteStream(target, {'flags': 'w'},'utf8');
inserted.end(newfile);
exec('cd '+location+'; sudo git add .;sudo git commit -am "[nodester] Watcher code inserted"',function(e,d){

0 comments on commit 097d47d

Please sign in to comment.