Skip to content

Commit

Permalink
Remove verbose command, fix npm version, move file writing to up front
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager committed Sep 12, 2024
1 parent 5a7de61 commit 8df5719
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
21 changes: 5 additions & 16 deletions packages/cli/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,25 @@ const { EXIT_CODES } = require('../lib/enums/exitCodes');
exports.command = 'doctor';
exports.describe = 'The doctor is in';

exports.handler = async ({ file, verbose }) => {
exports.handler = async ({ file }) => {
const doctor = new Doctor();

try {
trackCommandUsage('doctor', null, doctor.accountId);
} catch (e) {
logger.debug(e);
}

const diagnosis = await doctor.diagnose();

const stringifiedOutput = JSON.stringify(diagnosis, null, 4);

if (verbose) {
console.log(stringifiedOutput);
}

if (file) {
try {
fs.writeFileSync(file, stringifiedOutput);
logger.success(`Output written to ${file}`);
fs.writeFileSync(file, JSON.stringify(doctor.generateOutput(), null, 4));
logger.info(`Output written to ${file}`);
} catch (e) {
logger.error(`Unable to write output to ${file}, ${e.message}`);
process.exit(EXIT_CODES.ERROR);
}
}

await doctor.diagnose();
};

exports.builder = yargs =>
Expand All @@ -42,8 +35,4 @@ exports.builder = yargs =>
describe: 'Where to write the output',
type: 'string',
},
verbose: {
describe: 'Chatty?',
type: 'boolean',
},
});
5 changes: 2 additions & 3 deletions packages/cli/lib/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class Doctor {
...this.checkIfNpmInstallRequired(),
...this.validateProjectJsonFiles(),
]);

return this.generateOutput();
}

async checkIfNodeIsInstalled() {
Expand Down Expand Up @@ -152,7 +150,8 @@ class Doctor {
async getNpmVersion() {
const exec = util.promisify(execAsync);
try {
return (await exec('npm --version')).toString().trim();
const { stdout } = await exec('npm --version');
return stdout.toString().trim();
} catch (e) {
logger.debug(e);
return null;
Expand Down

0 comments on commit 8df5719

Please sign in to comment.