shopwarelabs/sw-cli-tools

Shopware 的 CLI 工具集

0.5.3 2023-06-15 08:04 UTC

This package is auto-updated.

Last update: 2024-09-15 10:51:30 UTC


README

Build Status License

Shopware CLI 工具是您在控制台中进行所有类型 Shopware 任务的帮助工具。它们将允许您

  • 从 VCS 设置 Shopware
  • 从发布标签设置 Shopware
  • 创建 Shopware 插件
  • 定义您使用的插件仓库
  • 从仓库安装插件并在 Shopware 中激活它们
  • 以 Shopware 商店或 Shopware 插件管理器期望的方式压缩插件

Shopware CLI 工具附带了一个简洁的扩展接口,因此您可以根据需要扩展它。

这是一个 早期开发预览 - 因此请不要期望它稳定。请在使用此工具进行生产部署之前等待 1.0.0 稳定版本的发布

欢迎提出拉取请求以及可能的扩展想法。

支持

自行承担风险,对此工具没有支持。

安装

我们通常建议使用 sw.phar 发布文件,您可以将它们下载到例如 ~/bin/sw,并将此目录添加到您本地用户的 $PATH(从 http://shopwarelabs.github.io/sw-cli-tools/ 下载当前构建)。

如果您想使用 sw-cli-tools 的开发版本,您应该检出存储库并运行 composer install 下载所有依赖项

需求

在您的系统上至少需要以下软件包可用。

  • openjdk-7-jre-headless
  • ant
  • git
  • curl
  • php7-curl
  • 如果您想使用颜色,您应该在 php.ini 中启用 php.posix

可用命令

  • sw cache:clear
  • sw install:vcs
  • sw install:release
  • sw plugin:install
  • sw plugin:zip:dir
  • sw plugin:zip:vcs
  • sw plugin:create
  • sw generate

使用命令

sw plugin:install

将从配置的仓库之一安装插件

有效的选项/参数有

--useHttp: use HTTP for checkout if possible (e.g. for VPN, SSH seems to be slow here sometimes)
--small: Show 3 columns of plugins in a short form
--shopware-root Shopware root directory
--branch branch to checkout out
names1…nameN - names of plugins to install

如果找到 .idea/vcs.xml,则此命令将自动为 phpstorm 创建 VCS 映射。您需要通过 File->Sychronize (Control+Alt+Y) 刷新您的配置

sw plugin:zip:vcs

将从 VCS 检出插件并正确地压缩以供商店使用

有效的选项/参数有

--useHttp: use HTTP for checkout if possible (e.g. for VPN, SSH seems to be slow here sometimes)
--small: Show 3 columns of plugins in a short form
--branch branch to checkout out
names1…nameN - names of plugins to zip

如果插件根目录中有一个名为 .sw-zip-blacklist 的文件,则该文件中描述的文件/目录将不会被压缩

sw plugin:zip:dir

将压缩指定的插件目录。DIRECTORY 必须指向插件引导文件所在的目录。

sw install:vcs

从 vcs 检出最新的 Shopware 版本(用于开发)

有效的选项/参数有

--branch: The branch to checkout
--databaseName: Name of the database to use
--installDir: Where to install shopware
--user: Github user name. If provided, the checkout will be done via HTTP

如果未提供,则将交互式地读取选项。数据库凭证配置在 ~/.config/sw-cli-tools/config.yaml 中

sw install:release

--release=RELEASE                Release version. Default: Latest. Possible are all shopware release versions like "4.2.0"
--install-dir[=INSTALL-DIR]      Install directory
--unpack-only                    Only unpack the downloaded release
--skip-download                  Skip release downloading
--db-host=DB-HOST                Database host [default: "localhost"]
--db-port=DB-PORT                Database port [default: "3306"]
--db-socket=DB-SOCKET            Database socket
--db-user=DB-USER                Database user
--db-password=DB-PASSWORD        Database password
--db-name=DB-NAME                Database name
--shop-locale=SHOP-LOCALE        Shop locale [default: "de_DE"]
--shop-host=SHOP-HOST            Shop host [default: "localhost"]
--shop-path=SHOP-PATH            Shop path [default: "/"]
--shop-name=SHOP-NAME            Shop name [default: "Demo shop"]
--shop-email=SHOP-EMAIL          Shop email address [default: "your.email@shop.com"]
--shop-currency=SHOP-CURRENCY    Shop currency [default: "EUR"]
--admin-username=ADMIN-USERNAME  Administrator username [default: "demo"]
--admin-password=ADMIN-PASSWORD  Administrator password [default: "demo"]
--admin-email=ADMIN-EMAIL        Administrator email address [default: "demo@demo.demo"]
--admin-locale=ADMIN-LOCALE      Administrator locale [default: "de_DE"]
--admin-name=ADMIN-NAME          Administrator name [default: "Demo user"]

sw plugin:create

将创建一个带有所有样板代码的 Shopware 插件。如果命令将在 Shopware 根目录中执行,则插件将放置在插件文件夹中,否则它将在同一目录中创建。

有效的选项/参数有

--legacy: Create a legacy Plugin for Shopware versions lower than 5.2
--namespace[="..."]: Namespace of the plugin, default: Frontend
--haveBackend: Generate a backend Controller + a simple ExtJS module
--backendModel[="..."]: The name of the model for your backend application
--haveFilter: Generate Condition/Facet/CriteriaRequestHandler in order to add a new filter in the frontend
--haveFrontend | -f: Generate a frontend controller
--haveModels | -m: Generate a simple doctrine model
--haveCommands | -c: Generate a console command
--haveWidget | -w: Generate a backend widget
--haveApi | -a: Generate an API resource + REST controller
--licenseHeader[="/home/user/license.txt"]: Include a license header file at the beginning of any file name: Name of your plugin. Must at least have a dev prefix + plugin name, e.g. "SwagBundle", "PrefixPluginName"; "SwagBrowserLanguageDetection"
--haveElasticSearch | -e: Generate ElasticSearch blueprint classes and an example of a decorator for the product number search.

如果未提供,则将交互式地读取选项。数据库凭证配置在 ~/.config/sw-cli-tools/config.yaml 中

sw generate

将生成可以用于填充商店的数据,例如用于负载测试。

!警告! 此命令具有破坏性

有效的选项/参数有

 -a, --articles[=ARTICLES]                          Number of articles to create
     --articleFilterGroups[=ARTICLEFILTERGROUPS]    Number article filter option groups to create
     --articleFilterOptions[=ARTICLEFILTEROPTIONS]  Number article filter options to create
     --articleFilterValues[=ARTICLEFILTERVALUES]    Number article filter values to create per each filter option
 -o, --orders[=ORDERS]                              Number of orders to create
 -c, --categories[=CATEGORIES]                      Number of categories to create
     --categoriesPerArticle[=CATEGORIESPERARTICLE]  Number of categories to assign to each article
 -e, --newsletter[=NEWSLETTER]                      Number of newsletter to create
 -u, --customers[=CUSTOMERS]                        Number of customers to create
     --vouchers[=VOUCHERS]                          Number of vouchers to create
     --chunk-size[=CHUNK-SIZE]                      Chung size
 -s, --seed[=SEED]                                  Random seed
     --installDir[=INSTALLDIR]                      Your Shopware installation path. If provided, data will be automatically injected into the configured database. [default: ""]
 -n, --no-interaction                               Do not ask any interactive question

如果从 Shopware 安装执行或提供 'installDir',则数据将自动写入您的 Shopware 数据库。否则,数据将导出到 '\output' 文件夹中的单个文件中。您需要按生成的顺序导入 .sql 文件(请参阅命令输出)

需要 MySQL 安装中的 'local-infile=1'。

扩展 cli 工具

新扩展

扩展在 /home/USER/.config/sw-cli-tools/extensions 文件夹中创建,包括供应商文件夹、扩展文件夹(包含扩展名称)和扩展文件夹内的 Bootstrap.php 文件。此外,您还可以在扩展文件夹内提供自己的 config.yaml 文件,该文件将扩展默认的 config.yaml 文件。

您的扩展引导的命名空间应该是 VENDOR_FOLDER\EXTENSION_FOLDER\Bootstrap

引导

引导是您扩展的主要入口点。如果它实现了 ContainerAwareExtension,它将通过 setContainer 注入应用程序的容器构建器。这样,容器就可以通过您的扩展进行扩展。此外,引导还可以实现 ConsoleAwareExtension。如果是这种情况,将在创建后调用 "getConsoleCommands" 方法 - 请在此处返回一个控制台命令实例数组。最后,扩展将调用实现 RepositoryAwareInterface 的扩展的 getRepositories 方法。

修改现有组件

由于您的 Bootstrap.php 是在容器之后实例化的,因此您可以替换容器中的任何服务。

路径

SW cli 工具使用了 XDG 目录标准。以下目录被使用:

~/.config/sw-cli-tools: Here the main configuration as well as the extensions are stored
~/.cache/sw-cli-tools: Here caches (like repo content) as well as release downloads are cached
~/.local/share/sw-cli-tools: Assets the demo data package are stored here

如果您通过 XDG 环境变量更改了这些目录,则将使用这些目录。

配置

脚本的配置是在 ~/.config/sw-cli-tools/config.yaml 中完成的。如果您的系统中不存在该文件,它将在脚本第一次使用后创建。

存储库

为了使用像 plugin:zip:vcs 这样的命令,该工具需要知道来源在哪里。为此,需要在配置文件的 repositories 部分中定义存储库。目前支持的存储库类型如下:

  • GitHub
  • Stash
  • BitBucket
  • SimpleList
  • GitLab

以下是一个示例配置可能看起来像这样:

repositories:
  GitLab:
    config:
      endpoint: https://gitlab.shopware.com/api/v4/
    repositories:
      Services SW5:
        cache: 86400
        url: groups/92/projects?per_page=100&private_token=your-private-token
        color: red
  GitHub:
    config:
      endpoint: https://api.github.com/search/
    repositories:
      Plugins SW5:
        cache: 86400
        url: repositories?q=org:Shopware5+topic:shopware-plugin
        color: blue

构建 sw.phar

为了构建发布包(sw.phar),使用了 box。每次在 master 分支上推送新版本时,Travis CI 都会自动构建一个新版本(参见 bin/deploy.sh)。

编码标准

项目的编码标准是 PSR-2。可以使用 php-cs-fixer 检测编码标准违规。

./vendor/bin/php-cs-fixer fix -v --level=psr2 ./src
./vendor/bin/php-cs-fixer fix -v --level=psr2 ./tests

一般提示

超时

如果您有缓慢的互联网连接,并且例如 git checkouts 或与 ProcessExecutor 相关的任务因超时而失败,您可以通过设置环境变量 SW_TIMEOUT 来增加超时时间。

SW_TIMEOUT=500 sw install:vcs