Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Display info message when running the lint:fix script post blueprint generation #10026

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
bertdeblock marked this conversation as resolved.
Show resolved Hide resolved
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