-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (32 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const _ = require('lodash');
const debug = require('debug')('push2cloud-compiler-cf-app-versioning');
const versioning = (config, mani, t, next) => {
debug('Add version of app');
const setVersionToName = (app) => {
const name = `${app.name}-${app.version}`;
debug(name);
return _.assign({}, app, { name: name, unversionedName: app.name });
};
const setVersionFromApp = (propName) => (a) => {
propName = propName || 'app';
const app = _.find(config.apps, (fa) => fa.name === a[propName]);
if (!app) return a;
const name = `${app.name}-${app.version}`;
debug(name);
var v = {};
v[propName] = name;
v.unversionedName = app.name;
return _.assign({}, a, v);
};
const versionedApps = _.map(config.apps, setVersionToName);
const versionedServiceBindings = _.map(config.serviceBindings, setVersionFromApp());
const versionedRoutes = _.map(config.routes, setVersionFromApp());
const versionedEnv = _.map(config.envVars, setVersionFromApp('name'));
next(null, _.assign({}, config, {
apps: versionedApps
, serviceBindings: versionedServiceBindings
, routes: versionedRoutes
, envVars: versionedEnv
}), mani, t);
};
module.exports = versioning;