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(create-waku): --example option #581

Merged
merged 16 commits into from
Mar 12, 2024
Merged

Conversation

ojj1123
Copy link
Contributor

@ojj1123 ojj1123 commented Mar 8, 2024

related #315

I wrote the prototype for --example option. I've referred to create-next-app
I will be adding automatically installing dependencies in next PR.

What features were added

pnpm create waku --example 14_react-tweet // will download https://github.com/dai-shi/waku/tree/main/examples/14_react-tweet

pnpm create waku --example https://github.com/dai-shi/waku/tree/main/examples/14_react-tweet

pnpm create waku --example https://github.com/himself65/waku-vercel-template

also in this PR, i've drop --choose-example as @dai-shi said
#315 (reply in thread)

What I want to discuss

In create-next-app, they are dealing with the branch name or file path containing the slash. But I've thought this case is a bit rare one so I didn't implement this feature in create-waku. How about this case?

Copy link

vercel bot commented Mar 8, 2024

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

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Mar 12, 2024 4:49am

Copy link

codesandbox-ci bot commented Mar 8, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

https://github.com/dai-shi/waku/pull/581/files#diff-995f71dd25297bc098cf21c18a6770843422edd5863adc74f7b181ca7c803bcfR25
We would like to copy only examples/01_template.

@himself65 Can you review please?

(Maybe, it's time for us to add some unit tests.)

packages/create-waku/src/helpers/examples.ts Outdated Show resolved Hide resolved
packages/create-waku/src/index.ts Outdated Show resolved Hide resolved
packages/create-waku/src/index.ts Outdated Show resolved Hide resolved
@dai-shi
Copy link
Owner

dai-shi commented Mar 8, 2024

they are dealing with the branch name or file path containing the slash.

Branch name or tag name is actually important because examples in main branch will be breaking with older versions.

packages/create-waku/src/helpers/examples.ts Outdated Show resolved Hide resolved
packages/create-waku/src/helpers/examples.ts Outdated Show resolved Hide resolved
packages/create-waku/src/index.ts Outdated Show resolved Hide resolved
Comment on lines 22 to 29
/**
* this is a part of the response type for github "Get a repository" API
* @see {@link https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository|GitHub REST API}
*/
interface GetRepoInfo {
/** A default branch of the repository */
default_branch: string;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I take a part of the response type from github docs here

cc. @himself65

@ojj1123
Copy link
Contributor Author

ojj1123 commented Mar 9, 2024

they are dealing with the branch name or file path containing the slash.

Branch name or tag name is actually important because examples in main branch will be breaking with older versions.

@dai-shi
what you mean?
you mean create-waku support the features below?

pnpm create waku --example 01_template // by default, download example from default branch

pnpm create waku --example 01_template --branch with-middleware // download example from with-middleware

This PR's implementation is only to download example from default branch by default

because examples in main branch will be breaking with older versions.

I didn't understand this situation

@dai-shi
Copy link
Owner

dai-shi commented Mar 9, 2024

I didn't understand this situation

Let's say, we release v0.20.0. At that point, we can use npm create --example 01_template, and it works fine.

Meanwhile, we will start merging PRs for v0.21.0, and examples will only work with the new (unreleased) version. If we run npm create --example 01_template at that point, the template won't work with v0.20.0.

@ojj1123
Copy link
Contributor Author

ojj1123 commented Mar 10, 2024

I got that situation.
but each example have package.json. I think that new example for working only with new (unreleased) version is added during or after merging new release.
Wouldn't it be safe if the examples aren't modified before new release or new example is added after new waku release?

Still if you think it is nessasary to get the branch or tag option, i will make it next PR

@dai-shi
Copy link
Owner

dai-shi commented Mar 10, 2024

is added during or after merging new release.

No, that's not the case.
Well, package.json lies in the examples folder (it only works with the monorepo setup.)

Still if you think it is nessasary to get the branch or tag option, i will make it next PR

Yes, it's necessary, but can be a follow-up PR.

@ojj1123 ojj1123 marked this pull request as ready for review March 11, 2024 09:38
@ojj1123 ojj1123 requested a review from dai-shi March 11, 2024 09:39
@ojj1123
Copy link
Contributor Author

ojj1123 commented Mar 11, 2024

Please review this PR.
I will do the works next PR below:

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

I didn't check the behavior though.

@@ -25,16 +25,18 @@
"start": "node ./dist/index.js",
"dev": "ncc build ./src/index.ts -w -o ./dist/",
"compile": "rm -rf template dist *.tsbuildinfo && pnpm run template && pnpm run build",
"template": "cp -r ../../examples template/ && rm -rf template/*/dist && rm -rf template/*/node_modules && mv template/01_template/.gitignore template/01_template/gitignore",
"template": "mkdir template && cp -r ../../examples/01_template template/01_template && rm -rf template/*/dist && rm -rf template/*/node_modules && mv template/01_template/.gitignore template/01_template/gitignore",
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we can just cp -r ../../examples/01_template template. You can consider it in the follow-up PRs.

Copy link
Contributor Author

@ojj1123 ojj1123 Mar 12, 2024

Choose a reason for hiding this comment

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

yeah i've tried to do that. but i've got it like below:

/template
  /src
  package.json
  ...

but i want to do this below:

/template
  /01_template

because i consider that it will be added the extra templates 👍

Copy link
Owner

Choose a reason for hiding this comment

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

okay, i thought the former is fine (single template). We don't know the future, but for now we have only one template.

return (
typeof err === 'object' &&
err !== null &&
typeof (err as { message?: unknown }).message === 'string'
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this works?

Suggested change
typeof (err as { message?: unknown }).message === 'string'
typeof err.message === 'string'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay i will try that next PR


// TODO automatically installing dependencies
// 1. check packageManager
// 2. and then install dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use this? https://github.com/antfu/ni

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh thanks.
My plan is just below:

exec(`${packageManager} install`)

i don't know ni but if it is useful, let's use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that can work too. just wanted to drop a possibility.

Copy link
Owner

Choose a reason for hiding this comment

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

Pay special attention when choosing a dependency. we generally avoid adding new dependencies especially if they are new.

) {
await pipeline(
await downloadTarStream(
`https://codeload.github.com/${username}/${name}/tar.gz/${branch}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

is this downloading the whole waku repo for users?

Copy link
Contributor Author

@ojj1123 ojj1123 Mar 12, 2024

Choose a reason for hiding this comment

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

Yes, the only way to get examples of waku is to download the whole waku repository.
Do you have any concerns or suggestions?
if you do, i would like to consider it

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, it might be too much size to download for the user. If there's no other way then let's go with this. but it's better to find a way.

@ojj1123
Copy link
Contributor Author

ojj1123 commented Mar 12, 2024

@dai-shi
I have no write access to this repository.
I was wondering if you could merge it 👍

@dai-shi
Copy link
Owner

dai-shi commented Mar 12, 2024

I was wondering if you could merge it

Basically, it feels like we are still in the middle of review.
We are not confident if there are no bugs, or if it's well designed / coded.
But, I guess you take the responsibility, so let's merge it this time.

okay i will try that next PR

out of curiosity, why do you prefer separating PRs?

@dai-shi dai-shi merged commit 64e883c into dai-shi:main Mar 12, 2024
28 checks passed
@ojj1123
Copy link
Contributor Author

ojj1123 commented Mar 12, 2024

Basically, it feels like we are still in the middle of review.
We are not confident if there are no bugs, or if it's well designed / coded.

yeah i also agree with you. If you have any feedback, please let me know !

out of curiosity, why do you prefer separating PRs?

i prefer separating the works such as refactoring and other features. I just want to focus on the interests of this PR and i tend to separate the task into smaller tasks and prioritize them.
if you have the other opinion, i could follow your one :)

@ojj1123 ojj1123 deleted the feat/example-option branch March 12, 2024 05:57
@dai-shi
Copy link
Owner

dai-shi commented Mar 12, 2024

if you have the other opinion, i could follow your one :)

Maybe we can create a branch, and send PRs there. Will let you know when it's appropriate.

Meanwhile, send follow-up PRs to main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants