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

feat: CLI for quick scaffolding #277

Merged
merged 20 commits into from Nov 11, 2023
Merged

feat: CLI for quick scaffolding #277

merged 20 commits into from Nov 11, 2023

Conversation

injurka
Copy link
Contributor

@injurka injurka commented Oct 9, 2023

Description

CLI.

  • Removes all previous eslint configs and dependencies as they are no longer needed.
  • Also removes everything related to prettier (if exist), since the current eslint configuration is aimed to work without it.
  • Adds the latest version of eslint and @antfu/eslint-config to devDependencies.
  • Adds/updates .vscode/settings.json to the configuration that was provided in readme.md

Linked Issues

fix #274

Additional context

@injurka injurka marked this pull request as ready for review October 9, 2023 11:19
package.json Outdated Show resolved Hide resolved
antfu
antfu previously requested changes Oct 9, 2023
src/cli/index.ts Outdated
Comment on lines 60 to 77
const eslintIgnorePath: string = path.join(cwd, '.eslintignore')
let eslintIgnoreLines: string[] = []

if (fs.existsSync(eslintIgnorePath)) {
const eslintIgnoreContent: string = fs.readFileSync(eslintIgnorePath, 'utf-8')
eslintIgnoreLines = eslintIgnoreContent.split('\n')
}

const eslintConfigContent = `
import antfu from '@antfu/eslint-config';

export default antfu({
${eslintIgnoreLines.length
? `ignores: [
${eslintIgnoreLines?.map(line => `'${line}'`).join(',\n')}
],`
: ''}
});`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use parse-gitignore package, as the ignore format is a bit different from globs, the reference here:

https://github.com/antfu/eslint-config-flat-gitignore/blob/60240bb3d1dfea0bf48aaa962e18f15f1547b4eb/src/index.ts#L24-L31

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't work out for me to use parse-gitignore or prompts with esm, so i can to change the import from ejs to cjs in bin/index.js to ../dist/cli/index.cjs. Or use unbuild with alias field. I chose the second option. However, i am not competent in this and do not know how best. My desire to realize exceeds the available knowledge (((

image

src/cli/index.ts Outdated

console.log(c.dim(`\nSetup eslint config...\n`))

// Update package.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have a few prompts for each step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not quite sure what exactly is meant, and Im also not sure I can envision a completely correct promts usage scenario on your behalf, so as best I could.

By the way, what do you think about splitting the functionality into separate parts, e.g.

export async function cli() {
  console.log(c.dim(`\nSetup eslint config ...\n`))

  const pkg = await updatePackageJson()
  await updateEslintFiles(pkg)
  await updateSettingsJson()

  console.log(c.green('\nSuccessful. Now you can update the dependencies and run'), c.dim('eslint . --fix\n')))
}

Or is it better to leave it as it is?

src/cli/index.ts Outdated Show resolved Hide resolved
src/cli/index.ts Outdated Show resolved Hide resolved
src/cli/index.ts Outdated Show resolved Hide resolved
src/cli/index.ts Outdated
}
// End update eslint files

// Update .vscode/settings.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A prompt would be nice.

src/cli/index.ts Outdated
Comment on lines 107 to 108
const settingsJsonWithoutComments = settingsContent.replace(/\/\/.*|\/\*[\s\S]*?\*\//g, '')
settings = JSON.parse(settingsJsonWithoutComments)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we won't want to remove all comments. Maybe instead of parsing, we insert the text before the last }. Leaving the formating to the ESLint config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its quite a difficult situation, in the sense that I cant parse it because of the presence of comments and I cant overwrite the fields as such, because I read it as a string line. I tried to do as you said and take into account all the problematic situations, but im not sure that such an implementation is okay 🥴

@injurka injurka requested a review from antfu October 10, 2023 14:23
@antfu antfu changed the title CLI for quick scaffolding feat: CLI for quick scaffolding Nov 10, 2023
@antfu antfu merged commit 2ee5a69 into antfu:main Nov 11, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI for quick scaffolding
2 participants