#673 - git settings

This commit is contained in:
Elio Struyf
2024-02-05 19:28:16 +01:00
parent accb069bab
commit 62b9f12494
9 changed files with 70 additions and 21 deletions

View File

@@ -9,6 +9,7 @@
### 🎨 Enhancements
- [#673](https://github.com/estruyf/vscode-front-matter/pull/673): Added git settings to the welcome view and settings view
- [#727](https://github.com/estruyf/vscode-front-matter/pull/727): Updated Japanese translations thanks to [mayumihara](https://github.com/mayumih387)
- [#737](https://github.com/estruyf/vscode-front-matter/issues/737): Optimize the grid layout of the content and media dashboards
- [#741](https://github.com/estruyf/vscode-front-matter/issues/741): Added message on the content dashboard when content is processed

View File

@@ -50,8 +50,11 @@
"settings.diagnostic": "Diagnostic",
"settings.diagnostic.description": "You can run the diagnostics to check the whole Front Matter CMS configuration.",
"settings.diagnostic.link": "Run full diagnostics",
"settings.git.enabled": "Git synchronization",
"settings.git.enabled.description": "Enable Git synchronization to easily sync your changes with your repository.",
"settings.git": "Git synchronization",
"settings.git.enabled": "Enable Git synchronization to easily sync your changes with your repository.",
"settings.git.commitMessage": "Commit message",
"settings.git.submoduleInfo": "When working with Git submodules, you can refer to the submodule settings in the documentation.",
"settings.git.submoduleLink": "Read more about Git submodules",
"settings.commonSettings.website.title": "Website and SSG settings",
"settings.commonSettings.previewUrl": "Preview URL",

3
src/constants/Git.ts Normal file
View File

@@ -0,0 +1,3 @@
export const GIT_CONFIG = {
defaultCommitMessage: 'Synced by Front Matter'
};

View File

@@ -8,3 +8,5 @@ export const DOCUMENTATION_SETTINGS_LINK = 'https://frontmatter.codes/docs/setti
export const SENTRY_LINK =
'https://1ac45704bbe74264a7b4674bdc2abf48@o1022172.ingest.sentry.io/5988293';
export const DOCS_SUBMODULES = 'https://frontmatter.codes/docs/git-integration#git-submodules';

View File

@@ -7,6 +7,7 @@ export * from './ExtensionState';
export * from './Features';
export * from './FrameworkDetectors';
export * from './GeneralCommands';
export * from './Git';
export * from './Links';
export * from './LocalStore';
export * from './Navigation';

View File

@@ -6,10 +6,11 @@ import { useRecoilValue } from 'recoil';
import { SettingsSelector } from '../../state';
import { SettingsInput } from './SettingsInput';
import { VSCodeButton } from '@vscode/webview-ui-toolkit/react';
import { FrameworkDetectors, SETTING_FRAMEWORK_START, SETTING_GIT_ENABLED, SETTING_PREVIEW_HOST, SETTING_WEBSITE_URL } from '../../../constants';
import { DOCS_SUBMODULES, FrameworkDetectors, GIT_CONFIG, SETTING_FRAMEWORK_START, SETTING_GIT_COMMIT_MSG, SETTING_GIT_ENABLED, SETTING_PREVIEW_HOST, SETTING_WEBSITE_URL } from '../../../constants';
import { messageHandler } from '@estruyf/vscode/dist/client';
import { DashboardMessage } from '../../DashboardMessage';
import { SettingsCheckbox } from './SettingsCheckbox';
import { ChevronRightIcon } from '@heroicons/react/24/outline';
export interface ICommonSettingsProps { }
@@ -44,7 +45,8 @@ export const CommonSettings: React.FunctionComponent<ICommonSettingsProps> = (pr
SETTING_PREVIEW_HOST,
SETTING_WEBSITE_URL,
SETTING_FRAMEWORK_START,
SETTING_GIT_ENABLED
SETTING_GIT_ENABLED,
SETTING_GIT_COMMIT_MSG,
]).then((config) => {
setConfig(config);
setUpdated(false);
@@ -72,15 +74,38 @@ export const CommonSettings: React.FunctionComponent<ICommonSettingsProps> = (pr
</div>
<div className='py-4'>
<h2 className='text-xl mb-2'>{l10n.t(LocalizationKey.settingsGitEnabled)}</h2>
<h2 className='text-xl mb-2'>{l10n.t(LocalizationKey.settingsGit)}</h2>
<div className='space-y-2'>
<SettingsCheckbox
label={l10n.t(LocalizationKey.settingsGitEnabledDescription)}
label={l10n.t(LocalizationKey.settingsGitEnabled)}
name={SETTING_GIT_ENABLED}
value={(config.find((c) => c.name === SETTING_GIT_ENABLED)?.value || false) as boolean}
onChange={onSettingChange}
/>
<SettingsInput
label={l10n.t(LocalizationKey.settingsGitCommitMessage)}
name={SETTING_GIT_COMMIT_MSG}
value={(config.find((c) => c.name === SETTING_GIT_COMMIT_MSG)?.value || "") as string}
placeholder={GIT_CONFIG.defaultCommitMessage}
onChange={onSettingChange}
/>
<p className={`text-[var(--frontmatter-secondary-text)] flex items-center`}>
<ChevronRightIcon className='h-4 w-4 inline' />
<span>
{l10n.t(LocalizationKey.settingsGitSubmoduleInfo)}&nbsp;
</span>
<a
href={DOCS_SUBMODULES}
title={l10n.t(LocalizationKey.settingsGitSubmoduleLink)}
className='text-[var(--vscode-textLink-foreground)] hover:text-[var(--vscode-textLink-activeForeground)]'>
{l10n.t(LocalizationKey.settingsGitSubmoduleLink)}
</a>
</p>
</div>
</div>

View File

@@ -5,6 +5,7 @@ export interface ISettingsInputProps {
label: string;
name: string;
value: string;
placeholder?: string;
onChange: (key: string, value: string) => void;
fallback?: string;
}
@@ -13,6 +14,7 @@ export const SettingsInput: React.FunctionComponent<ISettingsInputProps> = ({
label,
name,
value,
placeholder,
onChange,
fallback
}: React.PropsWithChildren<ISettingsInputProps>) => {
@@ -24,6 +26,7 @@ export const SettingsInput: React.FunctionComponent<ISettingsInputProps> = ({
boxShadow: 'none'
}}
value={value || fallback || ""}
placeholder={placeholder}
onInput={(e: React.ChangeEvent<HTMLInputElement>) => onChange(name, e.target.value)}>
{label}
</VSCodeTextField>

View File

@@ -1,9 +1,16 @@
import {
COMMAND_NAME,
CONTEXT,
GIT_CONFIG,
SETTING_DATE_FORMAT,
SETTING_GIT_COMMIT_MSG,
SETTING_GIT_ENABLED,
SETTING_GIT_SUBMODULE_BRANCH,
SETTING_GIT_SUBMODULE_FOLDER,
SETTING_GIT_SUBMODULE_PULL,
SETTING_GIT_SUBMODULE_PUSH
} from './../../constants/settings';
SETTING_GIT_SUBMODULE_PUSH,
TelemetryEvent
} from './../../constants';
import { Settings } from './../../helpers/SettingsHelper';
import { Dashboard } from '../../commands/Dashboard';
import { PanelProvider } from '../../panelWebView/PanelProvider';
@@ -17,14 +24,6 @@ import {
} from '../../helpers';
import { GeneralCommands } from './../../constants/GeneralCommands';
import simpleGit, { SimpleGit } from 'simple-git';
import {
COMMAND_NAME,
CONTEXT,
SETTING_DATE_FORMAT,
SETTING_GIT_COMMIT_MSG,
SETTING_GIT_ENABLED,
TelemetryEvent
} from '../../constants';
import { Folders } from '../../commands/Folders';
import { commands } from 'vscode';
import { PostMessageData } from '../../models';
@@ -187,7 +186,7 @@ export class GitListener {
// Check if anything changed
if (status.files.length > 0) {
await subGit.raw(['add', '.', '-A']);
await subGit.commit(commitMsg || 'Synced by Front Matter');
await subGit.commit(commitMsg || GIT_CONFIG.defaultCommitMessage);
}
await subGit.push();
} catch (e) {
@@ -214,7 +213,7 @@ export class GitListener {
'git',
'commit',
'-m',
commitMsg || 'Synced by Front Matter'
commitMsg || GIT_CONFIG.defaultCommitMessage
]);
await git.subModule(['foreach', 'git', 'push']);
}
@@ -234,7 +233,7 @@ export class GitListener {
if (status.files.length > 0) {
await git.raw(['add', '.', '-A']);
await git.commit(commitMsg || 'Synced by Front Matter');
await git.commit(commitMsg || GIT_CONFIG.defaultCommitMessage);
}
await git.push();

View File

@@ -194,11 +194,23 @@ export enum LocalizationKey {
/**
* Git synchronization
*/
settingsGitEnabled = 'settings.git.enabled',
settingsGit = 'settings.git',
/**
* Enable Git synchronization to easily sync your changes with your repository.
*/
settingsGitEnabledDescription = 'settings.git.enabled.description',
settingsGitEnabled = 'settings.git.enabled',
/**
* Commit message
*/
settingsGitCommitMessage = 'settings.git.commitMessage',
/**
* When working with Git submodules, you can refer to the submodule settings in the documentation.
*/
settingsGitSubmoduleInfo = 'settings.git.submoduleInfo',
/**
* Read more about Git submodules
*/
settingsGitSubmoduleLink = 'settings.git.submoduleLink',
/**
* Website and SSG settings
*/