@korodrogerie/update-koro-plugin
v1.3.0
Published
Updates Koro Plugins with Github Actions
Downloads
14
Readme
Update KoRo plugin CLI
Automatically updates a KoRo Shopware 6 plugin. Updates may include GitHub Actions pipelines to unifiy our workflows throughout the plugins we're using.
Usage
npx @korodrogerie/update-koro-plugin <plugin-name>
Advanced usage
The CLI script has an additional optional parameter which allows providing the package name which should be installed.
In this case the CLI script just installs the selected package.
npx @korodrogerie/update-koro-plugin <plugin-name> --package <package-name>
Packages
The CLI scripts is using a package approach to update KoRo plugins. Inside the directory packages
you're finding a packages.json
meta data file which defines the name of the package, the path to it and additionally Bash commands which will be executed after the files were copied over.
A typical package inside the packages.json
has the following syntax:
[{
"name": "My package name",
"path": "path/to/your/package",
"install": [
"echo 'Installation complete'"
]
}]
Template files inside packages
This tool supports template file (e.g. file extension is .hbs
, Handlebar template). This is a useful approach when you need to dynamically set certain values inside your files to the plugin name for example. The template files are getting the following installation context:
const installContext = {
root,
pluginName,
packageName,
pluginNameSnakeCase: camelToSnakeCase(pluginName)
}
Here's an example on how a package.json.hbs
file can look like as an example:
{
"private": true,
"name": "{{pluginNameSnakeCase}}",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "git+https://github.com/KoRoHandelsGmbH/{{pluginName}}.git"
},
"bugs": {
"url": "https://github.com/KoRoHandelsGmbH/{{pluginName}}/issues"
},
"homepage": "https://github.com/KoRoHandelsGmbH/{{pluginName}}#readme"
}
Patch files
With the support of git patches, we can also apply patches to certain files to change their content. It is especially useful for files which are already exist and you need to insert certain information to it.
Here's the workflow on how to create a patch file.
- Do your changes to the files in a package you wanna change
- Run
git diff > my-changes.patch
- Rename file from
my-changes.patch
tomy-changes.patch.hbs
- Open
my-changes.patch.hbs
and remove any absolute paths with relative ones - If template variables are used for certain terms for example the plugin name, please replace them with the corresponding variable which should be available in the installation context mentioned above.
When you're running the update-koro-plugin
scriupt it automatically picks up the patch file, renders the Handlebars template and applies the patch to the plugin.
How it works under the hood
To render the files this CLI script copies the files in a temporarily directory (inside /tmp/
), Handlebars renders the file content and writes back the content inside the temporarily directory. Next up the file gets renamed to its original name and gets copied to its destination path within the plugin. Last but not least the previously created temporarily directory will be removed.
Each package including their Bash commands will be installed installed and executed independently. Please note here that this CLI scripts is working with overrides which means if you want to update a certain file you have to provide the content from previous packages. Another way around this restriction is using Bash commands to add additional content to certain files.
License
Licensed under MIT
Copyright (c) 2020-present KoRo Handels GmbH