From d1e5940f731a684336c4e1ff1d9ff089fd8f639f Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 19 May 2016 07:30:26 -0700 Subject: [PATCH] force lodash v4 on some iterators so they do not run multiple times --- scripts/generate/js_api.js | 9 +++++---- scripts/generate/templates/api_methods.tmpl | 6 +++--- scripts/generate/templates/index.js | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/generate/js_api.js b/scripts/generate/js_api.js index f53750b71..6b8255f24 100644 --- a/scripts/generate/js_api.js +++ b/scripts/generate/js_api.js @@ -4,6 +4,7 @@ module.exports = function (branch, done) { * @type {[type]} */ var _ = require('../../src/lib/utils'); + var _v4 = require('lodash-migrate/lodash'); var utils = require('../../grunt/utils'); var fs = require('fs'); var async = require('async'); @@ -174,8 +175,8 @@ module.exports = function (branch, done) { var actions = []; // itterate all of the specs within the file, should only be one - _.each(spec, function (def, name) { - //camelcase the name + _v4.each(spec, function (def, name) { + // camelcase the name name = _.map(name.split('.'), _.camelCase).join('.'); if (name === 'cat.aliases') { @@ -218,7 +219,7 @@ module.exports = function (branch, done) { var urls = _.difference(def.url.paths, overrides.aliases[name]); var urlSignatures = []; - urls = _.map(urls, function (url) { + urls = _v4.map(urls, function (url) { var optionalVars = {}; var requiredVars = {}; var param; @@ -239,7 +240,7 @@ module.exports = function (branch, done) { urlSignatures.push(_.union(_.keys(optionalVars), _.keys(requiredVars)).sort().join(':')); - return _.omit({ + return _v4.omitBy({ fmt: url.replace(urlParamRE, function (full, match) { return '<%=' + _.camelCase(match) + '%>'; }), diff --git a/scripts/generate/templates/api_methods.tmpl b/scripts/generate/templates/api_methods.tmpl index 01574797d..e4bbbc345 100644 --- a/scripts/generate/templates/api_methods.tmpl +++ b/scripts/generate/templates/api_methods.tmpl @@ -8,7 +8,7 @@ NOTE: At this time, you must opt into the <%= branch %> API by setting the `apiV <% } actions = _.sortBy(actions, 'namespace'); -_.each(actions, function (action) { +_v4.each(actions, function (action) { action.index = 'api-' + action.name.toLowerCase().replace(/[^\w]+/g, '-') + branchSuffix; %> @@ -31,12 +31,12 @@ The default method is `<%= action.spec.method || 'GET' %>` and the usual < +_v4.each(action.allParams, function (param, paramName) { %> `<%= paramWithDefault(paramName, param.default) %>`:: `<%= paramType(param.type) %>` -- <%= joinParagraphs(param.description || '', 4) %><% if (param.type === 'enum') {%> Options:::<% -_.each(param.options, function (opt) {%> +_v4.each(param.options, function (opt) {%> * `"<%= opt %>"`<% });%> <% diff --git a/scripts/generate/templates/index.js b/scripts/generate/templates/index.js index 0c3ef4cad..21e8c872a 100644 --- a/scripts/generate/templates/index.js +++ b/scripts/generate/templates/index.js @@ -1,5 +1,6 @@ var _ = require('../../../src/lib/utils'); +var _v4 = require('lodash-migrate/lodash'); var utils = require('../../../grunt/utils'); var fs = require('fs'); var path = require('path'); @@ -42,6 +43,7 @@ var templateGlobals = { stringify: stringify, _: _, + _v4: _v4, indent: function (block, spaces) { var indent = _.repeat(' ', spaces);