mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
serverless run ui improvements
This commit is contained in:
parent
91d746d167
commit
fca3015a5e
@ -74,7 +74,7 @@ class Run {
|
||||
return localEmulatorRunning(getLocalRootUrl(this.options.lport))
|
||||
.then(localEmulatorAlreadyRunning => {
|
||||
if (localEmulatorAlreadyRunning) {
|
||||
logServerless('Emulator already running');
|
||||
// logServerless('Emulator already running');
|
||||
functionsDeployed = true;
|
||||
return deployFunctionsToLocalEmulator(
|
||||
this.serverless.service,
|
||||
@ -82,7 +82,7 @@ class Run {
|
||||
getLocalRootUrl(this.options.lport)
|
||||
).then(() => {
|
||||
// eslint-disable-next-line max-len
|
||||
logServerless('Functions deployed. For details please review the terminal running the Emulator.');
|
||||
logServerless('Functions loaded successfully in your current "serverless run" session.');
|
||||
});
|
||||
}
|
||||
return BbPromise.resolve();
|
||||
@ -91,7 +91,7 @@ class Run {
|
||||
.then(eventGatewayAlreadyRunning => {
|
||||
if (eventGatewayAlreadyRunning) {
|
||||
functionsRegistered = true;
|
||||
logServerless('Event Gateway already running');
|
||||
// logServerless('Event Gateway already running');
|
||||
return registerFunctionsToEventGateway(
|
||||
this.serverless.service,
|
||||
getLocalRootUrl(this.options.eport),
|
||||
@ -99,7 +99,7 @@ class Run {
|
||||
getLocalRootUrl(this.options.lport)
|
||||
).then(() => {
|
||||
// eslint-disable-next-line max-len
|
||||
logServerless('Functions and subscriptions registered. For details please review the terminal running the Event Gateway.');
|
||||
// logServerless('Functions and subscriptions registered. For details please review the terminal running the Event Gateway.');
|
||||
});
|
||||
}
|
||||
return BbPromise.resolve();
|
||||
|
||||
@ -8,7 +8,7 @@ const logLocalEmulator = require('./logLocalEmulator');
|
||||
|
||||
function deployFunctionsToLocalEmulator(service, servicePath, localEmulatorRootUrl) {
|
||||
// NOTE important for UX since it takes a while to upload large functions
|
||||
logLocalEmulator('Deploying functions...');
|
||||
logLocalEmulator('Functions loading...');
|
||||
|
||||
const functionDeploymentPromises = [];
|
||||
|
||||
|
||||
@ -6,19 +6,18 @@ const os = require('os');
|
||||
|
||||
const colorPrefix = chalk.hex('#D86121');
|
||||
const colorDim = chalk.hex('#777777');
|
||||
const spaceSmall = ' ';
|
||||
const spaceLarge = ' ';
|
||||
const spaceSmall = ' ';
|
||||
const prefix = colorPrefix(` Event Gateway${spaceSmall}`);
|
||||
|
||||
const prettifyValue = value => {
|
||||
const prettified = JSON.stringify(value, null, 2).replace(
|
||||
new RegExp('\\n', 'g'),
|
||||
`${os.EOL} `
|
||||
`${os.EOL}${spaceSmall}`
|
||||
);
|
||||
return `${spaceLarge}${prettified}`;
|
||||
return `${spaceSmall}${prettified}`;
|
||||
};
|
||||
|
||||
const getMessage = msg => {
|
||||
const processMessage = msg => {
|
||||
let parsedMsg;
|
||||
try {
|
||||
parsedMsg = JSON.parse(msg);
|
||||
@ -34,7 +33,7 @@ const getMessage = msg => {
|
||||
return `Subscription removed: event:${parsedMsg.event} >>> function:${parsedMsg.functionId}`;
|
||||
} else if (parsedMsg.msg === 'Event received.') {
|
||||
const event = JSON.parse(parsedMsg.event);
|
||||
const text = `Event received: ${event.event}${os.EOL}`;
|
||||
const text = `Event received: ${event.event}${os.EOL}${os.EOL}`;
|
||||
return `${text}${colorDim(prettifyValue(event))}${os.EOL}`;
|
||||
} else if (parsedMsg.msg === 'Function triggered.') {
|
||||
const event = JSON.parse(parsedMsg.event);
|
||||
@ -42,16 +41,12 @@ const getMessage = msg => {
|
||||
return `${text}`;
|
||||
} else if (parsedMsg.msg === 'Function finished.') {
|
||||
const response = prettifyValue(JSON.parse(parsedMsg.response));
|
||||
const text = `Function finished: ${parsedMsg.functionId}${os.EOL}${colorDim(response)}${os.EOL}`;
|
||||
const text = `Function finished: ${parsedMsg.functionId}${os.EOL}${os.EOL}${colorDim(response)}${os.EOL}`;
|
||||
return `${text}`;
|
||||
} else if (parsedMsg.msg === 'Function not found for HTTP event.') {
|
||||
const response = prettifyValue(JSON.parse(parsedMsg.event));
|
||||
const text = `Function not found for HTTP event:${os.EOL}${colorDim(response)}`;
|
||||
return `${text}`;
|
||||
return false;
|
||||
} else if (parsedMsg.msg === 'Function invocation failed.') {
|
||||
const text = `Failed to invoke function ${parsedMsg.functionId}${os.EOL}`;
|
||||
const errorText = `${spaceLarge}error: ${parsedMsg.error}`;
|
||||
return `${text}${errorText}`;
|
||||
return false;
|
||||
} else if (parsedMsg.msg.startsWith('Running in development mode with embedded etcd')) {
|
||||
const partOne = 'Running in development mode with embedded etcd. Event API listening on ';
|
||||
const re = new RegExp(`${partOne}(.*). Config API listening on (.*).`);
|
||||
@ -68,8 +63,10 @@ const getMessage = msg => {
|
||||
|
||||
module.exports = msg => {
|
||||
try {
|
||||
const processedMsg = getMessage(msg);
|
||||
log(`${prefix}${processedMsg}${os.EOL}`);
|
||||
const processedMsg = processMessage(msg);
|
||||
if (processedMsg) {
|
||||
log(`${prefix}${processedMsg}${os.EOL}`);
|
||||
}
|
||||
} catch (err) {
|
||||
// NOTE keep this here - it's a worse UX to skip messages
|
||||
// rather than having an unformated message logged
|
||||
|
||||
@ -1,13 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const colorPrefix = chalk.hex('#bdb018');
|
||||
const spaceSmall = ' ';
|
||||
const prefix = colorPrefix(` Emulator ${spaceSmall}`);
|
||||
const colorDim = chalk.hex('#777777');
|
||||
const spaceSmall = ' ';
|
||||
const prefix = colorPrefix(` Serverless${spaceSmall}`);
|
||||
|
||||
const processMessage = msg => {
|
||||
if (msg.trim().length < 0) {
|
||||
return false;
|
||||
} else if (typeof msg === 'string') {
|
||||
msg = msg.trim();
|
||||
|
||||
if (msg.startsWith('Error:')) {
|
||||
msg = `Function error:${os.EOL}${os.EOL}${colorDim(msg)}${os.EOL}`
|
||||
}
|
||||
}
|
||||
|
||||
return msg;
|
||||
};
|
||||
|
||||
function logLocalEmulator(message) {
|
||||
process.stdout.write(`${prefix}${message.trim()}\n`);
|
||||
message = processMessage(message);
|
||||
if (message) {
|
||||
process.stdout.write(`${prefix}${message}${os.EOL}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = logLocalEmulator;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const chalk = require('chalk');
|
||||
|
||||
const colorPrefix = chalk.hex('#bdb018');
|
||||
const spaceSmall = ' ';
|
||||
const spaceSmall = ' ';
|
||||
const prefix = colorPrefix(` Serverless${spaceSmall}`);
|
||||
|
||||
function logServerless(message) {
|
||||
|
||||
@ -26,7 +26,7 @@ const splitLinesAndLog = data => {
|
||||
function manageEventGateway(service, eventsPort, configurationPort, localEmulatorPort) {
|
||||
let initialized = false;
|
||||
const binaryFilePath = path.join(os.homedir(), '.serverless', 'event-gateway', 'event-gateway');
|
||||
logServerless('Initializing Event Gateway...');
|
||||
logServerless('Event Gateway initializing...');
|
||||
|
||||
const args = [
|
||||
`-embed-data-dir=${getTmpDirPath()}`,
|
||||
|
||||
@ -14,9 +14,9 @@ function manageLocalEmulator(service, servicePath, options) {
|
||||
let params = ['--port', port];
|
||||
if (debug) {
|
||||
params = params.concat(['--debug']);
|
||||
logServerless('Initializing Emulator in debug mode...');
|
||||
logServerless('Emulator initializing in debug mode...');
|
||||
} else {
|
||||
logServerless('Initializing Emulator...');
|
||||
logServerless('Emulator initializing...');
|
||||
}
|
||||
const cp = childProcess.spawn('sle', params);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user