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 414c6e6
Show file tree
Hide file tree
Showing 7 changed files with 33 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);
}
12 changes: 11 additions & 1 deletion plugin/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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";
import tsConfigPaths from "vite-tsconfig-paths";
import { configDefaults, defineConfig } from "vitest/config";

const { version } = require("./package.json");

function getOutDir(): string | undefined {
const env = loadEnv("prod", process.cwd());
if (env?.VITE_ENV !== "dev") {
Expand All @@ -19,6 +22,12 @@ 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 timestamp = new Date().toISOString().slice(2, 16).replace(/[-:]/g, "");
return `v${version}-${commitSha}-${timestamp}`;
}

export default defineConfig({
plugins: [
tsConfigPaths(),
Expand All @@ -32,6 +41,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 414c6e6

Please sign in to comment.