Skip to content

Commit

Permalink
fix(generic): clean up package manager warning output
Browse files Browse the repository at this point in the history
Integrate ora into the check system calls.
Break up the package manager warning with a newline.
  • Loading branch information
malept committed Aug 24, 2017
1 parent 88b92fc commit 894ed0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/electron-forge.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ tab.start();
if (process.argv[2] !== 'completion') {
(async () => {
let goodSystem;
await asyncOra('Checking your system', async () => {
goodSystem = await checkSystem();
await asyncOra('Checking your system', async (ora) => {
goodSystem = await checkSystem(ora);
});

if (!goodSystem) {
Expand Down
21 changes: 10 additions & 11 deletions src/util/check-system.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { exec } from 'child_process';
import logSymbols from 'log-symbols';
import semver from 'semver';

import { hasYarn, yarnOrNpmSpawn } from './yarn-or-npm';
Expand All @@ -26,31 +25,31 @@ const YARN_WHITELISTED_VERSIONS = {
linux: '0.27.5',
};

function warnIfPackageManagerIsntAKnownGoodVersion(packageManager, version, whitelistedVersions) {
function warnIfPackageManagerIsntAKnownGoodVersion(packageManager, version, whitelistedVersions, ora) {
const osVersions = whitelistedVersions[process.platform];
const versions = osVersions ? `${whitelistedVersions.all} || ${osVersions}` : whitelistedVersions.all;
if (!semver.satisfies(version, versions)) {
console.warn(
logSymbols.warning,
(`You are using ${packageManager}, but not a known good version. The known ` +
`versions that work with Electron Forge are: ${versions}`).yellow
ora.warn(
`You are using ${packageManager}, but not a known good version.\n` +
`The known versions that work with Electron Forge are: ${versions}`
);
}
}

async function checkPackageManagerVersion() {
async function checkPackageManagerVersion(ora) {
return yarnOrNpmSpawn(['--version'])
.then((version) => {
if (hasYarn()) {
warnIfPackageManagerIsntAKnownGoodVersion('Yarn', version, YARN_WHITELISTED_VERSIONS);
warnIfPackageManagerIsntAKnownGoodVersion('Yarn', version, YARN_WHITELISTED_VERSIONS, ora);
} else {
warnIfPackageManagerIsntAKnownGoodVersion('NPM', version, NPM_WHITELISTED_VERSIONS);
warnIfPackageManagerIsntAKnownGoodVersion('NPM', version, NPM_WHITELISTED_VERSIONS, ora);
}

return true;
});
}

export default async () =>
(await Promise.all([checkGitExists(), checkNodeVersion(), checkPackageManagerVersion()]))
export default async function (ora) {
return (await Promise.all([checkGitExists(ora), checkNodeVersion(ora), checkPackageManagerVersion(ora)]))
.every(check => check);
}
3 changes: 2 additions & 1 deletion test/fast/system_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect } from 'chai';

import checkSystem from '../../src/util/check-system';
import { fakeOra } from '../../src/util/ora';

describe('check-system', () => {
it('should succeed on valid agents', async () => {
expect(await checkSystem()).to.be.equal(true);
expect(await checkSystem(fakeOra)).to.be.equal(true);
});
});

0 comments on commit 894ed0a

Please sign in to comment.