diff --git a/package-lock.json b/package-lock.json index 03956c02308..1ec0df70689 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@kui-shell/plugin-git": "file:plugins/plugin-git", "@kui-shell/plugin-iter8": "file:plugins/plugin-iter8", "@kui-shell/plugin-kubectl": "file:plugins/plugin-kubectl", + "@kui-shell/plugin-kubectl-tray-menu": "file:plugins/plugin-kubectl-tray-menu", "@kui-shell/plugin-patternfly4-themes": "file:plugins/plugin-patternfly4-themes", "@kui-shell/plugin-proxy-support": "file:plugins/plugin-proxy-support", "@kui-shell/plugin-s3": "file:plugins/plugin-s3", @@ -787,6 +788,10 @@ "resolved": "plugins/plugin-kubectl", "link": true }, + "node_modules/@kui-shell/plugin-kubectl-tray-menu": { + "resolved": "plugins/plugin-kubectl-tray-menu", + "link": true + }, "node_modules/@kui-shell/plugin-patternfly4-themes": { "resolved": "plugins/plugin-patternfly4-themes", "link": true @@ -19195,6 +19200,50 @@ "uuid": "9.0.0" } }, + "plugins/plugin-kubectl-tray-menu": { + "name": "@kui-shell/plugin-kubectl", + "version": "11.4.0", + "license": "Apache-2.0", + "dependencies": { + "@kui-shell/jsonpath": "1.1.1", + "bytes-iec": "3.1.1", + "command-exists": "1.2.9", + "debug": "4.3.4", + "fs-extra": "10.1.0", + "js-yaml": "4.1.0", + "needle": "3.1.0", + "parse-duration": "1.0.2", + "pluralize": "8.0.0", + "semver": "7.3.7", + "tmp": "0.2.1", + "uuid": "9.0.0" + } + }, + "plugins/plugin-kubectl-tray-menu/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "plugins/plugin-kubectl-tray-menu/node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "plugins/plugin-kubectl/node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -19952,6 +20001,41 @@ } } }, + "@kui-shell/plugin-kubectl-tray-menu": { + "version": "file:plugins/plugin-kubectl-tray-menu", + "requires": { + "@kui-shell/jsonpath": "1.1.1", + "bytes-iec": "3.1.1", + "command-exists": "1.2.9", + "debug": "4.3.4", + "fs-extra": "10.1.0", + "js-yaml": "4.1.0", + "needle": "3.1.0", + "parse-duration": "1.0.2", + "pluralize": "8.0.0", + "semver": "7.3.7", + "tmp": "0.2.1", + "uuid": "9.0.0" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "@kui-shell/plugin-patternfly4-themes": { "version": "file:plugins/plugin-patternfly4-themes" }, diff --git a/package.json b/package.json index 6646e811020..3e098c98837 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "@kui-shell/plugin-git": "file:plugins/plugin-git", "@kui-shell/plugin-iter8": "file:plugins/plugin-iter8", "@kui-shell/plugin-kubectl": "file:plugins/plugin-kubectl", + "@kui-shell/plugin-kubectl-tray-menu": "file:plugins/plugin-kubectl-tray-menu", "@kui-shell/plugin-patternfly4-themes": "file:plugins/plugin-patternfly4-themes", "@kui-shell/plugin-proxy-support": "file:plugins/plugin-proxy-support", "@kui-shell/plugin-s3": "file:plugins/plugin-s3", diff --git a/plugins/plugin-kubectl-tray-menu/.gitignore b/plugins/plugin-kubectl-tray-menu/.gitignore new file mode 100644 index 00000000000..c9d057a334b --- /dev/null +++ b/plugins/plugin-kubectl-tray-menu/.gitignore @@ -0,0 +1,3 @@ +dist +mdist +build \ No newline at end of file diff --git a/plugins/plugin-kubectl-tray-menu/.npmignore b/plugins/plugin-kubectl-tray-menu/.npmignore new file mode 100644 index 00000000000..15a96786b07 --- /dev/null +++ b/plugins/plugin-kubectl-tray-menu/.npmignore @@ -0,0 +1,10 @@ +build +src +tests/data/* +tests/data/k8s/* +!tests/data/k8s/headless/* +dist/test/* +dist/test/k8s2/* +!dist/test/k8s2/headless-create-pod.js +tsconfig* +/*.tgz diff --git a/plugins/plugin-kubectl-tray-menu/package.json b/plugins/plugin-kubectl-tray-menu/package.json new file mode 100644 index 00000000000..547c3162ca0 --- /dev/null +++ b/plugins/plugin-kubectl-tray-menu/package.json @@ -0,0 +1,51 @@ +{ + "name": "@kui-shell/plugin-kubectl", + "version": "11.4.0", + "description": "Kubernetes visualization plugin for kubernetes", + "license": "Apache-2.0", + "keywords": [ + "kubernetes", + "kubectl", + "cli", + "ui", + "kui", + "plugin" + ], + "author": "@starpit", + "contributors": [ + "Mengting Yan" + ], + "homepage": "https://github.com/IBM/kui#readme", + "bugs": { + "url": "https://github.com/IBM/kui/issues/new" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/IBM/kui.git" + }, + "main": "dist/index.js", + "typedocMain": "src/index.ts", + "module": "mdist/index.js", + "types": "mdist/index.d.ts", + "dependencies": { + "@kui-shell/jsonpath": "1.1.1", + "bytes-iec": "3.1.1", + "command-exists": "1.2.9", + "debug": "4.3.4", + "fs-extra": "10.1.0", + "js-yaml": "4.1.0", + "needle": "3.1.0", + "parse-duration": "1.0.2", + "pluralize": "8.0.0", + "semver": "7.3.7", + "tmp": "0.2.1", + "uuid": "9.0.0" + }, + "krew": { + "commandPrefix": "kubeui" + }, + "publishConfig": { + "access": "public" + }, + "gitHead": "89de9f78e8a1a2bdd29d2e17d7c608ab006c6d32" +} diff --git a/plugins/plugin-kubectl/src/@types/images.d.ts b/plugins/plugin-kubectl-tray-menu/src/@types/images.d.ts similarity index 100% rename from plugins/plugin-kubectl/src/@types/images.d.ts rename to plugins/plugin-kubectl-tray-menu/src/@types/images.d.ts diff --git a/plugins/plugin-kubectl/src/electron-main.ts b/plugins/plugin-kubectl-tray-menu/src/electron-main.ts similarity index 100% rename from plugins/plugin-kubectl/src/electron-main.ts rename to plugins/plugin-kubectl-tray-menu/src/electron-main.ts diff --git a/plugins/plugin-kubectl-tray-menu/src/preload.ts b/plugins/plugin-kubectl-tray-menu/src/preload.ts new file mode 100644 index 00000000000..b85524e9902 --- /dev/null +++ b/plugins/plugin-kubectl-tray-menu/src/preload.ts @@ -0,0 +1,27 @@ +/* + * Copyright 2018 The Kubernetes Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Capabilities } from '@kui-shell/core' + +/** + * This is the module + * + */ +export default async function preloadKubectlTrayMenu() { + if (Capabilities.inElectron()) { + import('./tray/init').then(_ => _.default()) + } +} diff --git a/plugins/plugin-kubectl/src/tray/events.ts b/plugins/plugin-kubectl-tray-menu/src/tray/events.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/events.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/events.ts diff --git a/plugins/plugin-kubectl/src/tray/icons.ts b/plugins/plugin-kubectl-tray-menu/src/tray/icons.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/icons.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/icons.ts diff --git a/plugins/plugin-kubectl/src/tray/init.ts b/plugins/plugin-kubectl-tray-menu/src/tray/init.ts similarity index 78% rename from plugins/plugin-kubectl/src/tray/init.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/init.ts index ecc45ced404..7e6b604cca6 100644 --- a/plugins/plugin-kubectl/src/tray/init.ts +++ b/plugins/plugin-kubectl-tray-menu/src/tray/init.ts @@ -25,5 +25,11 @@ export default async function initTray() { .catch(err => { console.error('Error initializing tray menu', err) }) + + // rebroadcast renderer-side config change events to the main process + const { onKubectlConfigChangeEvents } = await import('@kui-shell/plugin-kubectl') + onKubectlConfigChangeEvents(async () => { + import('./events').then(_ => _.emitRefreshFromRenderer()) + }) } } diff --git a/plugins/plugin-kubectl/src/tray/main.ts b/plugins/plugin-kubectl-tray-menu/src/tray/main.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/main.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/main.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/contexts/current.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/contexts/current.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/contexts/current.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/contexts/current.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/contexts/index.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/contexts/index.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/contexts/index.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/contexts/index.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/index.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/index.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/index.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/index.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/loading.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/loading.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/loading.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/loading.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/namespaces/current.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/namespaces/current.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/namespaces/current.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/namespaces/current.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/namespaces/index.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/namespaces/index.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/namespaces/index.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/namespaces/index.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/resources/networking.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/networking.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/resources/networking.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/networking.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/resources/open.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/open.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/resources/open.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/open.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/resources/storage.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/storage.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/resources/storage.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/storage.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/resources/workloads.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/workloads.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/resources/workloads.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/resources/workloads.ts diff --git a/plugins/plugin-kubectl/src/tray/menus/section.ts b/plugins/plugin-kubectl-tray-menu/src/tray/menus/section.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/menus/section.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/menus/section.ts diff --git a/plugins/plugin-kubectl/src/tray/renderer.ts b/plugins/plugin-kubectl-tray-menu/src/tray/renderer.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/renderer.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/renderer.ts diff --git a/plugins/plugin-kubectl/src/tray/update.ts b/plugins/plugin-kubectl-tray-menu/src/tray/update.ts similarity index 100% rename from plugins/plugin-kubectl/src/tray/update.ts rename to plugins/plugin-kubectl-tray-menu/src/tray/update.ts diff --git a/plugins/plugin-kubectl-tray-menu/tsconfig.json b/plugins/plugin-kubectl-tray-menu/tsconfig.json new file mode 100644 index 00000000000..e133dd58f1e --- /dev/null +++ b/plugins/plugin-kubectl-tray-menu/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../node_modules/@kui-shell/builder/tsconfig-base.json", + "include": ["src/**/*"], + "compilerOptions": { + "composite": true, + "outDir": "mdist", + "rootDir": "src", + "baseUrl": "." + } +} diff --git a/plugins/plugin-kubectl/src/controller/kubectl/config.ts b/plugins/plugin-kubectl/src/controller/kubectl/config.ts index dd9d8db027a..1e8f2ba6fe0 100644 --- a/plugins/plugin-kubectl/src/controller/kubectl/config.ts +++ b/plugins/plugin-kubectl/src/controller/kubectl/config.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Arguments, Capabilities, Events, Registrar } from '@kui-shell/core' +import { Arguments, Events, Registrar } from '@kui-shell/core' import flags from './flags' import { doExecWithPty } from './exec' @@ -41,10 +41,6 @@ const mutators = [ export function emitKubectlConfigChangeEvent(type: ConfigChangeEventType, namespace?: string, context?: string) { try { Events.eventChannelUnsafe.emit(kubectlConfigChangeChannel, type, namespace, context) - - if (Capabilities.inElectron()) { - import('../../tray/events').then(_ => _.emitRefreshFromRenderer()) - } } catch (err) { console.error('Error in onKubectlConfigChangeEvent handler', err) } diff --git a/plugins/plugin-kubectl/src/non-headless-preload.ts b/plugins/plugin-kubectl/src/non-headless-preload.ts index 729a2777aad..ca54a6d0df0 100644 --- a/plugins/plugin-kubectl/src/non-headless-preload.ts +++ b/plugins/plugin-kubectl/src/non-headless-preload.ts @@ -17,7 +17,6 @@ import Debug from 'debug' import { PreloadRegistrar } from '@kui-shell/core' -import initTray from './tray/init' import registerPluginTabState from './tab-state' import podMode from './lib/view/modes/pods' import yamlMode from './lib/view/modes/yaml' @@ -44,7 +43,6 @@ import tabCompletionProvider from './lib/tab-completion' import { notebookVFS } from '@kui-shell/plugin-core-support' export default async (registrar: PreloadRegistrar) => { - initTray() registerPluginTabState() // register modes diff --git a/tsconfig.json b/tsconfig.json index ddd9a6fc869..577fc112939 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,9 @@ { "path": "plugins/plugin-kubectl" }, + { + "path": "plugins/plugin-kubectl-tray-menu" + }, { "path": "plugins/plugin-proxy-support" },