PrestaShopCorp / module-lib-mbo-installer

A helper to ease the download and unzip of modules from the Addons Marketplace
Open Software License 3.0
3 stars 2 forks source link

:sparkles: Adding DependencyBuilder #5

Closed intraordinaire closed 10 months ago

intraordinaire commented 1 year ago

In order to correctly build the dependencies variable to instantiate the CDC, add an helper to ease the work of module devs.

So, we have to add a module_dependencies.json file in the root dir of the module.

{
    "dependencies": [
      {
        "name" : "ps_accounts"
      },
      {
        "name" : "ps_eventbus"
      }
    ]
}

And then, in the module :

$mboInstaller = new Prestashop\ModuleLibMboInstaller\DependencyBuilder($this);
$requiredDependencies = $mboInstaller->handleDependencies();
return $twig->render('mytpl.html.twig', [
    'requiredDependencies' => $requiredDependencies,
]);

And later, in the tpl

<!-- Load cdc library -->
<script src="http://127.0.0.1:5173/dist/mbo-cdc-dependencies-resolver.umd.js"></script>

<!-- cdc container -->
<div id="cdc-container"></div>

<script defer>
  const renderMboCdcDependencyResolver = window.mboCdcDependencyResolver.render
  const context = {
    ...{$requiredDependencies|json_encode},
    // Optional callbacks to handle the display of the page
    onDependenciesResolved: () => console.log('Everything works!'),
    onDependencyResolved: (dependencyData) => console.log('Dependency installed', dependencyData),
    onDependencyFailed: (dependencyData) => console.log('Failed to install dependency', dependencyData),
    onDependenciesFailed: () => console.log('There are some errors'),
  }
  renderMboCdcDependencyResolver(context, '#cdc-container')
</script>

Here you will find a module (compatible from 1.7.0) in order to test/try it : prestashopexamplemodule.zip

UPDATED 27/11/2023

Go to the config page, and you will see something like this :

image
julienr114 commented 1 year ago

Hi, I remade the zip by including a first version of the cdc in the configuration page of the example module. prestashopexamplemodule.zip EDIT 23/10/2023 : Pick the one in the description

if you go on config page you should show something like this

Capture d’écran 2023-03-07 à 10 25 31
intraordinaire commented 1 year ago

You can find an updated example module version here prestashopexamplemodule.zip EDIT 23/10/2023 : Pick the one in the description

The ID have been added to the dependencies file in order to be able to correctly retrieve last available version & module name.

prestamodule commented 11 months ago

Hi,

Could a method like checkDependencies be added to the DependencyBuilder class, returning a simple boolean, allowing module developers to check if all dependencies are already installed instead of having to parse the return of handleDependencies?

Thanks!

intraordinaire commented 11 months ago

@prestamodule Thanks for your feedback ! Indeed, it's a good idea and it will ease the development.

prestamodule commented 11 months ago

Are there any plans to let module developers customize this dependencies installation page (like Billing allows for customization of some elements of the UI)? Or expose some methods to let them build the routes themselves and take over the entire process? I think this would allow developers to better integrate this new process with their brand/module identity

intraordinaire commented 11 months ago

@prestamodule It's the idea, yes. You could take the dependencies object and choose to display a page yourself, or deal with it as you want. We will add a documentation with the structure of the data, and the correct routes you should call to launch the installation process.

So it will be up to each dev to choose. Use the "all in one" solution, or build a custom one.