Skip to content

Commit

Permalink
Fixes #12 - Ignore directory hits and use project base path.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Sep 1, 2016
1 parent ddad334 commit d25b05e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
30 changes: 11 additions & 19 deletions lib/Models.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
/**
* AWS APIG Model definition.
*/

const walkSyncOptions = {
globs : ['**/s-models.yaml', '**/s-models.json'],
ignore : ['**/node_modules'],
directories: false
};

module.exports = function (S) {

const _ = require('lodash'),
Expand All @@ -17,11 +24,6 @@ module.exports = function (S) {
super();

this._class = 'Models';
this._walkSyncGlobs = {
globs : ['**/s-models.yaml', '**/s-models.json'],
ignore : ['**/node_modules']

};
this._filePath = filePath;

if (data) this.fromObject(data);
Expand All @@ -47,18 +49,8 @@ module.exports = function (S) {
return this._filePath;
}

getWalkSyncGlobs () {
return this._walkSyncGlobs;
}

getRootPath () {
let args = _.toArray(arguments);
args.unshift(path.dirname(this.getFilePath()));
return path.join.apply(path, args);
}

walkSyncDirs () {
return walkSync(this.getRootPath(), this.getWalkSyncGlobs());
walkSyncDirs (rootPath) {
return walkSync(rootPath, walkSyncOptions);
}

deserializeModels (models) {
Expand Down Expand Up @@ -91,13 +83,13 @@ module.exports = function (S) {
static loadFromProject (project) {
let models = new S.classes.Models({}, '');

return BbPromise.mapSeries(models.walkSyncDirs(), (filename) => {
return BbPromise.mapSeries(models.walkSyncDirs(project.getRootPath()), filename => {
// Load Templates
let modelsFilePath = project.getRootPath(filename);

if (S.utils.fileExistsSync(modelsFilePath)) {
let models = new S.classes.Models({}, modelsFilePath);

return models.load();
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-models-plugin",
"version": "1.1.0",
"version": "1.1.1",
"engines": {
"node": ">=4.0"
},
Expand Down

0 comments on commit d25b05e

Please sign in to comment.