-
-
Notifications
You must be signed in to change notification settings - Fork 479
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
Conversation
src/cli/index.ts
Outdated
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')} | ||
],` | ||
: ''} | ||
});` |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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 (((
src/cli/index.ts
Outdated
|
||
console.log(c.dim(`\nSetup eslint config...\n`)) | ||
|
||
// Update package.json |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
} | ||
// End update eslint files | ||
|
||
// Update .vscode/settings.json |
There was a problem hiding this comment.
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
const settingsJsonWithoutComments = settingsContent.replace(/\/\/.*|\/\*[\s\S]*?\*\//g, '') | ||
settings = JSON.parse(settingsJsonWithoutComments) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🥴
Description
CLI.
eslint
configs and dependencies as they are no longer needed.eslint
configuration is aimed to work without it.eslint
and@antfu/eslint-config
todevDependencies
..vscode/settings.json
to the configuration that was provided inreadme.md
Linked Issues
fix #274
Additional context