From f223df85e86c05d82376ce6d090d60cb1f0e1137 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Tue, 31 Jan 2017 19:59:19 -0800 Subject: [PATCH] refactor(generic): add wrappers for console.info and console.warn --- src/api/import.js | 9 ++++----- src/api/install.js | 3 ++- src/api/make.js | 9 +++++---- src/util/messages.js | 13 +++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 src/util/messages.js diff --git a/src/api/import.js b/src/api/import.js index da5bcec5b3..56a092107a 100644 --- a/src/api/import.js +++ b/src/api/import.js @@ -8,6 +8,7 @@ import initGit from '../init/init-git'; import { deps, devDeps } from '../init/init-npm'; import asyncOra from '../util/ora-handler'; +import { info, warn } from '../util/messages'; import installDepList from '../util/install-dependencies'; import readPackageJSON from '../util/read-package-json'; import confirmIfInteractive from '../util/confirm-if-interactive'; @@ -55,7 +56,7 @@ export default async (providedOptions = {}) => { let packageJSON = await readPackageJSON(dir); if (packageJSON.config && packageJSON.config.forge) { - if (interactive) console.warn('It looks like this project is already configured for "electron-forge"'.green); + warn(interactive, 'It looks like this project is already configured for "electron-forge"'.green); const shouldContinue = await confirmIfInteractive(interactive, 'Are you sure you want to continue?'); if (!shouldContinue) { @@ -206,11 +207,10 @@ export default async (providedOptions = {}) => { }), null, 2)); }); - if (interactive) console.info('NOTE: You might be able to remove your `.compilerc` file completely if you are only using the `es2015` and `react` presets'.yellow); // eslint-disable-line max-len + info(interactive, 'NOTE: You might be able to remove your `.compilerc` file completely if you are only using the `es2016` and `react` presets'.yellow); } - if (interactive) { - console.info(` + info(interactive, ` We have ATTEMPTED to convert your app to be in a format that electron-forge understands. Nothing much will have changed but we added the ${'"electron-prebuilt-compile"'.cyan} dependency. This is \ @@ -223,5 +223,4 @@ Also please note if you are using \`preload\` scripts you need to follow the ste at https://github.com/electron-userland/electron-forge/wiki/Using-%27preload%27-scripts Thanks for using ${'"electron-forge"'.green}!!!`); - } }; diff --git a/src/api/install.js b/src/api/install.js index 9a1f6c77dc..f6eb253140 100644 --- a/src/api/install.js +++ b/src/api/install.js @@ -10,6 +10,7 @@ import pify from 'pify'; import semver from 'semver'; import asyncOra from '../util/ora-handler'; +import { info } from '../util/messages'; import darwinDMGInstaller from '../installers/darwin/dmg'; import darwinZipInstaller from '../installers/darwin/zip'; @@ -100,7 +101,7 @@ export default async (providedOptions = {}) => { } }); - if (interactive) console.info(`Found latest release${prerelease ? ' (including prereleases)' : ''}: ${latestRelease.tag_name.cyan}`); + info(interactive, `Found latest release${prerelease ? ' (including prereleases)' : ''}: ${latestRelease.tag_name.cyan}`); let targetAsset = possibleAssets[0]; if (possibleAssets.length > 1) { diff --git a/src/api/make.js b/src/api/make.js index f5046de463..a577aac885 100644 --- a/src/api/make.js +++ b/src/api/make.js @@ -5,6 +5,7 @@ import path from 'path'; import asyncOra from '../util/ora-handler'; import electronHostArch from '../util/electron-host-arch'; import getForgeConfig from '../util/forge-config'; +import { info, warn } from '../util/messages'; import readPackageJSON from '../util/read-package-json'; import requireSearch from '../util/require-search'; import resolveDir from '../util/resolve-dir'; @@ -53,15 +54,15 @@ export default async (providedOptions = {}) => { } if (!skipPackage) { - if (interactive) console.info('We need to package your application before we can make it'.green); + info(interactive, 'We need to package your application before we can make it'.green); await packager({ dir, interactive, arch, platform, }); - } else if (interactive) { - console.warn('WARNING: Skipping the packaging step, this could result in an out of date build'.red); + } else { + warn(interactive, 'WARNING: Skipping the packaging step, this could result in an out of date build'.red); } const declaredArch = arch; @@ -72,7 +73,7 @@ export default async (providedOptions = {}) => { targets = overrideTargets; } - if (interactive) console.info('Making for the following targets:', `${targets.join(', ')}`.cyan); + info(interactive, 'Making for the following targets:', `${targets.join(', ')}`.cyan); let targetArchs = [declaredArch]; if (declaredArch === 'all') { diff --git a/src/util/messages.js b/src/util/messages.js new file mode 100644 index 0000000000..90309cdad2 --- /dev/null +++ b/src/util/messages.js @@ -0,0 +1,13 @@ +function info(interactive, message) { + if (interactive) { + console.info(message); + } +} + +function warn(interactive, message) { + if (interactive) { + console.warn(message); + } +} + +export { info, warn };