storyblok / field-plugin

Create and deploy Storyblok Field Plugin
https://www.storyblok.com/docs/plugins/field-plugins/introduction
25 stars 3 forks source link

feat(cli): check for duplicated names #362

Closed demetriusfeijoo closed 4 months ago

demetriusfeijoo commented 4 months ago

What?

It allows our CLI to handle duplicated name errors when deploying new field plugins.

image

Why?

JIRA: EXT-2053

As we don't have an ENDPOINT to check globally (from all users and scopes) whether a plugin with the same name, already exists in someone's account or in a different scope, naming collisions can happen during creation time.

The idea then is to not check it before trying to create a new plugin (because we don't have an endpoint for doing it globally) but a failing first approach, meaning that if we are not sure if a plugin with the same name exists or not we first try to create it and if it fails due name collision error, we prompt the user to rename it and try again with the new name. The user is going to be prompted about providing a new name until a unique name is provided or he/she doesn't quit the deployment routine.

Changing the update flow wasn't necessary since the duplicated name error is raised only during creation time, but as I did some refactoring I think is worth to check also the update flow.

How to test?

I think the easiest way to test it out maybe by, from the root of the repository, running:

yarn install

cd packages/cli/templates/react

yarn build && yarn build:cli && npx field-plugin deploy --token <your preview token>

The test scenarios I thought were:

  1. Deploy a new field plugin with a set of options
    • If the new name is duplicated (meaning it belongs to another user or another scope), the user needs to be prompted to continue to rename it or to abort. Until the user doesn't choose a unique name he/she will be still prompted to choose a new name since the one chosen is not unique. The user can skip any time just by saying no when prompted the first time.
    • If a unique name is provided, then, the new field plugin and its options should be listed in the Field Plugin Editor.
  2. Update the newly created field plugin with some other set of options
    • It should list all the new set of options in the Field Plugin Editor
  3. Update the newly created field plugin with no options
    • It shouldn't list any option in the Field Plugin Editor since no option was found in the manifest file.
  4. Try to update the newly created field plugin with a set of options but then, when prompted if the user wants to update the existing field plugin or to create a new one, proceed with the creation.
    • It should ask for a new name
    • If the user wants to save the new in the package.json, he/she can.
    • If the new name is duplicated (meaning it belongs to another user or another scope), the user needs to be prompted to continue to rename it or to abort. Until the user doesn't choose a unique name he/she will be still prompted to choose a new name since the one chosen is not unique. The user can skip any time just by saying no when prompted the first time.
    • If a unique name is provided, then, the new field plugin and its options should be listed in the Field Plugin Editor.
vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plugin-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2024 5:10pm
demetriusfeijoo commented 4 months ago

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

eunjae-lee commented 4 months ago

Also, could you test to make sure --skipPrompts parameter works well with all the scenarios?

demetriusfeijoo commented 4 months ago

Also, could you test to make sure --skipPrompts parameter works well with all the scenarios?

Oh, nice point @eunjae-lee, thanks! 💯

It was breaking when --skipPrompts was informed and there was a name collision. Fixed it here.