@vroomlabs/gsdk-deploy
Version:
Google Cloud deployment script for kubernetes clusters using Global Load Balancer
141 lines (122 loc) • 5.69 kB
JavaScript
;
/******************************************************************************
* MIT License
* Copyright (c) 2017 https://github.com/vroomlabs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Created by rogerk on 7/3/17.
******************************************************************************/Object.defineProperty(exports,'__esModule',{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called')}return call&&(typeof call==='object'||typeof call==='function')?call:self}function _inherits(subClass,superClass){if(typeof superClass!=='function'&&superClass!==null){throw new TypeError('Super expression must either be null or a function, not '+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}
var path=require('path');
var winston=require('winston');
var debug=require('debug');
var colors=require('colors');
var getArtifactsFolder=require('./artifacts').getArtifactsFolder;var
DebugLogger=function(_winston$Transport){_inherits(DebugLogger,_winston$Transport);
function DebugLogger(options){_classCallCheck(this,DebugLogger);var _this=_possibleConstructorReturn(this,(DebugLogger.__proto__||Object.getPrototypeOf(DebugLogger)).call(this,
options));
_this.name='debugLogger';
_this.level='silly';
_this.debugLog=debug('gsdk-deploy');return _this;
}_createClass(DebugLogger,[{key:'log',value:function log(
level,msg,meta,callback){
msg=level.toUpperCase()+' '+msg+' '+JSON.stringify(meta||{});
this.debugLog(msg);
callback(null,true);
}}]);return DebugLogger}(winston.Transport);
var logSettings={
levels:{
error:0,
warn:1,
help:2,
data:3,
info:4,
debug:5,
prompt:6,
verbose:7,
input:8,
silly:9},
colors:{
error:'red',
warn:'yellow',
help:'cyan',
data:'grey',
info:'green',
debug:'blue',
prompt:'grey',
verbose:'cyan',
input:'grey',
silly:'magenta'}};var
LogWriter=function(){
function LogWriter(options){_classCallCheck(this,LogWriter);
var consoleLevel='debug';
this.logPath=path.join(getArtifactsFolder()||process.cwd(),'gsdk-deploy.log');
process.argv.forEach(function(param){
var m=param.match(/^-log[:=]([\w]{4,7})$/i);
if(m)consoleLevel=m[1].toLowerCase();
});
this._logWriter=new winston.Logger(Object.assign({
levels:logSettings.levels,
colors:logSettings.colors,
transports:[
new DebugLogger,
new winston.transports.Console({
handleExceptions:true,
level:consoleLevel,
json:false,
colorize:true}),
new winston.transports.File({
filename:this.logPath,
level:'verbose'})]},
options||{}));
this._logWriter.cli();
}
/** @deprecated */_createClass(LogWriter,[{key:'log',value:function log()
{
this._logWriter.log.apply(this._logWriter,[].slice.call(arguments));
}
/**
* @param {string} message
* @param {object=} data
*/},{key:'error',value:function error(
message,data){return this.log('error',colors.red(message),data)}
/**
* @param {string} message
* @param {object=} data
*/},{key:'warn',value:function warn(
message,data){return this.log('warn',colors.dim.yellow(message),data)}
/**
* @param {string} message
* @param {object=} data
*/},{key:'info',value:function info(
message,data){return this.log('info',message,data)}
/**
* @param {string} message
* @param {object=} data
*/},{key:'verbose',value:function verbose(
message,data){return this.log('verbose',message,data)}
/**
* @param {string} message
* @param {object=} data
*/},{key:'debug',value:function debug(
message,data){return this.log('debug',colors.gray(message),data)}
/**
* @param {string} message
* @param {object=} data
*/},{key:'silly',value:function silly(
message,data){return this.log('silly',message,data)}}]);return LogWriter}();
var logger=exports.logger=new LogWriter;