8000 feat: preconditions by manuel3108 · Pull Request #368 · svelte-add/svelte-add · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

feat: preconditions #368

Merged
merged 8 commits into from
May 24, 2024 8000
Merged

feat: preconditions #368

merged 8 commits into from
May 24, 2024

Conversation

manuel3108
Copy link
Member
@manuel3108 manuel3108 commented May 19, 2024

First part for: #337,
helpful for #338, #363

This adds preconditions to svelte-add checks. Preconditions can be useful to determine if the environment is in a good state to apply the adder. In the future this could contain checks for checking if global tools (rust, cargo, see #338) are installed. While implementing I found out that we should be able to use this feature for detecting if the user currently has a dirty git repository and warn him about that (#363).

Opposed to the implementation of gatekeeping that svelte-add@v1 had in place, the user should have the possibility to ignore the preconditions and install the adder if he really likes to.

Sample usage:

export const checks = defineAdderChecks({
    options,
    preconditions: [
        {
            name: "rust installed",
            run: async () => {
                try {
                    await executeCli("rust", [], process.cwd());
                    return { success: true, message: undefined };
                    // eslint-disable-next-line no-unused-vars
                } catch (_) {
                    return { success: false, message: "Failed to execute rust cli" };
                }
            },
        },
        {
            name: "cargo installed",
            run: async () => {
                try {
                    await executeCli("cargo", [], process.cwd());
                    return { success: true, message: undefined };
                    // eslint-disable-next-line no-unused-vars
                } catch (_) {
                    return { success: false, message: "Failed to execute cargo cli" };
                }
            },
        },
    ],
});

The sample above results in the following console output:
image

The following things still need to be done

  • make sure the tests work correctly.
  • improve console output. It should be displayed inside the prompts intro and outro, and not separately as it is now.
  • add ability to execute cli commands inside the preconditions
  • exchange the symbols (checkmark / crossmark) with colored console output
  • fix circular dependency

@manuel3108 manuel3108 marked this pull request as ready for review May 24, 2024 16:55
@manuel3108 manuel3108 merged commit 9086cda into main May 24, 2024
1 of 2 checks passed
@manuel3108 manuel3108 deleted the feat-precondtions branch May 24, 2024 17:10
@github-actions github-actions bot mentioned this pull request May 24, 2024
@manuel3108 manuel3108 mentioned this pull request Jun 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0