Skip to content

Commit

Permalink
chore(dependencies): Update dependencies
Browse files Browse the repository at this point in the history
Updates the dependencies and switch from deprecated features of yeoman
to externalized packages now. Some changes resulted from the dependency
updates.
  • Loading branch information
kenjones-cisco committed Jan 12, 2016
1 parent f430735 commit a442506
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 102 deletions.
78 changes: 38 additions & 40 deletions app/index.js
Expand Up @@ -2,6 +2,7 @@

var path = require('path');
var yeoman = require('yeoman-generator');
var _ = require('lodash');
var _s = require('underscore.string');
var gulpif = require('gulp-if');
var beautify = require('gulp-beautify');
Expand All @@ -11,29 +12,32 @@ var debug = helpers.debug;


module.exports = yeoman.Base.extend({
constructor: function () {
yeoman.Base.apply(this, arguments);
this.argument('name', {
type: String,
required: false
});

this.option('dry-run', {
type: Boolean,
desc: 'Do not make changes just display changes that would have been made',
default: false
});
this.option('apiPath', {
type: String,
desc: 'Specifiy local path or URL of Swagger API spec'
});
this.option('database', {
type: String,
desc: 'The database name to use with mongoose'
});
},

initializing: {
init: function () {
this.argument('name', {
type: String,
required: false
});

this.option('dry-run', {
type: Boolean,
desc: 'Do not make changes just display changes that would have been made',
defaults: false
});
this.option('apiPath', {
type: String,
desc: 'Specifiy local path or URL of Swagger API spec'
});
this.option('database', {
type: String,
desc: 'The database name to use with mongoose'
});

this.props = {};
this.log('Swagapi Generator');

}
},

Expand Down Expand Up @@ -78,7 +82,7 @@ module.exports = yeoman.Base.extend({
this.log('Running in dry-run mode');
}

this.config.defaults({
this.props = _.defaults(this.props, {
appname: this.appname,
slugName: _s.slugify(this.appname),
apiPath: options.apiPath,
Expand All @@ -95,21 +99,15 @@ module.exports = yeoman.Base.extend({
message: 'The database name to use with mongoose',
name: 'database',
type: 'input',
when: function () {
return !self.config.get('database');
}
when: !self.props.database
}];

self.prompt(prompts, function (answers) {
for (var key in answers) {
debug('prompt results: %s =>', key, answers[key]);
if (typeof answers[key] !== 'undefined' && answers[key] !== null) {
debug('setting key value: %s', key);
self.config.set(key, answers[key]);
}
debug('prompt results: database =>', answers.database);
if (helpers.hasValue(answers.database)) {
debug('setting value for database');
self.props.database = answers.database;
}

self.config.save();
next();
});
}
Expand All @@ -118,7 +116,8 @@ module.exports = yeoman.Base.extend({

writing: {
genspec: function () {
this.composeWith('swaggerize:spec', {
this.options.props = this.props;
this.composeWith('swagapi:spec', {
options: this.options,
arguments: this.args
}, {
Expand Down Expand Up @@ -154,11 +153,10 @@ module.exports = yeoman.Base.extend({
this.copy('gitignore', '.gitignore');
this.copy('npmignore', '.npmignore');

api = helpers.loadApi(this.config.get('apiPath'),
this.read(this.config.get('apiPath')));
api = helpers.loadApi(this.props.apiPath, this.read(this.props.apiPath));

this.template('_package.json', 'package.json', {
slugName: this.config.get('slugName'),
slugName: this.props.slugName,
api: api,
_s: _s
});
Expand All @@ -170,17 +168,17 @@ module.exports = yeoman.Base.extend({
this.copy('_logger.js', upath.joinSafe(this.appRoot, 'config', 'logger.js'));
this.copy('_errors.js', upath.joinSafe(this.appRoot, 'config', 'errors.js'));
this.template('default.yml', upath.joinSafe(this.appRoot, 'config', 'default.yml'), {
database: this.config.get('database')
database: this.props.database
});
this.template('custom-environment-variables.yml',
upath.joinSafe(this.appRoot, 'config', 'custom-environment-variables.yml'), {
database: this.config.get('database')
database: this.props.database
});

},

database: function () {
if (!this.config.get('database')) {
if (!this.props.database) {
debug('skipping database setup generation');
return;
}
Expand All @@ -193,7 +191,7 @@ module.exports = yeoman.Base.extend({

debug('generating database configuration files');
this.template('_config_db.js', upath.joinSafe('config', 'db.js'), {
database: this.config.get('database')
database: this.props.database
});
},

Expand Down
12 changes: 6 additions & 6 deletions handlers/index.js
Expand Up @@ -23,7 +23,7 @@ module.exports = yeoman.Base.extend({
required: true
});
this.appRoot = this.destinationRoot();
this.api = this.options.api;
this.props = this.options.props;
},

writing: {
Expand All @@ -36,7 +36,7 @@ module.exports = yeoman.Base.extend({
mkdirp.sync(upath.joinSafe(self.appRoot, 'handlers'));
}

routes = self._formatRoutes(self.api.paths);
routes = self._formatRoutes(self.props.api.paths);

_.forEach(_.values(routes), function (route) {

Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = yeoman.Base.extend({
}

var self = this;
var operations = self._formatRoutes(self.api.paths);
var operations = self._formatRoutes(self.props.api.paths);

_.forEach(_.values(operations), function (operation) {

Expand All @@ -81,9 +81,9 @@ module.exports = yeoman.Base.extend({
_: _,
util: util,
specutil: specutil,
resourcePath: self.api.basePath,
resourcePath: self.props.api.basePath,
operations: operation,
models: self.api.definitions
models: self.props.api.definitions
});
} else {
self.log.ok('(DRY-RUN) test %s generated', file);
Expand Down Expand Up @@ -144,7 +144,7 @@ module.exports = yeoman.Base.extend({
var dbModels = [];
var schemas, dbFileName;

if (!self.config.get('database') && !this.options.database) {
if (!self.props.database) {
return null;
}

Expand Down
14 changes: 11 additions & 3 deletions lib/helpers.js
Expand Up @@ -23,10 +23,11 @@ helpers.fileExists = function fileExists(file) {
};

helpers.findFile = function findFile(name, root, project) {
var location;
name = _.trim(name);
var location = null;
debug('name: %s root: %s project: %s', name, root, project);

if (!name) {
if (!name || helpers.isRemote(name)) {
return name;
}

Expand All @@ -37,7 +38,7 @@ helpers.findFile = function findFile(name, root, project) {
}
});

return location ? location : name;
return location;
};

helpers.isRemote = function isRemote(apiPath) {
Expand Down Expand Up @@ -77,3 +78,10 @@ helpers.unprefix = function unprefix(str, pre) {

return str;
};

helpers.hasValue = function hasValue(value) {
if (_.isUndefined(value) || _.isNull(value)) {
return false;
}
return true;
};
10 changes: 5 additions & 5 deletions models/index.js
Expand Up @@ -17,7 +17,7 @@ module.exports = yeoman.Base.extend({
required: true
});
this.appRoot = this.destinationRoot();
this.api = this.options.api;
this.props = this.options.props;
},

writing: {
Expand All @@ -30,7 +30,7 @@ module.exports = yeoman.Base.extend({
mkdirp.sync(basePath);
}

if (self.config.get('database')) {
if (self.props.database) {
if (!self.options['dry-run']) {
self.copy('_models_index.js',
upath.joinSafe(self.appRoot, 'models', 'index.js'));
Expand All @@ -39,7 +39,7 @@ module.exports = yeoman.Base.extend({
}
}

_.forEach(this.api.definitions, function (model, modelName) {
_.forEach(this.props.api.definitions, function (model, modelName) {
if (!model.properties) {
debug('model has no properties: %s', modelName);
return;
Expand All @@ -56,7 +56,7 @@ module.exports = yeoman.Base.extend({
debug('children: %s', model['x-children']);
_.forEach(model['x-children'], function(childName) {
debug('childName: %s', childName);
model.children[childName] = self.api.definitions[childName];
model.children[childName] = self.props.api.definitions[childName];
});
}

Expand All @@ -72,7 +72,7 @@ module.exports = yeoman.Base.extend({
model._ = _;
model.helpers = specutil;

if (self.config.get('database')) {
if (self.props.database) {
debug('generating mongoose enabled model: %s', modelName);
if (!self.options['dry-run']) {
self.template('_model_mongoose.js', file, model);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -35,10 +35,11 @@
"swagger-schema-official": "^2.0.0-",
"underscore.string": "^3.1.1",
"upath": "^0.1.6",
"yeoman-generator": "^0.20.1"
"yeoman-generator": "^0.22.3"
},
"devDependencies": {
"yeoman-assert": "^2.1.1",
"yeoman-test": "^1.0.0",
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.3",
"gulp-eslint": "^1.1.1",
Expand Down

0 comments on commit a442506

Please sign in to comment.