Skip to content

Commit

Permalink
refactor(CLI): Replace process.stdout use with modern logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 14, 2021
1 parent 49f0913 commit be00a26
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/cli/handle-error.js
Expand Up @@ -26,7 +26,7 @@ const writeMessage = (title, message) => {
line = `${line}-`;
}

process.stdout.write(' \n');
legacy.consoleLog(' ');
legacy.consoleLog(chalk.yellow(` ${title} ${line}`));
legacy.consoleLog(' ');

Expand Down
3 changes: 2 additions & 1 deletion lib/cli/render-help/command.js
Expand Up @@ -21,5 +21,6 @@ module.exports = (commandName) => {
}
if (commandSchema) renderOptionsHelp(Object.assign({}, commandSchema.options));

process.stdout.write('\n');
legacy.consoleLog('');
writeText();
};
10 changes: 8 additions & 2 deletions lib/cli/render-version.js
Expand Up @@ -5,7 +5,7 @@ const { version } = require('../../package');
const { version: dashboardPluginVersion } = require('@serverless/dashboard-plugin/package');
const { version: componentsVersion } = require('@serverless/components/package');
const { platformClientVersion } = require('@serverless/dashboard-plugin');
const { legacy, log } = require('@serverless/utils/log');
const { legacy, log, writeText } = require('@serverless/utils/log');
const isStandaloneExecutable = require('../utils/isStandaloneExecutable');
const resolveLocalServerlessPath = require('./resolve-local-serverless-path');
const chalk = require('chalk');
Expand Down Expand Up @@ -54,10 +54,16 @@ module.exports = async () => {
return '';
})();

process.stdout.write(
legacy.write(
`Framework Core: ${version}${installationModePostfix}\n` +
`Plugin: ${dashboardPluginVersion}\n` +
`SDK: ${platformClientVersion}\n` +
`Components: ${componentsVersion}\n`
);
writeText(
`Framework Core: ${version}${installationModePostfix}`,
`Plugin: ${dashboardPluginVersion}`,
`SDK: ${platformClientVersion}`,
`Components: ${componentsVersion}`
);
};
4 changes: 3 additions & 1 deletion lib/utils/open.js
Expand Up @@ -14,6 +14,7 @@ const path = require('path');
const childProcess = require('child_process');
const fs = require('fs');
const isWsl = require('is-wsl');
const { legacy, log } = require('@serverless/utils/log');

const pAccess = promisify(fs.access);
const pExecFile = promisify(childProcess.execFile);
Expand Down Expand Up @@ -158,10 +159,11 @@ module.exports = async (target, options) => {
}
subprocess.once('error', (error) => {
if (process.env.SLS_DEBUG) {
process.stdout.write(
legacy.write(
`Serverless: ${chalk.red(`Opening of browser window errored with ${error.stack}`)}\n`
);
}
log.info(`Opening of browser window errored with ${error.stack}`);
});

subprocess.unref();
Expand Down
11 changes: 8 additions & 3 deletions lib/utils/openBrowser.js
Expand Up @@ -5,20 +5,25 @@
const opn = require('./open');
const chalk = require('chalk');
const isDockerContainer = require('is-docker');
const { legacy, log, style } = require('@serverless/utils/log');

module.exports = function openBrowser(url) {
process.stdout.write(
`\nIf your browser does not open automatically, please open the URL: ${url}\n\n`
legacy.write(`\nIf your browser does not open automatically, please open the URL: ${url}\n\n`);
log.notice();
log.notice(
style.aside(`If your browser does not open automatically, please open this URL: ${url}`)
);
log.notice();
let browser = process.env.BROWSER;
if (browser === 'none' || isDockerContainer()) return;
if (process.platform === 'darwin' && browser === 'open') browser = undefined;
const options = { wait: false, app: browser };
opn(url, options).catch((err) => {
if (process.env.SLS_DEBUG) {
process.stdout.write(
legacy.write(
`Serverless: ${chalk.red(`Opening of browser window errored with ${err.stack}`)}\n`
);
}
log.info(`Opening of browser window errored with ${err.stack}`);
});
};
5 changes: 4 additions & 1 deletion lib/utils/processBackendNotificationRequest.js
@@ -1,12 +1,15 @@
'use strict';

const chalk = require('chalk');
const { legacy, log, style } = require('@serverless/utils/log');

const processBackendNotificationRequest = require('@serverless/utils/process-backend-notification-request');

module.exports = (notifications) => {
const notification = processBackendNotificationRequest(notifications);
if (!notification) return;

process.stdout.write(`\n${chalk.gray(notification.message)}\n`);
legacy.write(`\n${chalk.gray(notification.message)}\n`);
log.notice();
log.notice(style.aside(notification.message));
};

0 comments on commit be00a26

Please sign in to comment.