var fs = require('fs')
, path = require('path')
, repl1 = "var useragent = require('express-useragent');\nvar express = require('express');"
, repl2 = "app.use(useragent.express());    app.use(app.router);";


if (path.existsSync(__dirname + '/config/environment.js')) {
    var data = fs.readFileSync(__dirname + '/config/environment.js', 'utf8');
    if(!/var express = require('express');/gim.test(data) && !/app.use(app.router);/gim.test(data)) {
        data.replace(/var express = require('express');/gim,repl1)
            .replace(/app.use(app.router);/gim,repl2);
        fs.writeFileSync(__dirname + '/config/environment.js', data, 'utf8');
    }
}

process.exit(0);
@@ -20,33 +20,8 @@
 s')%0A
-, path = require('path')%0A
 , re
@@ -85,38 +85,16 @@
  express
- = require('express');
 %22%0A, repl
@@ -127,16 +127,18 @@
 ress());
+%5Cn
     app.
@@ -158,16 +158,43 @@
 r);%22
+%0A, basepath = process.cwd()
 ;%0A%0A%0Aif (
 path
@@ -189,20 +189,18 @@
 ;%0A%0A%0Aif (
-path
+fs
 .existsS
@@ -199,33 +199,32 @@
 .existsSync(
-__dirname
+basepath
  + '/config/
@@ -251,16 +251,27 @@
     var 
+environment
 data = f
@@ -281,33 +281,32 @@
 eadFileSync(
-__dirname
+basepath
  + '/config/
@@ -348,157 +348,237 @@
 var 
-express = require('express');/gim.test(data) && !/app.use(app.router);/gim.test(data)) %7B%0A        data.replace(/var express = require('
+useragent/gim.test(environmentdata) && !/useragent%5C.express/gim.test(environmentdata)) %7B%0A        fs.writeFileSync(basepath + '/config/environment.js',%0A            environmentdata.toString()%0A            .replace(/var 
 express
-');
 /gim,
+ 
 repl
@@ -605,24 +605,25 @@
 ace(/app.use
+%5C
 (app.router)
@@ -625,90 +625,323 @@
 uter
+%5C
 );/gim,
+ 
 repl2)
+, 'utf8')
 ;%0A    
+%7D%0A
     
-fs.writeFileSync(__dirname + '/config/environment.js', data
+if (fs.existsSync(basepath + '/npmfile.js')) %7B%0A        var npmfiledata = fs.readFileSync(basepath + '/npmfile.js', 'utf8');%0A        fs.writeFileSync(basepath + '/npmfile.js',%0A            npmfiledata.toString()%0A            .replace(/%5C%22require%5C(%5C'express-useragent%5C'%5C)%5C;%5C%22/gim, %22%22)
 , 'u

Fix install.js for CompoundJS (RailwayJS)