mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Unify build fs layout (#6717)
* unify build fs layout Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use currentApp path for static files Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * absolute override path for tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
fe0c13424a
commit
4ac47fa795
1
Makefile
1
Makefile
@ -33,6 +33,7 @@ ci-validate-dev: binaries/client build-extensions compile-dev
|
||||
.PHONY: dev
|
||||
dev: binaries/client build-extensions
|
||||
rm -rf static/build/
|
||||
yarn run build:tray-icons
|
||||
yarn dev
|
||||
|
||||
.PHONY: lint
|
||||
|
||||
@ -9,7 +9,7 @@ import path from "path";
|
||||
import sharp from "sharp";
|
||||
|
||||
const size = Number(process.env.OUTPUT_SIZE || "16");
|
||||
const outputFolder = process.env.OUTPUT_DIR || "./build/tray";
|
||||
const outputFolder = process.env.OUTPUT_DIR || "./static/build/tray";
|
||||
const inputFile = process.env.INPUT_SVG_PATH || "./src/renderer/components/icon/logo-lens.svg";
|
||||
const noticeFile = process.env.NOTICE_SVG_PATH || "./src/renderer/components/icon/notice.svg";
|
||||
const spinnerFile = process.env.SPINNER_SVG_PATH || "./src/renderer/components/icon/arrow-spinner.svg";
|
||||
|
||||
17
package.json
17
package.json
@ -94,25 +94,10 @@
|
||||
"build": {
|
||||
"generateUpdatesFilesForAllChannels": true,
|
||||
"files": [
|
||||
"static/build/main.js"
|
||||
"static/**/*"
|
||||
],
|
||||
"afterSign": "build/notarize.js",
|
||||
"extraResources": [
|
||||
{
|
||||
"from": "locales/",
|
||||
"to": "locales/",
|
||||
"filter": "**/*.js"
|
||||
},
|
||||
{
|
||||
"from": "static/",
|
||||
"to": "static/",
|
||||
"filter": "!**/main.js"
|
||||
},
|
||||
{
|
||||
"from": "build/tray",
|
||||
"to": "static/icons",
|
||||
"filter": "*.png"
|
||||
},
|
||||
{
|
||||
"from": "extensions/",
|
||||
"to": "./extensions/",
|
||||
|
||||
@ -4,9 +4,10 @@
|
||||
*/
|
||||
import type { app as electronApp } from "electron";
|
||||
|
||||
export type PathName = Parameters<typeof electronApp["getPath"]>[0];
|
||||
export type PathName = Parameters<typeof electronApp["getPath"]>[0] | "currentApp";
|
||||
|
||||
export const pathNames: PathName[] = [
|
||||
"currentApp",
|
||||
"home",
|
||||
"appData",
|
||||
"userData",
|
||||
|
||||
@ -19,6 +19,7 @@ describe("app-paths", () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
const defaultAppPathsStub: AppPaths = {
|
||||
currentApp: "some-current-app",
|
||||
appData: "some-app-data",
|
||||
cache: "some-cache",
|
||||
crashDumps: "some-crash-dumps",
|
||||
@ -70,6 +71,7 @@ describe("app-paths", () => {
|
||||
const actual = windowDi.inject(appPathsInjectionToken);
|
||||
|
||||
expect(actual).toEqual({
|
||||
currentApp: "some-current-app",
|
||||
appData: "some-app-data",
|
||||
cache: "some-cache",
|
||||
crashDumps: "some-crash-dumps",
|
||||
@ -93,6 +95,7 @@ describe("app-paths", () => {
|
||||
const actual = mainDi.inject(appPathsInjectionToken);
|
||||
|
||||
expect(actual).toEqual({
|
||||
currentApp: "some-current-app",
|
||||
appData: "some-app-data",
|
||||
cache: "some-cache",
|
||||
crashDumps: "some-crash-dumps",
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import staticFilesDirectoryInjectable from "./static-files-directory.injectable";
|
||||
|
||||
|
||||
export default getGlobalOverride(staticFilesDirectoryInjectable, () => "/some-static-directory");
|
||||
@ -3,17 +3,17 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import appPathsInjectable from "../app-paths/app-paths.injectable";
|
||||
import joinPathsInjectable from "../path/join-paths.injectable";
|
||||
import lensResourcesDirInjectable from "./lens-resources-dir.injectable";
|
||||
|
||||
const staticFilesDirectoryInjectable = getInjectable({
|
||||
id: "static-files-directory",
|
||||
|
||||
instantiate: (di) => {
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const lensResourcesDir = di.inject(lensResourcesDirInjectable);
|
||||
const currentAppDir = di.inject(appPathsInjectable).currentApp;
|
||||
|
||||
return joinPaths(lensResourcesDir, "static");
|
||||
return joinPaths(currentAppDir, "static");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ import extensionInstallationStateStoreInjectable from "../extension-installation
|
||||
import installExtensionInjectable from "../extension-installer/install-extension/install-extension.injectable";
|
||||
import extensionPackageRootDirectoryInjectable from "../extension-installer/extension-package-root-directory/extension-package-root-directory.injectable";
|
||||
import installExtensionsInjectable from "../extension-installer/install-extensions/install-extensions.injectable";
|
||||
import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable";
|
||||
import readJsonFileInjectable from "../../common/fs/read-json-file.injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import pathExistsInjectable from "../../common/fs/path-exists.injectable";
|
||||
@ -29,6 +28,7 @@ import getRelativePathInjectable from "../../common/path/get-relative-path.injec
|
||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||
import removePathInjectable from "../../common/fs/remove-path.injectable";
|
||||
import homeDirectoryPathInjectable from "../../common/os/home-directory-path.injectable";
|
||||
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||
|
||||
const extensionDiscoveryInjectable = getInjectable({
|
||||
id: "extension-discovery",
|
||||
@ -41,7 +41,7 @@ const extensionDiscoveryInjectable = getInjectable({
|
||||
installExtension: di.inject(installExtensionInjectable),
|
||||
installExtensions: di.inject(installExtensionsInjectable),
|
||||
extensionPackageRootDirectory: di.inject(extensionPackageRootDirectoryInjectable),
|
||||
staticFilesDirectory: di.inject(staticFilesDirectoryInjectable),
|
||||
resourcesDirectory: di.inject(lensResourcesDirInjectable),
|
||||
readJsonFile: di.inject(readJsonFileInjectable),
|
||||
pathExists: di.inject(pathExistsInjectable),
|
||||
watch: di.inject(watchInjectable),
|
||||
|
||||
@ -38,7 +38,7 @@ interface Dependencies {
|
||||
readonly extensionsStore: ExtensionsStore;
|
||||
readonly extensionInstallationStateStore: ExtensionInstallationStateStore;
|
||||
readonly extensionPackageRootDirectory: string;
|
||||
readonly staticFilesDirectory: string;
|
||||
readonly resourcesDirectory: string;
|
||||
readonly logger: Logger;
|
||||
readonly isProduction: boolean;
|
||||
readonly fileSystemSeparator: string;
|
||||
@ -142,7 +142,7 @@ export class ExtensionDiscovery {
|
||||
}
|
||||
|
||||
get inTreeFolderPath(): string {
|
||||
return this.dependencies.joinPaths(this.dependencies.staticFilesDirectory, "../extensions");
|
||||
return this.dependencies.joinPaths(this.dependencies.resourcesDirectory, "extensions");
|
||||
}
|
||||
|
||||
get nodeModulesPath(): string {
|
||||
|
||||
@ -79,7 +79,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows normal tray icon", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -97,7 +97,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows tray icon for checking for updates", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -114,7 +114,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows tray icon for normal", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -141,7 +141,7 @@ describe("installing update", () => {
|
||||
|
||||
it("still shows tray icon for downloading", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -160,7 +160,7 @@ describe("installing update", () => {
|
||||
|
||||
it("still shows normal tray icon", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -180,7 +180,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows tray icon for update being available", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconUpdateAvailableTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -197,7 +197,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows tray icon for checking for updates", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
@ -215,7 +215,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows tray icon for update being available", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconUpdateAvailableTemplate.png",
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -234,7 +234,7 @@ describe("installing update", () => {
|
||||
|
||||
it("shows tray icon for downloading update", () => {
|
||||
expect(builder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
"/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,12 +8,12 @@ import { getApplicationBuilder } from "../../renderer/components/test-utils/get-
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { LensWindow } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
||||
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||
import focusApplicationInjectable from "../../main/electron-app/features/focus-application.injectable";
|
||||
import type { CreateElectronWindow } from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable";
|
||||
import createElectronWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable";
|
||||
import splashWindowInjectable from "../../main/start-main-application/lens-window/splash-window/splash-window.injectable";
|
||||
import { runInAction } from "mobx";
|
||||
import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable";
|
||||
|
||||
describe("opening application window using tray", () => {
|
||||
describe("given application has started", () => {
|
||||
@ -36,8 +36,8 @@ describe("opening application window using tray", () => {
|
||||
mainDi.override(focusApplicationInjectable, () => focusApplicationMock);
|
||||
|
||||
mainDi.override(
|
||||
lensResourcesDirInjectable,
|
||||
() => "/some-lens-resources-directory",
|
||||
staticFilesDirectoryInjectable,
|
||||
() => "/some-static-directory",
|
||||
);
|
||||
|
||||
const loadFileMock = jest
|
||||
@ -119,7 +119,7 @@ describe("opening application window using tray", () => {
|
||||
});
|
||||
|
||||
it("starts loading static HTML of splash window", () => {
|
||||
expect(callForSplashWindowHtmlMock).toHaveBeenCalledWith("/some-lens-resources-directory/static/splash.html");
|
||||
expect(callForSplashWindowHtmlMock).toHaveBeenCalledWith("/some-static-directory/splash.html");
|
||||
});
|
||||
|
||||
describe("when loading of splash window HTML resolves", () => {
|
||||
|
||||
@ -9,13 +9,17 @@ interface Dependencies {
|
||||
app: App;
|
||||
}
|
||||
|
||||
export type GetElectronAppPath = (name: PathName) => string;
|
||||
export type GetElectronAppPath = (name: PathName | "currentApp") => string;
|
||||
|
||||
export const getElectronAppPath = ({
|
||||
app,
|
||||
}: Dependencies): GetElectronAppPath => (
|
||||
(name) => {
|
||||
try {
|
||||
if (name === "currentApp") {
|
||||
return app.getAppPath();
|
||||
}
|
||||
|
||||
return app.getPath(name);
|
||||
} catch (e) {
|
||||
return "";
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import staticFilesDirectoryInjectable from "../../../common/vars/static-files-directory.injectable";
|
||||
import isDevelopmentInjectable from "../../../common/vars/is-development.injectable";
|
||||
import isMacInjectable from "../../../common/vars/is-mac.injectable";
|
||||
import { camelCase, flow, upperFirst } from "lodash/fp";
|
||||
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
||||
@ -16,12 +15,11 @@ const getTrayIconPathInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const isMac = di.inject(isMacInjectable);
|
||||
|
||||
const baseIconDirectory = joinPaths(
|
||||
staticFilesDirectory,
|
||||
isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras
|
||||
"build/tray",
|
||||
);
|
||||
|
||||
const fileSuffix = isMac ? "Template.png" : ".png";
|
||||
|
||||
@ -7,9 +7,9 @@ import { hasCorrectExtension } from "./has-correct-extension";
|
||||
import readFileInjectable from "../../../../common/fs/read-file.injectable";
|
||||
import readDirectoryInjectable from "../../../../common/fs/read-directory.injectable";
|
||||
import type { RawTemplates } from "./create-resource-templates.injectable";
|
||||
import staticFilesDirectoryInjectable from "../../../../common/vars/static-files-directory.injectable";
|
||||
import joinPathsInjectable from "../../../../common/path/join-paths.injectable";
|
||||
import parsePathInjectable from "../../../../common/path/parse.injectable";
|
||||
import lensResourcesDirInjectable from "../../../../common/vars/lens-resources-dir.injectable";
|
||||
|
||||
const lensCreateResourceTemplatesInjectable = getInjectable({
|
||||
id: "lens-create-resource-templates",
|
||||
@ -18,14 +18,14 @@ const lensCreateResourceTemplatesInjectable = getInjectable({
|
||||
const readFile = di.inject(readFileInjectable);
|
||||
const readDir = di.inject(readDirectoryInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
|
||||
const parsePath = di.inject(parsePathInjectable);
|
||||
const resourcesDirectory = di.inject(lensResourcesDirInjectable);
|
||||
|
||||
/**
|
||||
* Mapping between file names and their contents
|
||||
*/
|
||||
const templates: [file: string, contents: string][] = [];
|
||||
const templatesFolder = joinPaths(staticFilesDirectory, "../templates/create-resource");
|
||||
const templatesFolder = joinPaths(resourcesDirectory, "templates/create-resource");
|
||||
|
||||
for (const dirEntry of await readDir(templatesFolder)) {
|
||||
if (hasCorrectExtension(dirEntry)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user