Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify build fs layout #6717

Merged
merged 4 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/generate-tray-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 1 addition & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
3 changes: 2 additions & 1 deletion src/common/app-paths/app-path-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/common/app-paths/app-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
6 changes: 3 additions & 3 deletions src/common/vars/static-files-directory.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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",
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/extension-discovery/extension-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions src/features/application-update/installing-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});

Expand All @@ -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",
);
});

Expand All @@ -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",
);
});

Expand All @@ -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",
);
});

Expand All @@ -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",
);
});

Expand All @@ -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",
);
});

Expand All @@ -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",
);
});

Expand All @@ -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",
);
});
});
Expand All @@ -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",
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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
Expand Down Expand Up @@ -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", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
4 changes: 1 addition & 3 deletions src/main/tray/menu-icon/get-tray-icon-path.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)) {
Expand Down