lukaskleinschmidt/kirby-terminal

1.0.1 2020-12-03 13:16 UTC

This package is auto-updated.

Last update: 2024-08-28 16:23:42 UTC


README

从面板管理后台进程。定义脚本,就像您可能已经熟悉从 npm 中那样。启动或停止预定义的脚本,并在面板中直接监控输出。

Terminal Preview

商业用途

此插件免费。如果您在商业项目中使用它,请考虑捐赠

安装

下载

下载并将此存储库复制到 /site/plugins/terminal

Git 子模块

git submodule add https://github.com/lukaskleinschmidt/kirby-terminal.git site/plugins/terminal

Composer

composer require lukaskleinschmidt/kirby-terminal

定义脚本

您能够运行几乎任何您通常在终端中运行的脚本或命令。脚本可以定义为一个简单的字符串,或者如果您需要更多控制,您可以将脚本定义为一个回调。预期的回调返回一个 string 或一个 Script 对象。回调的闭包绑定到脚本部分模型。

<?php

return [
    'lukaskleinschmidt.terminal.scripts' => [
        'hello-world' => 'echo "Hello World!"',
        'list-index' => function () {
            return 'ls';
        },
        'list-content' => function () {
            $cwd = $this->kirby()->root('content') . '/' . $this->diruri();

            // Set the current working directory for the script
            return script('ls', $cwd);
        },
    ]
];

为了更好地了解可能实现的功能,您可以将这三个脚本添加到您的配置中,并将它们简单地放入 sitepage 蓝图。

sections:
  hello-world:
    type: terminal
    script: hello-world

  list-index:
    type: terminal
    script: list-index

  list-content:
    type: terminal
    script: list-content

示例 deploy 脚本适用于 sitepage 蓝图。在 site 蓝图中使用它将部署整个内容文件夹。在 page 蓝图中使用它将仅部署页面及其对应的子树。

<?php

return [
    'lukaskleinschmidt.terminal.scripts' => [
        'deploy' => function () {
            $source = $this->kirby()->root('content') . '/\./' . $this->diruri();
            $target = 'shh_user@example.com:/var/www/html/content';

            // If you are not 100% certain you have the right path on the remote
            // server then test this command without the --delete flag first
            return "rsync --delete --relative -avz $source $target";
        }
    ]
];

权限

您可能希望限制对某些脚本的访问。您可以通过将门回调添加到您的配置文件中来实现这一点。预期的回调返回 truefalse。在回调内部,您有权访问已认证的用户。此外,闭包绑定到部分对象,允许您做出更细致的决策。以下两个示例将帮助您入门。

<?php

return [
    'lukaskleinschmidt.terminal.gate' => function ($user) {
        return in_array($user->email(), [
            'user@example.com'
        ]);
    }
];
<?php

return [
    'lukaskleinschmidt.terminal.gate' => function ($user) {
        $permissions = [
            'user@example.com' => ['deploy']
        ];

        return in_array($this->script(), $permissions[$user->email()] ?? []);
    }
];

如果您想要禁用特定环境的所有脚本,请将门设置为 false

<?php
// config.example.com.php

return [
    'lukaskleinschmidt.terminal.gate' => false,
];

端点

如果您遇到任何冲突,您可以更改使用的 API 端点。

<?php

return [
    'lukaskleinschmidt.terminal.endpoint' => 'custom-terminal-endpoint'
];

蓝图

sections:
  terminal:
    headline: Terminal
    type: terminal
    script: deploy

可用选项

确认对话框

# Basic confirmation dialog
confirm: Are you sure you are ready for this?

# Advanced confirmation dialog
confirm:
  button: So ready
  icon: wand
  size: medium
  theme: positive
  text: Are you sure you are ready for this?

多语言

您可以提供 headlinehelpstartstopconfirm 属性的多语言翻译。如果您使用高级确认对话框,您还可以提供 buttontext 属性的翻译。

confirm:
  en: Are you sure you are ready for this?
  de: Bist du sicher, dass du bereit bist?

许可协议

MIT

致谢