Commits

Brian McKenna committed 62461c8

Fix getFileContents and use fs for existsSync

  • Participants
  • Parent commits 0cff77e

Comments (0)

Files changed (2)

File src/compile.js

 };
 
 var getFileContents = function(filename) {
-    var path = require('path'),
+    var fs = require('fs'),
         exts = ["", ".roy", ".lroy"],
         filenames = _.map(exts, function(ext){
             return filename + ext;
         }),
+        foundFilename,
         source,
         err,
         i;
         source = fs.readFileSync(filename, 'utf8');
         filenames = [filename];
     } else {
-        source = _.find(filenames, function(filename) {
-            return path.existsSync(filename);
+        foundFilename = _.find(filenames, function(filename) {
+            return fs.existsSync(filename);
         });
+        if(foundFilename) {
+            source = fs.readFileSync(foundFilename, 'utf8');
+        }
     }
 
     if(source == null) {
 
     _.each(argv, function(filename) {
         // Read the file content.
-        var source = fs.readFileSync(filename, 'utf8');
+        var source = getFileContents(filename);
 
         if(filename.match(literateExtension)) {
             // Strip out the Markdown.

File src/modules.js

     var source = opts.modules[moduleName] || '';
 
     if(!source && opts.nodejs) {
-        var path = require('path'),
+        var fs = require('fs'),
             targetFile = resolveNodeModule(moduleName, opts.filename) + '.roym';
 
-        if(path.existsSync(targetFile)) {
-            source = require('fs').readFileSync(targetFile, 'utf8');
+        if(fs.existsSync(targetFile)) {
+            source = fs.readFileSync(targetFile, 'utf8');
         }
     }