mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Make all migration declarations injectable using a token - Make all migrations injectable using a token for the renderer side (instead of clearing them based on the truthiness of ipcRenderer) Signed-off-by: Sebastian Malton <sebastian@malton.name>
38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import fse from "fs-extra";
|
|
import path from "path";
|
|
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
import { isErrnoException } from "../../../common/utils";
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import { userStorePreMigrationsInjectionToken } from "../../../common/user-store/migrations";
|
|
|
|
const userStoreFileNameMigrationInjectable = getInjectable({
|
|
id: "user-store-file-name-migration",
|
|
instantiate: (di) => () => {
|
|
const userDataPath = di.inject(directoryForUserDataInjectable);
|
|
const configJsonPath = path.join(userDataPath, "config.json");
|
|
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
|
|
|
try {
|
|
fse.moveSync(configJsonPath, lensUserStoreJsonPath);
|
|
} catch (error) {
|
|
if (error instanceof Error && error.message === "dest already exists.") {
|
|
fse.removeSync(configJsonPath);
|
|
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
|
// (No such file or directory)
|
|
return; // file already moved
|
|
} else {
|
|
// pass other errors along
|
|
throw error;
|
|
}
|
|
}
|
|
},
|
|
injectionToken: userStorePreMigrationsInjectionToken,
|
|
});
|
|
|
|
export default userStoreFileNameMigrationInjectable;
|