mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
allow to import open-lens
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
5048850fb4
commit
fa66e356bf
11
package.json
11
package.json
@ -5,6 +5,15 @@
|
||||
"homepage": "https://github.com/lensapp/lens",
|
||||
"version": "6.3.0-alpha.0",
|
||||
"main": "static/build/main.js",
|
||||
"exports": {
|
||||
".": "./static/build/library/library.js"
|
||||
},
|
||||
"files": [
|
||||
"static/**/*",
|
||||
"!static/build/main.*",
|
||||
"build/**/*",
|
||||
"templates/**/*"
|
||||
],
|
||||
"copyright": "© 2022 OpenLens Authors",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
@ -22,12 +31,12 @@
|
||||
"dev-run": "nodemon --watch ./static/build/main.js --exec \"electron --remote-debugging-port=9223 --inspect .\"",
|
||||
"dev:main": "yarn run compile:main --watch --progress",
|
||||
"dev:renderer": "yarn run ts-node webpack/dev-server.ts",
|
||||
"compile-library": "env NODE_ENV=production yarn run webpack --config webpack/library.ts",
|
||||
"compile": "env NODE_ENV=production concurrently yarn:compile:*",
|
||||
"compile:main": "yarn run webpack --config webpack/main.ts",
|
||||
"compile:renderer": "yarn run webpack --config webpack/renderer.ts",
|
||||
"compile:extension-types": "yarn run webpack --config webpack/extensions.ts",
|
||||
"compile:node-fetch": "yarn run webpack --config ./webpack/node-fetch.ts",
|
||||
"postinstall": "yarn run compile:node-fetch",
|
||||
"npm:fix-package-version": "yarn run ts-node build/set_npm_version.ts",
|
||||
"build:linux": "yarn run compile && electron-builder --linux --dir",
|
||||
"build:mac": "yarn run compile && electron-builder --mac --dir",
|
||||
|
||||
35
src/library.ts
Normal file
35
src/library.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import staticFilesDirectoryInjectable from "./common/vars/static-files-directory.injectable";
|
||||
import { registerInjectables } from "./main/register-injectables";
|
||||
import { afterApplicationIsLoadedInjectionToken } from "./main/start-main-application/runnable-tokens/after-application-is-loaded-injection-token";
|
||||
import { beforeApplicationIsLoadingInjectionToken } from "./main/start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||
import { beforeElectronIsReadyInjectionToken } from "./main/start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
|
||||
import { onLoadOfApplicationInjectionToken } from "./main/start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||
import startMainApplicationInjectable from "./main/start-main-application/start-main-application.injectable";
|
||||
|
||||
interface AppConfig {
|
||||
di: DiContainer;
|
||||
staticPath: string;
|
||||
}
|
||||
|
||||
function startApp(conf: AppConfig) {
|
||||
const { di, staticPath } = conf;
|
||||
|
||||
di.override(staticFilesDirectoryInjectable, () => staticPath);
|
||||
|
||||
return di.inject(startMainApplicationInjectable);
|
||||
}
|
||||
|
||||
export {
|
||||
registerInjectables,
|
||||
startApp,
|
||||
afterApplicationIsLoadedInjectionToken,
|
||||
beforeApplicationIsLoadingInjectionToken,
|
||||
beforeElectronIsReadyInjectionToken,
|
||||
onLoadOfApplicationInjectionToken,
|
||||
};
|
||||
@ -3,29 +3,10 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { createContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { registerInjectables } from "./register-injectables";
|
||||
|
||||
export const getDi = () => {
|
||||
const di = createContainer("main");
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.main);
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
requireContexts: [
|
||||
require.context("./", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../extensions", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../common", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../features", true, CONTEXT_MATCHER_FOR_FEATURES),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return di;
|
||||
return registerInjectables(di);
|
||||
};
|
||||
|
||||
29
src/main/register-injectables.ts
Normal file
29
src/main/register-injectables.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
|
||||
export function registerInjectables(di: DiContainer) {
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.main);
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
requireContexts: [
|
||||
require.context("./", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../extensions", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../common", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../features", true, CONTEXT_MATCHER_FOR_FEATURES),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return di;
|
||||
}
|
||||
116
webpack/library.ts
Normal file
116
webpack/library.ts
Normal file
@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import path from "path";
|
||||
import type webpack from "webpack";
|
||||
import { DefinePlugin } from "webpack";
|
||||
import nodeExternals from "webpack-node-externals";
|
||||
import getTypeScriptLoader from "./get-typescript-loader";
|
||||
import rendererConfig, { iconsAndImagesWebpackRules } from "./renderer";
|
||||
import { buildDir, isDevelopment, mainDir } from "./vars";
|
||||
import { platform } from "process";
|
||||
|
||||
const configs: { (): webpack.Configuration }[] = [
|
||||
rendererConfig,
|
||||
];
|
||||
|
||||
configs.push((): webpack.Configuration => {
|
||||
console.info("WEBPACK:library", {
|
||||
isDevelopment,
|
||||
buildDir,
|
||||
});
|
||||
|
||||
return {
|
||||
name: "lens-app-library",
|
||||
context: __dirname,
|
||||
target: "electron-main",
|
||||
mode: isDevelopment ? "development" : "production",
|
||||
devtool: isDevelopment ? "cheap-module-source-map" : "source-map",
|
||||
cache: isDevelopment ? { type: "filesystem" } : false,
|
||||
entry: {
|
||||
library: path.resolve(mainDir, "..", "library.ts"),
|
||||
},
|
||||
output: {
|
||||
path: path.join(buildDir, "library"),
|
||||
library: {
|
||||
type: "commonjs",
|
||||
},
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".json", ".js", ".ts"],
|
||||
},
|
||||
externals: [
|
||||
nodeExternals(),
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: "node-loader",
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: "ts-loader",
|
||||
options: {
|
||||
compilerOptions: {
|
||||
declaration: true, // output .d.ts
|
||||
sourceMap: false, // to override sourceMap: true in tsconfig.json
|
||||
outDir: path.join(buildDir, "library"),
|
||||
},
|
||||
},
|
||||
},
|
||||
...iconsAndImagesWebpackRules(),
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new DefinePlugin({
|
||||
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||
CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||
}),
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
configs.push((): webpack.Configuration => {
|
||||
console.info("WEBPACK:library:download-binaries", {
|
||||
isDevelopment,
|
||||
buildDir,
|
||||
});
|
||||
|
||||
return {
|
||||
name: "lens-app-library-download-binaries",
|
||||
context: __dirname,
|
||||
target: "electron-main",
|
||||
mode: isDevelopment ? "development" : "production",
|
||||
devtool: false,
|
||||
cache: isDevelopment ? { type: "filesystem" } : false,
|
||||
entry: {
|
||||
download_binaries: path.resolve(process.cwd(), "build", "download_binaries.ts"),
|
||||
},
|
||||
output: {
|
||||
path: path.join(buildDir, "library"),
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".json", ".js", ".ts"],
|
||||
},
|
||||
externals: [
|
||||
nodeExternals(),
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: "node-loader",
|
||||
},
|
||||
getTypeScriptLoader({}, /\.ts$/),
|
||||
...iconsAndImagesWebpackRules(),
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
export default configs;
|
||||
Loading…
Reference in New Issue
Block a user