Closed samdark closed 6 years ago
I think need do it via lite(core) version
@schmunk42 what is your worry about having a separate template? For me, having something specific is much more desirable than something trying to do all things, otherwise they are not really templates.
@rustamwin Can you link to the lite version and what that is so I can see?
It would be good to have separate templates:
My experience is that whether you have an API, CLI or web-site your application (eg. models, components, modules, ...) account for most of the code.
I.e. all web-applications also have CLI commands, eg. yii migrate
. Not necessarily an API, but nowadays it's also very likely - and as said above the API often also uses your application models. API projects also come with CLI commands.
So it boils down to three "entrypoints" for your application:
/
(serving HTML)/api
(serving JSON or XML)yii
(CLI)I'm talking about microservice architecture where each service is absolutely independent from other components. @schmunk42, you are talking about monolith app.
It’s often needed a service which 1) takes data from message queue channel, 2) does some conversion / processings / sending emails or push notifications, and so on, 3) sends data to another message queue channel.
There is no need in any endpoints other than CLI there. It should have very simple skeleton but with logs, tests, init
and other Yii app functionality.
The same is about API app — mostly it has to serve API endpoints and send / get data from other services via internal API or message queue. Here also CLI needed but just for basic things like migrations.
Web app has much different structure and more visual components than API app.
So definitely all these three app types will be used for absolutely different purposes.
Now to create such services I have either to create a new microservice app from scratch (manually adding logs, tests, caches), or use “advanced” app and then remove all obsolete things (like backend or frontend namespaces) from there. Both these options take time, and prevent me from using updates, improvements or bugfixes for “advanced” or “basic” apps.
@roslov I agree in several points, currently there are way too many files in the app template, IMHO.
That's why I created a proposal here https://github.com/yiisoft/app/pull/41
There will be always trade-offs, but nonetheless I think the above PR would be a step in the right direction.
CC: @yiisoft/core-developers @yiisoft/reviewers
Having worked on angular for a while I found the approach that NRWL takes quite helpful. Maybe that would be something Yii could also offer, a workspace, where you have one vendor
and cli
folder that all possible "apps" would pull from, if needed.
A structure could look like this then:
-- /bin (with yii.php)
-- /apps
---- /web
---- /api
---- /vue-comp (all the JS stuff)
-- /libs (what is now modules, things that any of the apps can rely on, abstraction of core logic)
-- /vendor
-- /config (all of the common config stuff, each app can then have its own set, if needed)
-- composer.json
-- /node-modules (if one uses js dev somewhere in the apps)
-- package.json
Currently we are working on a software that started with template from kartik-v. We moved and deleted stuff ... now we are switching slowly to vuejs components, so there is a need for api controllers. I think this mix of pure php "web" and more api-driven code may become more common now.
Just my two cents worth :)
EDIT: Thinking even further ... Yii could offer, as part of the cli, the option to start with a specific template, say, Yii-Vue or Yii-Advanced or Yii-jquery or whatever. The CLI would then create the necessary folders and add assets, etc.
E.g. yii app/create yii-vue
Actually I would prefer one modular template with everything (separate endpoints for backend, frontend, api, console) and some initial script which will ask 2-3 questions and remove unnecessary parts of template.
ask 2-3 questions and remove unnecessary parts of template.
That's probably a very good idea.
I was just considering the same thing, we get to have a single source for the template but still allow correct customisation. For example, you could ask the dev if they want cookies enabled or not and modify the config appropriately.
Is this easy enough to do directly with Composer or would there be an easier way? Perhaps run a Yii console command after installing with Composer?
In addition to the above I'd like to see something like:
composer require yiisoft/yii2-bootstrap4
*** register asset-bundle***
...to get a theme.
composer require yiisoft-contrib/yii2-user
or
composer require 2amigos/yii2-usuario
to install a user-module.
Is this easy enough to do directly with Composer or would there be an easier way?
I'd no tie this to composer.
Perhaps run a Yii console command after installing with Composer?
A console command which is part of the framework would be great.
I'd no tie this to composer.
Why not?
What do we want the script to configure for the developer?
We can start with a simple set and see whether Composer can handle it. The script should be able to delete unrequired folders/files, modify config files and modify composer require. Anything else?
https://github.com/yiisoft/yii2-composer is a good example of what could be tied to Composer.
I'd no tie this to composer. Why not?
Because composer's task is to install packages, not to prepare the project and its environment. And script hooks in composer are hard to debug, how do you run them without composer? If they fail your package installation process might fail also.
how do you run them without composer?
Why should you?
Why should you?
Because I don't want to bake the setup of my application into the package manager, as said above.
Because different environments might require slightly different setups.
Even if there is a postCreateProject
hook (I made the PR once) you can't even modify what it is doing until you got the project code and ran it.
The question is more, why should we use composer for that? I also don't think yii2-composer
is a good example of what could be tied to composer; with exception of the extensions part, since it's directly related to application packages, but not setting permissions or copying files.
OK. How do you see it?
For application setup I'd like to see a console command as part of the framework, see https://github.com/yiisoft/app-api/issues/1#issuecomment-400623446
composer create-project yiisoft/app
vendor/bin/yii app/init
* Asking questions like mentioned above...
We're using make
for several of those tasks, but I think it might not be portable enough across different platforms.
Does it make sense to re-run that init command after install is done?
Does it make sense to re-run that init command after install is done?
Sure, for debugging or in case you have removed a folder like runtime
. A CLI command is much better suited for that, than composer-hooks triggering class methods - how would you run those manually?
There is also difference between interactive setups (eg. first time project creation) and non-interactive ones for deployments.
You'll never deploy a template. It's always interactive.
We are talking about multiple tasks here:
I don't think we should bloat framework core with commands for app initialization. We could create separate composer package, which will provide commands for this task. These commands can be triggered by composer or manually.
After initialization package could be just removed. But with good design it could be used event after initialization, for example to add separate endpoint to existing application.
So is everyone agreed that we will start by creating something with Composer and an interactive shell and see if we can get that to work?
Yep, I think that's the way to go.
Basic design considerations expound here https://github.com/yiisoft/yii-base-web/issues/45#issuecomment-415479940
@samdark I can not close this issue, btw
@schmunk42 should it be closed?
I think so, installation is done via composer require yiisoft/yii-base-api
it's clear that this application will not have any assets or CLI commands.
Is it has been finished?
The template? No. But we agreed on how to proceed with it.
Do we really need this or can we handle it via
yiisoft/app
? See also https://github.com/yiisoft/yii2-app-basic/issues/184#issuecomment-399400693