-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add package manager selection and --dry-run option #92
base: main
Are you sure you want to change the base?
Conversation
This commit introduces a new, self-contained module located at `src/actions/create-config.ts`. This module is designed to handle creating and managing the Stylelint configuration file. **Functionality:** - **Configuration Existence Check:** The module begins by implementing a mechanism for detecting existing Stylelint configurations. This is crucial to prevent accidental overwriting of user-defined settings. The `findExistingConfig` function leverages the `cosmiconfigSync` utility. This search ensures that all common configuration locations are considered. This prevents accidental overwrites. - **Conditional Configuration Creation:** Based on the user's initial preference (selected in a prior step), the module determines the appropriate base configuration to extend. If the user opted for a basic setup focused on error detection, `stylelint-config-recommended` is chosen. For users desiring a more opinionated and comprehensive setup, `stylelint-config-standard` is selected.
This commit introduces the `src/actions/ensure-package-json.ts` module to ensure a `package.json` file exists in the project directory. Key changes: - Implements `hasPackageJson` which uses `fs.readdirSync` to check if `package.json` exists in the directory. - Implements `initializePackageJson` which creates a default `package.json` if one is missing. It uses `execa` to run the `npm init -y` command. - Implements `ensureProjectPackageJson` as the main function to check for and potentially create the `package.json`.
This commit introduces the `installProjectDependencies` action to handle the installation of necessary project dependencies. Key changes: - Implements `installProjectDependencies` which uses `execa` to execute the package manager's install command. - Installs `stylelint` and either `stylelint-config-recommended` or `stylelint-config-standard` based on the user's usage preference. - Uses `getInstallCommand` to determine the correct install command (`install` for npm, `add` for others).
This commit introduces the `promptInstallDependencies` function to ask the user whether to install specified dependencies. Key changes: - Uses the `prompts` library to present a confirmation prompt to the user. - The prompt message includes the package manager and the list of dependencies to be installed. - Returns a boolean indicating the user's choice.
This commit introduces the `promptPackageManager` function to allow the user to select their preferred package manager (npm, pnpm, or yarn). Key changes: - Uses the `prompts` library to present a selection prompt. - Uses `which-pm-runs` to pre-select the package manager if it's already being used in the project. - Returns the selected package manager.
This commit introduces the `promptUsagePreference` function to let the user choose their preferred Stylelint usage level (error detection only or error detection and style enforcement).
This commit introduces a `messages` module to centralize all user-facing messages within the application.
This commit introduces a signal handler to gracefully handle the SIGINT signal (typically triggered by Ctrl+C). Key changes: - Implements `setupProcessHandlers` to attach a listener to the `SIGINT` signal. - When the signal is received, the handler logs a message indicating cancellation and then exits the process.
This commit introduces the main application logic within the `main` function. Key changes: - Sets up process handlers for graceful cancellation. - Checks for existing Stylelint configurations and exits if one is found. - Ensures the existence of a `package.json` file. - Prompts the user for their preferred Stylelint usage (errors only or errors and style). - Prompts the user to select their preferred package manager. - Prompts the user to confirm the installation of necessary dependencies. - Conditionally installs dependencies and creates the Stylelint configuration file based on user input. - Displays next steps and customization information upon successful setup.
…e manager support Updates the package description to be more generic ("The initialization script for Stylelint.") instead of being specific to npm init. Also updates the keywords to better reflect the functionality and improve discoverability, including terms like "configuration", "initializer", "cli", and "setup".
…ed dependencies, added context, minor fixes to improve readability
I have some questions to discuss before we ship this.
If you have any questions or suggestions for improvements, please @mention me in here. I'm currently having some health issues, so being directly mentioned will help me track notifications better. I will check this draft from time to time, when we're ready with the suggestions I'll begin implementing new tests and an entry point in the root folder (index.mjs). |
Co-authored-by: Gary Gozlan <[email protected]>
Example workflow with package.json already existing (no audio): 2024-12-27.16-36-53.mp4 |
Example workflow with no package.json existing (no audio): 2024-12-27.16-42-11.mp4 |
@idkgene Thank you for working on this; it looks great! I also appreciate the clarity of the PR description. I've two preliminary comments related to some decisions we took with Stylelint that may not be obvious:
With these suggestions in mind, we can summarise the tool's scope as an initialisation script that installs Stylelint and the Standard config using a person's preferred package manager and then creates an ESM configuration file to extend that config. It also provides a dry-run option for transparency and safety.
I'd expect Ctrl + C to exit the tool completely, but it would be interesting to know what Astro's and ESLint's init tools do and how they approach testing. Thanks again for broadening our support of package managers. It'll help more new users quickly get up and running with Stylelint. It's great to see bun support included, too! |
…t post-install command
Latest Update Summary:
On My List (Personal Notes):
Links for later: |
@idkgene Thank you for your recent commits. The latest summary looks great! It would be interesting to see what is uncovered about testing. However, I think we can start with a light touch. Once the testing is in place, I think we can undraft the PR for others to review. And once we've merged and released this PR, we can update our docs as part of stylelint/stylelint#8210 to inform people that the init script supports other package managers. |
@jeddy3 Thank you for your feedback! It's currently 8 PM my time, and I'm just about to join my family to celebrate New Year's. As for your question, in short, I noticed they test individual 'modules' using fixtures and that's the play. I also have some tests already that haven't been submitted yet. I'll be back with more detailed comments and information tomorrow afternoon, after the holiday celebration. Wishing you and your family a very Happy New Year filled with joy, success, and good health! 🎉✨ |
It's great that you're willing to post some more details tomorrow. Please don't feel rushed, though. As open-source contributors, we do what we can when we can. Thank you for your kind words about the new year. I wish you and yours all the best in 2025! 🎉 |
Latest Updates TLDR (mostly UX)
Preview of the latest changes (audio muted, video is speeded up)2025-01-01.15-26-28.mp4Questions UX relatedI've been critically examining our CLI's user experience, comparing it with Astro's approach. While our current implementation provides functionality, there are opportunities for improvement in user guidance and interaction clarity. So the questions are:
This looks nice, isn't hard to implement, yet I'm overwhelmed so that the tool should save the balance between being informative, but not overly verbose. I want the implemented functionality to be good and intuitive for the dev either if he is super skilled or not at all. TestingI assume that our approach is as follows:
I think it would be appropriate to fixtures like this: const configs = {
js: './fixtures/configs/stylelint.config.js',
mjs: './fixtures/configs/stylelint.config.mjs',
// and so one
}; As long as all this formats are in docs I think they need to be tested. Modules as I wrote above should be tested in isolation and itntegration test will check the full flow of CLI operation. Currently actions tests are finished. Prompts, utils and main flow to be done. Planning on getting PR out of the draft when I'm done with the tests. |
Addition described in the PR's TLDR comment.
Thank you for your latest additions. It's shaping up to be a useful and robust tool!
Yes, I believe both improve the user experience as people can:
What do you think about the following?:
For
Do you think that'd be possible? (Adding details to each step makes the |
Hey. I wanted to apologize for the delay in getting this PR finalized. I’ve been working on it in my spare time, and I’ve run into a couple of issues with |
@gnify No need to apologise. As open-source contributors, we do what we can when we can. Many thanks for working on this in your spare time. Take as long as you need. We appreciate your efforts. The PR is looking great and significantly improves user experience, especially for people encountering Stylelint for the first time. So, thank you! |
This PR introduces a significant overhaul to the
npm init stylelint
command, focusing on providing users with greater control and transparency during the initial setup process. I've implemented two key features:--dry-run
option.Motivation
The existing
npm init stylelint
command, while functional, makes implicit assumptions that can lead to friction and confusion for users:Implicit npm Assumption: The tool automatically uses npm for dependency installation, disregarding the user's potential preference or existing project setup with pnpm, yarn, or bun. This forces manual intervention and can lead to inconsistencies in dependency management.
Lack of Transparency and Safety: The tool directly modifies the file system without providing a way to preview the intended actions. This can be problematic for users who want to understand the changes before they are applied or for debugging potential issues.
This PR directly addresses these shortcomings, resulting in a more observable initialization experience.
Breakdown of the changes Made:
1.
src/actions/context.ts
:npm init stylelint
command. It parses command-line arguments, detects the package manager, and creates aContext
object that holds information, which we need throughout the initialization process.2.
src/actions/create-config.ts
:.stylelintrc.json
configuration file.3.
src/actions/ensure-package-json.ts
:package.json
file exists in the project directory. If it doesn't, it attempts to create one.4.
src/actions/help.ts
:--help
flag is used.5.
src/actions/install.ts
:6.
src/actions/post-install.ts
:7.
src/prompts/install-now.ts
:8.
src/prompts/package-manager.ts
:9.
src/prompts/usage-preference.ts
:10.
src/shell.ts
:child_process.spawn
function for executing shell commands.Note
This was created to replace
execa
, reducing the project's dependency footprint. Comes from astro - https://github.com/withastro/astro/blob/main/packages/upgrade/src/shell.ts11.
index.ts
:npm init stylelint
command. It orchestrates the entire initialization process.Related Issues
#16
#91