diff --git a/CHANGELOG.md b/CHANGELOG.md index a77b2046..c7fb27d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#131](https://github.com/estruyf/vscode-front-matter/issues/131): Folder creation support added on media dashboard - [#134](https://github.com/estruyf/vscode-front-matter/issues/134): On startup, the extension checks if local settings can be promoted - [#135](https://github.com/estruyf/vscode-front-matter/issues/135): `Hidden` property added for field configuration +- [#137](https://github.com/estruyf/vscode-front-matter/issues/137): Ask to move the `.templates` folder to the new `.frontmatter` folder ### 🐞 Fixes diff --git a/package.json b/package.json index 6359c4c6..96167159 100644 --- a/package.json +++ b/package.json @@ -455,7 +455,7 @@ }, "frontMatter.templates.folder": { "type": "string", - "default": ".templates", + "default": ".frontmatter/templates", "markdownDescription": "Specify the folder to use for your article templates. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.templates.folder)", "scope": "Templates" }, diff --git a/src/constants/ExtensionState.ts b/src/constants/ExtensionState.ts index 9ec19108..4f6be545 100644 --- a/src/constants/ExtensionState.ts +++ b/src/constants/ExtensionState.ts @@ -3,5 +3,6 @@ export const ExtensionState = { PagesView: `frontMatter:Pages:ViewType`, SelectedFolder: `frontMatter:SelectedFolder`, Version: `frontMatter:Version`, - SettingPromoted: `frontMatter:Settings:Promoted` + SettingPromoted: `frontMatter:Settings:Promoted`, + MoveTemplatesFolder: `frontMatter:Templates:Move`, }; \ No newline at end of file diff --git a/src/constants/LocalStore.ts b/src/constants/LocalStore.ts new file mode 100644 index 00000000..a5634e5e --- /dev/null +++ b/src/constants/LocalStore.ts @@ -0,0 +1,8 @@ + + +export const LocalStore = { + rootFolder: ".frontmatter", + contentFolder: "content", + templatesFolder: "templates", + mediaDatabaseFile: "mediaDb.json" +} \ No newline at end of file diff --git a/src/constants/index.ts b/src/constants/index.ts index c2b754b1..fad8cc87 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -3,6 +3,7 @@ export * from './DefaultFields'; export * from './Extension'; export * from './ExtensionState'; export * from './Links'; +export * from './LocalStore'; export * from './Navigation'; export * from './charMap'; export * from './context'; diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts index adaa29a4..c63cc30e 100644 --- a/src/helpers/Extension.ts +++ b/src/helpers/Extension.ts @@ -1,9 +1,11 @@ -import { basename } from "path"; +import { existsSync, renameSync } from "fs"; +import { basename, join } from "path"; import { extensions, Uri, ExtensionContext, window, workspace, commands } from "vscode"; import { Folders, WORKSPACE_PLACEHOLDER } from "../commands/Folders"; -import { EXTENSION_NAME, GITHUB_LINK, SETTINGS_CONTENT_FOLDERS, SETTINGS_CONTENT_PAGE_FOLDERS, SETTING_DATE_FIELD, SETTING_MODIFIED_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTING_TAXONOMY_CONTENT_TYPES, DEFAULT_CONTENT_TYPE_NAME, EXTENSION_BETA_ID, EXTENSION_ID, ExtensionState, DefaultFields } from "../constants"; +import { EXTENSION_NAME, GITHUB_LINK, SETTINGS_CONTENT_FOLDERS, SETTINGS_CONTENT_PAGE_FOLDERS, SETTING_DATE_FIELD, SETTING_MODIFIED_FIELD, SETTING_SEO_DESCRIPTION_FIELD, SETTING_TAXONOMY_CONTENT_TYPES, DEFAULT_CONTENT_TYPE_NAME, EXTENSION_BETA_ID, EXTENSION_ID, ExtensionState, DefaultFields, LocalStore, SETTING_TEMPLATES_FOLDER } from "../constants"; import { ContentType } from "../models"; import { Notifications } from "./Notifications"; +import { parseWinPath } from "./parseWinPath"; import { Settings } from "./SettingsHelper"; @@ -183,6 +185,34 @@ export class Extension { } } } + + // Migration to version 5 + if (major <= 5) { + const isMoved = await Extension.getInstance().getState(ExtensionState.MoveTemplatesFolder); + if (!isMoved) { + const wsFolder= Folders.getWorkspaceFolder(); + if (wsFolder) { + const templateFolder = join(parseWinPath(wsFolder.fsPath), `.templates`); + if (existsSync(templateFolder)) { + window.showInformationMessage(`Would you like to move your ".templates" folder to the new ".frontmatter" folder?`, 'Yes', 'No').then(async (result) => { + if (result === "Yes") { + const newFolderPath = join(parseWinPath(wsFolder.fsPath), LocalStore.rootFolder, LocalStore.templatesFolder); + renameSync(templateFolder, newFolderPath); + commands.executeCommand(`workbench.action.reloadWindow`); + Settings.update(SETTING_TEMPLATES_FOLDER, undefined, true); + Settings.update(SETTING_TEMPLATES_FOLDER, undefined); + } else if (result === "No") { + Settings.update(SETTING_TEMPLATES_FOLDER, `.templates`, true); + } + + if (result === "No" || result === "Yes") { + Extension.getInstance().setState(ExtensionState.MoveTemplatesFolder, true); + } + }); + } + } + } + } } public async setState(propKey: string, propValue: T, type: "workspace" | "global" = "global"): Promise { diff --git a/src/helpers/MediaLibrary.ts b/src/helpers/MediaLibrary.ts index 9a29b308..b86736bc 100644 --- a/src/helpers/MediaLibrary.ts +++ b/src/helpers/MediaLibrary.ts @@ -6,6 +6,7 @@ import { Folders, WORKSPACE_PLACEHOLDER } from '../commands/Folders'; import { existsSync, renameSync } from 'fs'; import { Notifications } from './Notifications'; import { parseWinPath } from './parseWinPath'; +import { LocalStore } from '../constants'; interface MediaRecord { description: string; @@ -18,7 +19,7 @@ export class MediaLibrary { private constructor() { const wsFolder = Folders.getWorkspaceFolder(); - this.db = new JsonDB(join(parseWinPath(wsFolder?.fsPath || ""), '.frontmatter/mediaDb.json'), true, false, '/'); + this.db = new JsonDB(join(parseWinPath(wsFolder?.fsPath || ""), LocalStore.rootFolder, LocalStore.contentFolder, LocalStore.mediaDatabaseFile), true, false, '/'); workspace.onDidRenameFiles(e => { e.files.forEach(f => {