Skip to content

Commit

Permalink
refactor(generic): add wrappers for console.info and console.warn
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Feb 1, 2017
1 parent c8a15f4 commit f223df8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/api/import.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 \
Expand All @@ -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}!!!`);
}
};
3 changes: 2 additions & 1 deletion src/api/install.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/api/make.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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') {
Expand Down
13 changes: 13 additions & 0 deletions 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 };

0 comments on commit f223df8

Please sign in to comment.