UNPKG

apiconnect-cli-publish-bluemix

Version:

Plugin for IBM API Connect Developer Toolkit

54 lines (49 loc) 1.9 kB
/********************************************************* {COPYRIGHT-TOP} *** * Licensed Materials - Property of IBM * 5725-Z22, 5725-Z63, 5725-U33, 5725-Z63 * * (C) Copyright IBM Corporation 2016, 2017 * * All Rights Reserved. * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. ********************************************************** {COPYRIGHT-END} **/ // Node module: apiconnect-cli-publish-bluemix var Promise = require('bluebird'); var bluemixInjection = require('./bluemixInjection'); var g = require('strong-globalize')(); var path = require('path'); function prepareProject(projectDir, projectType) { var promises = []; var messages = []; var validProjectTypes = [ 'LoopBack', 'Node', 'swiftserver' ]; switch (projectType) { case 'loopback': promises.push(bluemixInjection.copyFiles([ { sourceFile: path.join(__dirname, 'injectionFiles/server/boot/trustProxy.js'), destination: path.join(projectDir, 'server/boot/'), }, { sourceFile: path.join(__dirname, 'injectionFiles/server/middleware/bluemixHttpRedirect.js'), destination: path.join(projectDir, 'server/middleware/'), } ])); promises.push(bluemixInjection.insertIntoJsonFiles( path.join(projectDir, 'server'), '*middleware*.json', 'initial', { './middleware/bluemixHttpRedirect': {} }) ); messages.push('API invoke tls-profile: client:Loopback-client'); break; case 'node': // no changes needed break; case 'swiftserver': // no changes needed break; default: return Promise.reject(new Error(g.f('The project type is invalid. Valid types: %s', validProjectTypes.join(', ')))); } return Promise.all(promises).then(function() { return messages; }); } module.exports = prepareProject;