Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Guard against no model dir

  • Loading branch information...
commit ec3355758fc78d26ea04bcaceb84e4ecd6609616 1 parent 6af11fc
mde authored
Showing with 19 additions and 9 deletions.
  1. +19 −9 lib/init/build.js
View
28 lib/init/build.js
@@ -1,21 +1,31 @@
var utils = require('utilities')
+ , path = require('path')
, fs = require('fs');
exports.init = function (app, callback) {
- var modelDir = utils.file.readdirR('app/models')
+ var modelDir = path.join('app/models')
+ , cwd = process.cwd()
+ , models
, files = []
, file
, content
- , built;
- for (var i in modelDir) {
- file = modelDir[i].replace('app/models', '').replace('app\\models', '').replace('/', '').replace('\\', '');
- if (file) {
- content = fs.readFileSync(modelDir[i], 'utf8');
- files.push("(function(){\n" + content + "}());");
- }
+ , built
+ , jsPat = /\.js$/;
+
+ // May be running totally model-less
+ if (!utils.file.existsSync(path.join(cwd, modelDir))) {
+ return callback();
}
+
+ models = utils.file.readdirR(modelDir)
+ models.forEach(function (item) {
+ if (jsPat.test(item)) {
+ content = fs.readFileSync(item, 'utf8');
+ files.push("(function () {\n" + content + "}());");
+ }
+ });
built = files.join('\n\n');
- geddy.file.mkdirP('public/js/core/');
+ geddy.file.mkdirP(path.join('public/js/core'));
fs.writeFileSync('public/js/core/models.js', built);
return callback();
};
Please sign in to comment.
Something went wrong with that request. Please try again.