Skip to content
This repository
Browse code

Guard against no model dir

  • Loading branch information...
commit ec3355758fc78d26ea04bcaceb84e4ecd6609616 1 parent 6af11fc
Matthew Eernisse authored November 09, 2012

Showing 1 changed file with 19 additions and 9 deletions. Show diff stats Hide diff stats

  1. 28  lib/init/build.js
28  lib/init/build.js
... ...
@@ -1,21 +1,31 @@
1 1
 var utils = require('utilities')
  2
+  , path = require('path')
2 3
   , fs = require('fs');
3 4
 
4 5
 exports.init = function (app, callback) {
5  
-  var modelDir = utils.file.readdirR('app/models')
  6
+  var modelDir = path.join('app/models')
  7
+    , cwd = process.cwd()
  8
+    , models
6 9
     , files = []
7 10
     , file
8 11
     , content
9  
-    , built;
10  
-  for (var i in modelDir) {
11  
-      file = modelDir[i].replace('app/models', '').replace('app\\models', '').replace('/', '').replace('\\', '');
12  
-    if (file) {
13  
-      content = fs.readFileSync(modelDir[i], 'utf8');
14  
-      files.push("(function(){\n" + content + "}());");
15  
-    }
  12
+    , built
  13
+    , jsPat = /\.js$/;
  14
+
  15
+  // May be running totally model-less
  16
+  if (!utils.file.existsSync(path.join(cwd, modelDir))) {
  17
+    return callback();
16 18
   }
  19
+
  20
+  models = utils.file.readdirR(modelDir)
  21
+  models.forEach(function (item) {
  22
+    if (jsPat.test(item)) {
  23
+      content = fs.readFileSync(item, 'utf8');
  24
+      files.push("(function () {\n" + content + "}());");
  25
+    }
  26
+  });
17 27
   built = files.join('\n\n');
18  
-  geddy.file.mkdirP('public/js/core/');
  28
+  geddy.file.mkdirP(path.join('public/js/core'));
19 29
   fs.writeFileSync('public/js/core/models.js', built);
20 30
   return callback();
21 31
 };

0 notes on commit ec33557

Please sign in to comment.
Something went wrong with that request. Please try again.