caffeinated / modules

:package: Modules package for Laravel
https://caffeinatedpackages.com
MIT License
954 stars 230 forks source link

config:publish #26

Closed illuminate3 closed 9 years ago

illuminate3 commented 9 years ago

Is there a command to publish the config files for this package (and themes) or do we just copy and paste them?

Arigatou!

kaidesu commented 9 years ago

Right now, manually copy. I need to get Laravel 5's vendor publishing command set up still. Once that update is made you'll be able to run php artisan vendor:publish to copy the config file to your app.

illuminate3 commented 9 years ago

Sweet!

illuminate3 commented 9 years ago

Could you explain this in more detail. Actually, an update to the codex would be better.

Does this just publish the caffeinated module package or does this work for each created module?

I tried to run the command and didn't see anything being published. But then again I don't have a module config file yet, nor am I sure that I was doing it right.

kaidesu commented 9 years ago

This simply publishes the package's config (modules.php) file to your config directory for your application.

illuminate3 commented 9 years ago

I just ran

vendor:publish --provider="caffeinated/modules"

Got the publish complete message but didn't see a modules.php in the L5 config directory.

Also, how would you go about creating a config file for a module?

kaidesu commented 9 years ago

You just need to run vendor:publish, and also when using the --provider parameter, you need to reference the package's service provider:

vendor:publish --provider="Caffeinated\Modules\ModulesServiceProvider"

For your modules, you should be able to do the same from within your module's service provider, check out the Laravel documentation here: http://laravel.com/docs/5.0/packages#configuration on how to set it up. You'll probably only need the $this->mergeConfigFrom() method.

I personally haven't tried this or have needed to create a module-specific config file, so let me know how it goes!

illuminate3 commented 9 years ago

published main config file. Tried to move the Modules directory up 1 level to the main directory and checked all the namespaces (hopefully) and was not getting routes and what not to work. I'll dig deeper when I try again.

Was there any reason why you decided to go with the App directory?

Thanks for the tip about the module config!

kaidesu commented 9 years ago

Sorry, looks like I had the publish path mixed up. 0f8903abef856444621956881d2bdb11379244be fixes this.

There were a couple reasons why I chose the app directory as the default location.

  1. Modules are related to and extend your application, so it made since to place the Modules directory within app (where you already have your controllers, requests, etc.).
  2. The app directory is already namespaced and autoloaded by default. If I placed the modules directory at the root of your Laravel installation, you'd have to register a new psr-4 autoload path letting Laravel know about your modules. This would have been an extra step to getting things set up and installed.

Sounds like you haven't added your new modules directory to your composer's psr-4 autoload array:

composer.json

"psr-4": {
    "App\\": "app/",
    "Modules\\": "modules/"
}

and in your modules.php config file:

config/modules.php

'path' => base_path('modules'),

'namespace' => 'Modules\\'

That should do it~

illuminate3 commented 9 years ago

Ah! There was a bug then. Thanks for fixing that.

I'm just not sure if app/modules or just modules is better. I'm just thinking of directory structure and ease of use for end users. My goal is to build out an extendable application framework something like WP which allows users to download plugins. Actually, something like the laravel October app but having it be more laravel than symfony.

kaidesu commented 9 years ago

I understand where you're coming from. Eventually I do want to add the ability to define multiple locations for this very reason. It would make it so you could store core modules within ./app/Modules and then "addon" modules elsewhere like ./modules for example.

For now though my focus is on ironing out the bugs and getting v1.0 released; so maybe I'll get around to that for v1.1!

illuminate3 commented 9 years ago

I'm glad that I've been bugging you then. I still need to update to latest rev but things have been stable and working great so far. I just need to figure out what to do about the kernel.php right now.

I sent you private email so you can contact me if need any testing or what not.

@addons hmmm, I think you"d be better off with a widget system than over doing the current module system. The other tread got me thinking about packages and modules in more detail and what you have with modules is similar to HMVC which is something that some people did ask for until they gave into packages.

illuminate3 commented 9 years ago

hmmm, this might not be closed ...

    public function boot()
    {
    // Publish a config file
//dd("loaded");
        $this->mergeConfigFrom(
            __DIR__.'/../Config/module_manager.php', 'module_manager.php'
            );

        $this->publishes([
            __DIR__.'/path/to/config/module_manager.php' => config_path('module_manager.php'),
        ]);

        $this->publishes([
            __DIR__.'/../config/module_manager.php', config_path('module_manager.php')
        ], 'config');

    }
vendor:publish --provider="App\Modules\ModuleManager\Providers\ModuleManagerServiceProvider" --tag="config"
vendor:publish --provider="App\Modules\ModuleManager\Providers\ModuleManagerServiceProvider"

Nothing is getting published. The dd does get hit but the commands don't fire.

kaidesu commented 9 years ago

Why do you have two $this->publishes commands firing? Get rid of the first one, and update the path to point to the correct directory in the other; looks like you need to capitalize config.

kaidesu commented 9 years ago

Also the mergeConfigFrom() method needs to go in your provider's register() method. And I believe the second parameter should be the slug of your module.