ramsey / php-library-starter-kit

:building_construction: A tool to quickly set up the base files of a PHP library project.
MIT License
243 stars 25 forks source link

Pre answer the questions? #33

Closed simpleapps-io closed 2 years ago

simpleapps-io commented 2 years ago

How do I use the answer file or otherwise give the starter kit the answers before running the command?

ramsey commented 2 years ago

The answer file is provided as a convenience, in case the user quits the wizard before finishing the questions.

I hadn't considered a use case where users might want to pre-answer the questions, but that's something that might be possible. The answers file is named .starter-kit-answers and is located in the root of the project. The data consists of all the public properties of Ramsey\Dev\LibraryStarterKit\Answers encoded as a JSON object. It might be possible to pass an additional parameter to the composer create-project command that tells it the location of an existing answers file to load.

Can you tell me more about this use case, so I can get a better understanding of how you want to use it?

simpleapps-io commented 2 years ago

Here is the use case. I'm creating a series of microservices based on https://github.com/spiral/framework Each service is going to have a library that has code that is auto-generated for the client library/SDK, the libraries are based on this starter kit and then the generated code is placed into the library and customized with https://github.com/nikic/PHP-Parser

The lead microservice in the project already has the code to pull in details from SQLServer about the columns, create the microservice app, generate the gRPC/Protobuf files, and created the client library with tests and data validation.

I'm looking to replicate this process and set up at least 10 more times for other microservices, possibly 25+ times. If I could pre-generate the answers for the library (outside of the project folder) I would be able to take out a large manual step. If the format documentation and a command-line option for pointing to an answer file were available that would be wonderful.

I think the file would need to live outside the project folder as I got an error message about the folder not being empty when I tried to create an answer file in the location it appeared to expect it. This would fit well into my design as I have folders for each microservice that have details about how it is set up and options for the code builder to create the code.

I can provide more details on the system in a direct message if needed.

ramsey commented 2 years ago

Sounds good. I think this is enough information. I need to figure out how to pass additional parameters when using composer create-project, but once I've figured that out, the rest of it should be pretty straightforward.

simpleapps-io commented 2 years ago

Excellent

simpleapps-io commented 2 years ago

Would it be easier to look for environment variables? or maybe an environment variable that points to the answers file?

ramsey commented 2 years ago

@simpleapps-io An environment variable is definitely easier and is a great idea. Thanks!

Check out the notes here on the 3.3.0 tag, and give it a try: https://github.com/ramsey/php-library-starter-kit/releases/tag/3.3.0

ramsey commented 2 years ago

@simpleapps-io, was this useful for your needs?

simpleapps-io commented 2 years ago

I missed the update. I will test within the new few days. Thank you.

simpleapps-io commented 2 years ago

I ended up writing a Symfony command to create the answer file and once I get the format and parameters correct it works great! Thank you!

ramsey commented 2 years ago

Awesome! That's great to hear. Thanks for the feature idea.