mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove extension-store for now
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
3e65e07575
commit
ecd5cbe76a
@ -1,7 +1,6 @@
|
||||
import type { ExtensionId, LensExtension, ExtensionManifest } from "./lens-extension"
|
||||
import type { ExtensionId, LensExtension, ExtensionManifest, ExtensionModel } from "./lens-extension"
|
||||
import { broadcastIpc } from "../common/ipc"
|
||||
import type { LensRuntimeRendererEnv } from "./lens-runtime"
|
||||
import { ExtensionModel } from "./extension-store"
|
||||
import path from "path"
|
||||
import { observable, reaction, toJS, } from "mobx"
|
||||
import logger from "../main/logger"
|
||||
@ -20,7 +19,7 @@ export function extensionPackagesRoot() {
|
||||
export function withExtensionPackagesRoot(callback: Function) {
|
||||
const cwd = process.cwd()
|
||||
try {
|
||||
process.chdir(path.resolve(extensionPackagesRoot()))
|
||||
process.chdir(extensionPackagesRoot())
|
||||
return callback()
|
||||
} finally {
|
||||
process.chdir(cwd)
|
||||
@ -44,14 +43,14 @@ export class ExtensionLoader {
|
||||
}
|
||||
|
||||
autoEnableOnLoad(getLensRuntimeEnv: () => LensRuntimeRendererEnv, { delay = 0 } = {}) {
|
||||
logger.info('[EXTENSIONS-MANAGER]: auto-activation loaded extensions: ON');
|
||||
logger.info('[EXTENSIONS-LOADER]: auto-activation loaded extensions: ON');
|
||||
return reaction(() => this.extensions.toJS(), installedExtensions => {
|
||||
installedExtensions.forEach((ext) => {
|
||||
let instance = this.instances.get(ext.manifestPath)
|
||||
if (!instance) {
|
||||
const extensionModule = this.requireExtension(ext)
|
||||
if (!extensionModule) {
|
||||
logger.error("[EXTENSION-MANAGER] failed to load extension " + ext.manifestPath)
|
||||
logger.error("[EXTENSION-LOADER] failed to load extension " + ext.manifestPath)
|
||||
return
|
||||
}
|
||||
const LensExtensionClass = extensionModule.default;
|
||||
@ -72,7 +71,7 @@ export class ExtensionLoader {
|
||||
const extMain = path.join(path.dirname(extension.manifestPath), extension.manifest.main)
|
||||
return __non_webpack_require__(extMain)
|
||||
} catch (err) {
|
||||
console.error(`[EXTENSION-MANAGER]: can't load extension main at ${extension.manifestPath}: ${err}`, { extension });
|
||||
console.error(`[EXTENSION-LOADER]: can't load extension main at ${extension.manifestPath}: ${err}`, { extension });
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -17,15 +17,14 @@ export class ExtensionManager {
|
||||
async load() {
|
||||
logger.info("[EXTENSION-MANAGER] loading extensions from " + this.extensionPackagesRoot)
|
||||
|
||||
fs.ensureDir(path.join(this.extensionPackagesRoot, "node_modules"))
|
||||
fs.writeFileSync(path.join(this.extensionPackagesRoot, "package.json"), `{"dependencies": []}`, {mode: 0o600})
|
||||
await fs.ensureDir(path.join(this.extensionPackagesRoot, "node_modules"))
|
||||
await fs.writeFile(path.join(this.extensionPackagesRoot, "package.json"), `{"dependencies": []}`, {mode: 0o600})
|
||||
|
||||
return await this.loadExtensions();
|
||||
}
|
||||
|
||||
async getExtensionByManifest(manifestPath: string): Promise<InstalledExtension> {
|
||||
let manifestJson: ExtensionManifest;
|
||||
let mainJs: string;
|
||||
try {
|
||||
manifestJson = __non_webpack_require__(manifestPath)
|
||||
withExtensionPackagesRoot(() => {
|
||||
@ -41,7 +40,7 @@ export class ExtensionManager {
|
||||
manifest: manifestJson
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`[EXTENSION-MANAGER]: can't install extension at ${manifestPath}: ${err}`, { manifestJson, mainJs });
|
||||
logger.error(`[EXTENSION-MANAGER]: can't install extension at ${manifestPath}: ${err}`, { manifestJson });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
import type { ExtensionId, ExtensionManifest, ExtensionVersion, LensExtension } from "./lens-extension";
|
||||
import { observable, toJS, } from "mobx";
|
||||
import { BaseStore } from "../common/base-store";
|
||||
|
||||
export interface ExtensionStoreModel {
|
||||
extensions: [ExtensionId, ExtensionModel][]
|
||||
}
|
||||
|
||||
export interface ExtensionModel {
|
||||
id: ExtensionId;
|
||||
version: ExtensionVersion;
|
||||
name: string;
|
||||
manifestPath: string;
|
||||
description?: string;
|
||||
enabled?: boolean;
|
||||
updateUrl?: string;
|
||||
}
|
||||
|
||||
export interface InstalledExtension<T extends ExtensionModel = any> {
|
||||
manifestPath: string;
|
||||
manifest: ExtensionManifest;
|
||||
extensionModule: {
|
||||
[name: string]: any;
|
||||
default: new (model: ExtensionModel, manifest?: ExtensionManifest) => LensExtension
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtensionStore extends BaseStore<ExtensionStoreModel> {
|
||||
private constructor() {
|
||||
super({
|
||||
configName: "lens-extension-store",
|
||||
});
|
||||
}
|
||||
|
||||
@observable extensions = observable.map<ExtensionId, LensExtension>();
|
||||
|
||||
getById(id: ExtensionId): LensExtension {
|
||||
return this.extensions.get(id);
|
||||
}
|
||||
|
||||
async removeById(id: ExtensionId) {
|
||||
const extension = this.getById(id);
|
||||
if (extension) {
|
||||
await extension.uninstall();
|
||||
this.extensions.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(): ExtensionStoreModel {
|
||||
return toJS({
|
||||
extensions: Array.from(this.extensions).map(([id, instance]) => [id, instance.toJSON()]),
|
||||
}, {
|
||||
recurseEverything: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const extensionStore = ExtensionStore.getInstance<ExtensionStore>()
|
||||
@ -1,4 +1,3 @@
|
||||
import type { ExtensionModel } from "./extension-store";
|
||||
import type { LensRuntimeRendererEnv } from "./lens-runtime";
|
||||
import type { PageRegistration } from "./register-page";
|
||||
import { readJsonSync } from "fs-extra";
|
||||
@ -9,6 +8,16 @@ export type ExtensionId = string | ExtensionPackageJsonPath;
|
||||
export type ExtensionPackageJsonPath = string;
|
||||
export type ExtensionVersion = string | number;
|
||||
|
||||
export interface ExtensionModel {
|
||||
id: ExtensionId;
|
||||
version: ExtensionVersion;
|
||||
name: string;
|
||||
manifestPath: string;
|
||||
description?: string;
|
||||
enabled?: boolean;
|
||||
updateUrl?: string;
|
||||
}
|
||||
|
||||
export interface ExtensionManifest extends ExtensionModel {
|
||||
main: string;
|
||||
description?: string; // todo: add more fields similar to package.json + some extra
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
import { RouteProps } from "react-router";
|
||||
import { buildURL } from "../../navigation";
|
||||
|
||||
export const extensionsRoute: RouteProps = {
|
||||
path: "/extensions"
|
||||
}
|
||||
|
||||
export interface IExtensionsRouteParams {
|
||||
}
|
||||
|
||||
export const extensionsURL = buildURL<IExtensionsRouteParams>(extensionsRoute.path);
|
||||
@ -1,4 +0,0 @@
|
||||
.Extensions {
|
||||
$spacing: $padding * 2;
|
||||
padding: $spacing;
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
import "./extensions.scss"
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { extensionStore } from "../../../extensions/extension-store";
|
||||
import { WizardLayout } from "../layout/wizard-layout";
|
||||
import { Icon } from "../icon";
|
||||
|
||||
@observer
|
||||
export class Extensions extends React.Component {
|
||||
// todo: add input-select to customize extensions loading folder(s)
|
||||
renderInfoPanel() {
|
||||
return (
|
||||
<div className="info-panel flex gaps align-center">
|
||||
<Icon material="info"/>
|
||||
<p>Extensions available to install</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { extensions } = extensionStore;
|
||||
return (
|
||||
<WizardLayout className="Extensions" infoPanel={this.renderInfoPanel()}>
|
||||
<h2>Extensions</h2>
|
||||
<pre>
|
||||
{JSON.stringify(extensions.toJSON(), null, 2)}
|
||||
</pre>
|
||||
</WizardLayout>
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
export * from "./extensions.route"
|
||||
export * from "./extensions"
|
||||
@ -11,7 +11,6 @@ import { Workspaces, workspacesRoute } from "../+workspaces";
|
||||
import { AddCluster, addClusterRoute } from "../+add-cluster";
|
||||
import { ClusterView } from "./cluster-view";
|
||||
import { ClusterSettings, clusterSettingsRoute } from "../+cluster-settings";
|
||||
import { Extensions, extensionsRoute } from "../+extensions";
|
||||
import { clusterViewRoute, clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
|
||||
import { clusterStore } from "../../../common/cluster-store";
|
||||
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
|
||||
@ -64,7 +63,6 @@ export class ClusterManager extends React.Component {
|
||||
<Route component={AddCluster} {...addClusterRoute} />
|
||||
<Route component={ClusterView} {...clusterViewRoute} />
|
||||
<Route component={ClusterSettings} {...clusterSettingsRoute} />
|
||||
<Route component={Extensions} {...extensionsRoute}/>
|
||||
{dynamicPages.globalPages.map(({ path, components: { Page } }) => {
|
||||
return <Route key={path} path={path} component={Page}/>
|
||||
})}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user