From 54707419224ca69adc1b94240830c52931884218 Mon Sep 17 00:00:00 2001 From: Andreas Hochsteger Date: Sat, 25 May 2024 13:12:04 +0000 Subject: [PATCH] feat: add version info lib, logs and docs --- docs/docs/reference/placeholder.mdx | 3 +++ docs/docusaurus.config.js | 6 ++++++ global.d.ts | 5 +++++ src/lib/EnvProvider.ts | 27 +++++++++++++++++++++++++++ src/lib/processors/GmailProcessor.ts | 6 +++++- tsconfig-examples.json | 24 ++---------------------- tsconfig.json | 2 +- webpack.config.js | 3 +++ 8 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 global.d.ts diff --git a/docs/docs/reference/placeholder.mdx b/docs/docs/reference/placeholder.mdx index 20bbb37f..c0f45a06 100644 --- a/docs/docs/reference/placeholder.mdx +++ b/docs/docs/reference/placeholder.mdx @@ -16,6 +16,9 @@ These placeholder are valid globally and can also be used for internal purposes | `date.now` | Current Timestamp | The current timestamp. Use `"${:date::}"` to format the date/time using a custom [date-fns format strings](https://date-fns.org/docs/format) (default: `"yyyy-MM-dd HH:mm:ss"`). | `2023-06-26 09:00:00` | | `env.runMode` | Runmode | The runMode used for processing. | `safe-mode` | | `env.timezone` | Timezone | The timezone used for processing. | `UTC` | +| `lib.description` | Library Description | The description of the Gmail Processor library. | | +| `lib.name` | Library Name | The name of the Gmail Processor library. | `gmail-processor` | +| `lib.version` | Library Version | The version of the Gmail Processor library. | `0.0.0` | | `user.email` | User Email | The email address of the active user. | `my.email@gmail.com` | ## Processing Placeholder diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 8cd6f1f9..cac55cb7 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -1,6 +1,7 @@ // @ts-check // Note: type annotations allow type checking and IDEs autocompletion import { themes } from 'prism-react-renderer'; +import { version } from "../package.json" const lightCodeTheme = themes.vsLight; const darkCodeTheme = themes.vsDark; @@ -84,6 +85,11 @@ const config = { }, // {to: '/blog', label: 'Blog', position: 'left'}, { to: '/playground', label: 'Playground', position: 'left' }, + { + href: `https://github.com/ahochsteger/gmail-processor/releases/${version}`, + position: 'right', + label: `Latest Release: ${version}`, + }, { href: 'https://github.com/ahochsteger/gmail-processor', position: 'right', diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 00000000..a77cade9 --- /dev/null +++ b/global.d.ts @@ -0,0 +1,5 @@ +declare const __PACKAGE_JSON__: { + description: string + name: string + version: string +} diff --git a/src/lib/EnvProvider.ts b/src/lib/EnvProvider.ts index 98c14179..e3be8335 100644 --- a/src/lib/EnvProvider.ts +++ b/src/lib/EnvProvider.ts @@ -8,6 +8,15 @@ import { } from "./Context" import { Logger as Log } from "./utils/Logger" +const packageInfo: { + description: string + name: string + version: string +} = + typeof __PACKAGE_JSON__ !== "undefined" + ? __PACKAGE_JSON__ + : { version: "0.0.0", name: "gmail-processor", description: "" } + export class EnvProvider { public static buildMetaInfo(ctx: EnvContext) { const m: MetaInfo = { @@ -29,6 +38,24 @@ export class EnvProvider { "Timezone", "The timezone used for processing.", ), + "lib.description": mi( + MIT.STRING, + () => packageInfo.description, + "Library Description", + "The description of the Gmail Processor library.", + ), + "lib.name": mi( + MIT.STRING, + () => packageInfo?.name, + "Library Name", + "The name of the Gmail Processor library.", + ), + "lib.version": mi( + MIT.STRING, + () => packageInfo?.version, + "Library Version", + "The version of the Gmail Processor library.", + ), "user.email": mi( MIT.STRING, () => ctx.env.session.getActiveUser().getEmail(), diff --git a/src/lib/processors/GmailProcessor.ts b/src/lib/processors/GmailProcessor.ts index 61a9d1dc..4119392b 100644 --- a/src/lib/processors/GmailProcessor.ts +++ b/src/lib/processors/GmailProcessor.ts @@ -30,6 +30,7 @@ import { newConfig, } from "../config/Config" import { VariableEntry } from "../config/GlobalConfig" +import { PatternUtil } from "../utils/PatternUtil" import { Timer } from "../utils/Timer" import { BaseProcessor } from "./BaseProcessor" import { ThreadProcessor } from "./ThreadProcessor" @@ -150,7 +151,10 @@ export class GmailProcessor extends BaseProcessor { ctx: EnvContext, reportFormat = "text", ): ProcessingResult { - ctx.log.info("Processing GmailProcessor config started ...") + const version = PatternUtil.stringValue(ctx, "lib.version") + ctx.log.info( + `Processing config started using Gmail Processor v${version} ...`, + ) this.checkTimezone(ctx, config) const actionRegistry = GmailProcessor.setupActionRegistry(ctx) actionRegistry.registerCustomActions(customActions) diff --git a/tsconfig-examples.json b/tsconfig-examples.json index 988dca97..07c8f21f 100644 --- a/tsconfig-examples.json +++ b/tsconfig-examples.json @@ -1,24 +1,4 @@ { - "compilerOptions": { - "allowJs": true, - "baseUrl": "src/", - "declaration": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "inlineSourceMap": true, - "lib": ["ES2020"], - "module": "commonjs", - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": false, - "noUnusedLocals": true, - "noUnusedParameters": true, - "outDir": "build", - "resolveJsonModule": true, - "strict": true, - // ES2019 for V8 support: https://github.com/google/clasp/blob/master/docs/typescript.md#v8-engine-support - "target": "ES2019", - "types": ["google-apps-script", "jest", "node"] - }, - "include": ["src/examples/**/*", "src/lib/**/*"] + "extends": "./tsconfig.json", + "include": ["src/lib/**/*", "src/examples/**/*", "./global.d.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 5f0a0d8e..fe108c63 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,5 +20,5 @@ "target": "ES2019", "types": ["google-apps-script", "jest", "node"] }, - "include": ["src/lib/**/*"] + "include": ["src/lib/**/*", "./global.d.ts"] } diff --git a/webpack.config.js b/webpack.config.js index 3b36d521..676f562c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,8 @@ /* eslint-disable no-undef, @typescript-eslint/no-var-requires */ const GasPlugin = require("gas-webpack-plugin") const NodePolyfillPlugin = require("node-polyfill-webpack-plugin") +const __PACKAGE_JSON__ = require("./package.json") +const { DefinePlugin } = require("webpack") module.exports = { mode: "development", @@ -20,6 +22,7 @@ module.exports = { comment: true, }), new NodePolyfillPlugin(), + new DefinePlugin({ __PACKAGE_JSON__: JSON.stringify(__PACKAGE_JSON__) }), ], devtool: false, }