Laravel-modules: Module composer.json require-dev and scripts

Created on 12 Mar 2017  路  7Comments  路  Source: nWidart/laravel-modules

I didn't found a way to add dev packages and scripts to the main composer.json from the module composer.json, isn't there the possibility yet?
Would you accept a PR with this? Something like this

Thanks.

Most helpful comment

This is now on dev-master as well. Has to change your code a bit so it'd work if the script title wasn't present in the main composer.json file.

All 7 comments

Hello,

That looks decent indeed. One thing it doesn't do is add that packages to the main composer.json file as the require key does. That might be something good to have as well.

I just added this on dev-master. Feel free to test it out. 馃憤

This has now been tagged.

Thanks :)

What about the scripts?

//scripts
$scripts = $module->getComposerAttr('scripts', []);
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
foreach ($scripts as $key => $script):
    $composer['scripts'][$key] = array_unique(array_merge($composer['scripts'][$key], $script));
endforeach;
file_put_contents(base_path('composer.json'), json_encode($composer, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));

I don't know if my approach is the best way to do this but it's working.

For example, i have a dev module where i add all dev packages that i need. When i install the dev module i want to install the dev packages and update the scripts from the main composer.

For example:

Update

"scripts":{
"post-update-cmd": [
    "Illuminate\\Foundation\\ComposerScripts::postUpdate",
    "php artisan optimize"
    ]
},

With

"scripts":{
"post-update-cmd": [
    "Illuminate\\Foundation\\ComposerScripts::postUpdate",
    "php artisan ide-helper:generate",
    "php artisan ide-helper:meta",
    "php artisan optimize"
    ]
},

Oh, you're right, I missed that part. I'll try to implement this asap.

This is now on dev-master as well. Has to change your code a bit so it'd work if the script title wasn't present in the main composer.json file.

Thanks :). Will test soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dagulo picture dagulo  路  3Comments

sandeepk2304 picture sandeepk2304  路  3Comments

developh picture developh  路  3Comments

dang-tien picture dang-tien  路  3Comments

quentingosset picture quentingosset  路  4Comments