Skip to content

Commit

Permalink
feat: add build stamp to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebrynes7 committed Jan 3, 2025
1 parent 3d6ec0c commit 7e0bf80
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions plugin/src/i18n/langs/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const en: Translations = {
label: "Enable debug logging",
description: "Whether debug logging should be enabled",
},
buildStamp: {
label: "Build stamp",
description: "Stamp for the build of this plugin",
},
},
deprecation: {
warningMessage: "This setting is deprecated and will be removed in a future release.",
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/i18n/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export type Translations = {
label: string;
description: string;
};
buildStamp: {
label: string;
description: string;
};
};
deprecation: {
warningMessage: string;
Expand Down
1 change: 1 addition & 0 deletions plugin/src/stamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BuildStamp = "SYNC_WITH_TODOIST_BUILD_STAMP";
7 changes: 7 additions & 0 deletions plugin/src/ui/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AutoRefreshIntervalControl } from "./AutoRefreshIntervalControl";
import { Setting } from "./SettingItem";
import { TokenChecker } from "./TokenChecker";
import "./styles.scss";
import { BuildStamp } from "@/stamp";

export class SettingsTab extends PluginSettingTab {
private readonly plugin: TodoistPlugin;
Expand Down Expand Up @@ -188,6 +189,12 @@ const SettingsRoot: React.FC<Props> = ({ plugin }) => {
>
<Setting.ToggleControl {...toggleProps("debugLogging")} />
</Setting.Root>
<Setting.Root
name={i18n.advanced.buildStamp.label}
description={i18n.advanced.buildStamp.description}
>
<span className="setting-item-build-stamp">{BuildStamp}</span>
</Setting.Root>
</PluginContext.Provider>
);
};
4 changes: 4 additions & 0 deletions plugin/src/ui/settings/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
margin-left: 0.5em;
}
}

.setting-item-build-stamp {
font-size: var(--font-smaller);
}
11 changes: 10 additions & 1 deletion plugin/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path, { resolve } from "path";
import { execSync } from "node:child_process";
import path, { resolve } from "node:path";
import replace from "@rollup/plugin-replace";
import { loadEnv } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
Expand All @@ -19,6 +20,13 @@ function getOutDir(): string | undefined {
return path.join(vaultDir, ".obsidian", "plugins", "todoist-sync-plugin");
}

function getBuildStamp(): string {
const commitSha = execSync("git rev-parse --short HEAD").toString().trim();
const isDirty = execSync("git status --porcelain").toString().trim().length > 0;
const timestamp = new Date().toISOString().slice(2, 16).replace(/[-:]/g, "");
return `${commitSha}${isDirty ? "-dirty" : ""}-${timestamp}`;
}

export default defineConfig({
plugins: [
tsConfigPaths(),
Expand All @@ -32,6 +40,7 @@ export default defineConfig({
}),
replace({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
SYNC_WITH_TODOIST_BUILD_STAMP: getBuildStamp(),
}),
],
build: {
Expand Down

0 comments on commit 7e0bf80

Please sign in to comment.