Skip to content

Commit

Permalink
Display info message when running the lint:fix script post blueprin…
Browse files Browse the repository at this point in the history
…t generation
  • Loading branch information
bertdeblock committed Sep 29, 2022
1 parent 5c26dc2 commit 7ca0283
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/tasks/generate-from-blueprint.js
Expand Up @@ -17,7 +17,7 @@ class GenerateTask extends Task {

if (options.lintFix) {
try {
await lintFix.run(this.ui);
await lintFix.run(this.project);
} catch (error) {
logger.error('Lint fix failed: %o', error);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/install-blueprint.js
Expand Up @@ -51,7 +51,7 @@ class InstallBlueprintTask extends Task {

if (options.lintFix) {
try {
await lintFix.run(this.ui);
await lintFix.run(this.project);
} catch (error) {
logger.error('Lint fix failed: %o', error);
}
Expand Down
21 changes: 11 additions & 10 deletions lib/utilities/lint-fix.js
@@ -1,26 +1,27 @@
'use strict';

const fs = require('fs-extra');
const execa = require('../utilities/execa');
const isYarnProject = require('../utilities/is-yarn-project');
const prependEmoji = require('../utilities/prepend-emoji');

async function run(ui) {
async function run(project) {
let lintFixScriptName = 'lint:fix';
let cwd = process.cwd();
let packageJson = fs.readJsonSync('package.json');

let hasLintFixScript = !!packageJson.scripts[lintFixScriptName];
let hasLintFixScript = Boolean(project.pkg.scripts[lintFixScriptName]);

if (!hasLintFixScript) {
ui.writeWarnLine(
'Lint fix skipped: "lint:fix" not found in package.json scripts. New files might not pass linting.'
project.ui.writeWarnLine(
`Lint fix skipped: "${lintFixScriptName}" script not found in "package.json". New files might not pass linting.`
);

return;
}

let usingYarn = fs.existsSync('yarn.lock');
project.ui.writeLine('');
project.ui.writeLine(prependEmoji('✨', `Running "${lintFixScriptName}" script...`));

let cwd = process.cwd();

if (usingYarn) {
if (isYarnProject(project.root)) {
await execa('yarn', [lintFixScriptName], { cwd });
} else {
await execa('npm', ['run', lintFixScriptName], { cwd });
Expand Down

0 comments on commit 7ca0283

Please sign in to comment.