mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 18:13:01 +08:00
Add 8 new shortcut commands under `lark-cli apps`: Plugin package management (aligned with fullstack-cli): - +plugin-install: download tgz, extract to node_modules, update package.json - +plugin-uninstall: remove from node_modules and package.json actionPlugins - +plugin-list: list declared plugins with installation status Plugin instance CRUD (aligned with feida-ai): - +plugin-instance-create: validate + write capability JSON with formValue validation - +plugin-instance-update: merge mutable fields, re-validate formValue - +plugin-instance-delete: idempotent file removal - +plugin-instance-get: read capability JSON - +plugin-instance-list: scan capabilities directory Shared infrastructure (plugin_common.go): - 4-level capabilities dir resolution (flag → env → .env.local MIAODA_APP_TYPE → detection) - formValue validation ported from feida-ai (5 rules: forbidden Handlebars, paramsSchema type constraints, input ref existence, unconsumed params, array double-wrap auto-fix) - tgz extraction with path traversal protection - package.json actionPlugins management - Install version check with mismatch warnings
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package apps
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/larksuite/cli/internal/output"
|
|
"github.com/larksuite/cli/shortcuts/common"
|
|
)
|
|
|
|
// AppsPluginList lists plugin packages declared in package.json actionPlugins,
|
|
// cross-referencing with node_modules to report installation status.
|
|
var AppsPluginList = common.Shortcut{
|
|
Service: appsService,
|
|
Command: "+plugin-list",
|
|
Description: "List declared plugin packages and their installation status",
|
|
Risk: "read",
|
|
Flags: []common.Flag{
|
|
{Name: "project-path", Desc: "project root path (defaults to current directory)"},
|
|
},
|
|
DryRun: func(ctx context.Context, rctx *common.RuntimeContext) *common.DryRunAPI {
|
|
return common.NewDryRunAPI().
|
|
Desc("List declared plugin packages and installation status").
|
|
Set("action", "list").
|
|
Set("source", "package.json actionPlugins + node_modules")
|
|
},
|
|
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
|
|
projectPath, err := pluginResolveProjectPath(rctx.Str("project-path"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return pluginCheckProjectDir(projectPath)
|
|
},
|
|
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
|
|
projectPath, err := pluginResolveProjectPath(rctx.Str("project-path"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pkg, err := pluginReadPackageJSON(projectPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
declared := pluginGetActionPlugins(pkg)
|
|
plugins := make([]interface{}, 0, len(declared))
|
|
for key, version := range declared {
|
|
installed := pluginInstalledVersion(projectPath, key)
|
|
status := "declared_not_installed"
|
|
if installed != "" {
|
|
status = "installed"
|
|
}
|
|
plugins = append(plugins, map[string]interface{}{
|
|
"key": key,
|
|
"version": version,
|
|
"status": status,
|
|
})
|
|
}
|
|
|
|
data := map[string]interface{}{"plugins": plugins}
|
|
rctx.OutFormat(data, &output.Meta{Count: len(plugins)}, func(w io.Writer) {
|
|
if len(plugins) == 0 {
|
|
fmt.Fprintln(w, "No plugins declared in package.json actionPlugins.")
|
|
return
|
|
}
|
|
rows := make([]map[string]interface{}, 0, len(plugins))
|
|
for _, p := range plugins {
|
|
rows = append(rows, p.(map[string]interface{}))
|
|
}
|
|
output.PrintTable(w, rows)
|
|
})
|
|
return nil
|
|
},
|
|
}
|