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): use project name from package json by default #20479

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

abdallahmz
Copy link
Contributor

@abdallahmz abdallahmz commented Jun 10, 2024

What does it do?

When prompting the user for the name of the project during the deployment process, the setDefaultName function sets the default project name to the name of the existing Strapi project (retrieved from package.json), instead of using a generic default name like "my-strapi-project".

  • Also added unit testing config to the cli/cloud package.
    To run: yarn test:unit from the cloud folder.

Why is it needed?

This change is needed to improve the user experience during the deployment process

How to test it?

  • you need to have Strapi Cloud services running locally (main server + cli-api)
  • run yarn build in the strapi/strapi folder containing this code's repository
  • create a new strapi CMS project
  • from the strapi CMS project: call the built strapi.js command to run the login command
  • Then, use the deploy command:
    When asked for the name of the project, check that the default value is the name of your existing project (as specified in package.json), not "my-strapi-project".

Result:

Screenshot 2024-06-14 at 11 28 35

Related issue(s)/PR(s)

Let us know if this is related to any issue/pull request

Copy link

vercel bot commented Jun 10, 2024

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

Name Status Preview Comments Updated (UTC)
contributor-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 8:02am

@gonbaum gonbaum force-pushed the feature/cloud-cli branch 2 times, most recently from 0cdc9f0 to 0c96b74 Compare June 11, 2024 12:18
Base automatically changed from feature/cloud-cli to develop June 12, 2024 08:21
@abdallahmz abdallahmz force-pushed the feature/cloud-cli-default-project-name branch from beda654 to b731004 Compare June 12, 2024 14:43
@abdallahmz abdallahmz added source: cli Source is cli package pr: enhancement This PR adds or updates some part of the codebase or features labels Jun 12, 2024
@abdallahmz abdallahmz force-pushed the feature/cloud-cli-default-project-name branch from b731004 to 360d43a Compare June 14, 2024 09:09
@abdallahmz abdallahmz force-pushed the feature/cloud-cli-default-project-name branch from 360d43a to ab08c32 Compare June 14, 2024 09:14
@abdallahmz abdallahmz force-pushed the feature/cloud-cli-default-project-name branch from ab08c32 to 0b891c4 Compare June 14, 2024 10:03
@abdallahmz abdallahmz force-pushed the feature/cloud-cli-default-project-name branch from 0b891c4 to 6a88b01 Compare June 17, 2024 08:42
@abdallahmz abdallahmz requested a review from gonbaum June 17, 2024 08:42
Comment on lines 9 to 13
defaultValues.name = newDefaultName;
const nameQuestion = questions.find((q) => q.name === 'name');
if (nameQuestion) {
nameQuestion.default = newDefaultName;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid mutating parameters, please?
I believe we want to go towards functional programming and pure functions. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice thought, function updated!

if (question.name === 'name') {
return { ...question, default: newDefaultName };
}
return { ...question };
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to create a fresh object?

Suggested change
return { ...question };
return question;

If the point was to copy the object to not keep the reference, then you might want to do a deepClone instead of destructuring. 🤔

Copy link
Contributor Author

@abdallahmz abdallahmz Jun 17, 2024

Choose a reason for hiding this comment

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

Went for the JSON parse/stringify to do the copy, although it'll only work with simple objects/array (The initial code would've at least kept the functions if they were added to the question)

The only solution without any "effective" drawback would be to add a proper class or factory to instantiate the "question" and "default values" objects and use that instead. You think it's worth refactoring now?

Copy link
Member

Choose a reason for hiding this comment

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

I think you didn't responded to my first question 😄

But in any case, if we really want to copy, we can use https://lodash.com/docs/4.17.15#cloneDeep

Copy link
Contributor Author

@abdallahmz abdallahmz Jun 17, 2024

Choose a reason for hiding this comment

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

Indeed, I want to avoid having the same references. Initial code works for the current code since we only have scalar values so far.
Using cloneDeep now, should be better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: enhancement This PR adds or updates some part of the codebase or features source: cli Source is cli package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants