#137 - Ask to move the templates foler into frontmatter

This commit is contained in:
Elio Struyf
2021-10-06 21:03:17 +02:00
parent 2e6a466ba5
commit 1ea0999d17
7 changed files with 47 additions and 5 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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"
},
+2 -1
View File
@@ -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`,
};
+8
View File
@@ -0,0 +1,8 @@
export const LocalStore = {
rootFolder: ".frontmatter",
contentFolder: "content",
templatesFolder: "templates",
mediaDatabaseFile: "mediaDb.json"
}
+1
View File
@@ -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';
+32 -2
View File
@@ -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<boolean | undefined>(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<T>(propKey: string, propValue: T, type: "workspace" | "global" = "global"): Promise<void> {
+2 -1
View File
@@ -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 => {