create-next-app icon indicating copy to clipboard operation
create-next-app copied to clipboard

Custom repo templates

Open jasonkylefrank opened this issue 6 years ago • 5 comments

Purpose of the pull request

This PR adds the ability to specify a custom repository as the starting point (i.e., template) for the created Next.js app, instead of only allowing the Next.js examples for the starting point. I wanted to be able to create other templates, push them to GitHub, and then use those as my starting-point template for create-next-app. I did not necessarily want to get them added to the example set in Next.js's repo. This PR solves that issue.

Testing this code

Here is how you can test it without installing it. Notice the new --clone-repo option:

$ node cli --clone-repo https://github.com/<username>/<reponame> output-dir

This will check to see if the supplied URL is a git repo. If it is, it proceeds to with a similar routine that happens when an "example" is specified: It creates the output directory, and then it clones the repository into the new directory, followed by the other normal activities, such as running npm install, etc.

Obviously if this package was installed it should be called like this:

$ create-next-app --clone-repo https://github.com/<username>/<reponame> output-dir

jasonkylefrank avatar Oct 04 '18 20:10 jasonkylefrank

This is great Jason, thanks! I've left a few comments inline we should discuss, but I think we can get this in soon 😄

stephenmathieson avatar Oct 05 '18 14:10 stephenmathieson

@stephenmathieson Thanks for your comments! I've tried to address each one. I'm currently blocked on this comment thread though.

jasonkylefrank avatar Oct 12 '18 20:10 jasonkylefrank

I'd be very interested in this as well.

As for the argument naming, I instinctively typed:

yarn create next-app my-project -e https://github.com/franky47/next-template

Although -e should probably be reserved for "official" examples in the nextjs repository.

franky47 avatar Oct 23 '18 09:10 franky47

Would be interested in using this @jasonkylefrank — currently leveraging create react app fork/template solution, but looking to create something for next. Where are you at with this? Can I help?

bbuckland avatar Nov 13 '18 19:11 bbuckland

Hi @bbuckland ! Great to hear that you're interested in this!

To answer your question about the status, I think this PR is very close to being accepted. I was only waiting on response from @stephenmathieson regarding my Oct 12 fixes.

I believe I addressed the issues that @stephenmathieson pointed out, but 2 small issues require some interaction to finalize:

  1. The command-line keyword --clone-repo could be adjusted if we find that another keyword is better. In this comment thread I suggested some options.

  2. There was some discussion about whether or not we needed some Promise wrappers in some of the new code, particularly in my validateRepoName() and clone() functions in clone-repo.js. After digging into it more, I think we should keep them present. This is due to how the simple-git library uses promises internally. I outlined this issue more in this comment thread.

So in short, if we (a) agree on the proper keyword and (b) are agreeable to use the promise wrappers mentioned in clone-repo.js, then I believe this is done. Again, mostly just waiting on response from @stephenmathieson .

Final note, it looks like my code in clone-repo.js currently has the promise wrapper in clone() and does not have the promise wrapper in validateRepoName(). That's because I was systematically trying to get rid of those wrappers when I ran into those problems and ended up finding the info about how the simple-git library is using promises internally. I think my testing showed that it would be better to keep the promise wrapper in validateRepoName() (just like it currently is in clone(). I can't test that at the moment though, so maybe that's something that @bbuckland can help test (with and without the promise wrapper in validateRepoName())?

jasonkylefrank avatar Nov 14 '18 14:11 jasonkylefrank