diff --git a/package.json b/package.json index 23e87d52..8b2759ff 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@rollup/plugin-commonjs": "^22.0.1", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", + "@rollup/plugin-replace": "^4.0.0", "@rollup/plugin-typescript": "^8.3.3", "@typescript-eslint/eslint-plugin": "^5.30.6", "@typescript-eslint/parser": "^5.30.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8592c492..5460a691 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,7 @@ specifiers: '@rollup/plugin-commonjs': ^22.0.1 '@rollup/plugin-json': ^4.1.0 '@rollup/plugin-node-resolve': ^13.3.0 + '@rollup/plugin-replace': ^4.0.0 '@rollup/plugin-typescript': ^8.3.3 '@typescript-eslint/eslint-plugin': ^5.30.6 '@typescript-eslint/parser': ^5.30.6 @@ -33,6 +34,7 @@ devDependencies: '@rollup/plugin-commonjs': 22.0.1_rollup@2.77.0 '@rollup/plugin-json': 4.1.0_rollup@2.77.0 '@rollup/plugin-node-resolve': 13.3.0_rollup@2.77.0 + '@rollup/plugin-replace': 4.0.0_rollup@2.77.0 '@rollup/plugin-typescript': 8.3.3_sbpikdwgo7pbmeew3vug7t5zyu '@typescript-eslint/eslint-plugin': 5.30.6_b7n364ggt6o4xlkgyoaww3ph3q '@typescript-eslint/parser': 5.30.6_he2ccbldppg44uulnyq4rwocfa @@ -216,6 +218,16 @@ packages: rollup: 2.77.0 dev: true + /@rollup/plugin-replace/4.0.0_rollup@2.77.0: + resolution: {integrity: sha512-+rumQFiaNac9y64OHtkHGmdjm7us9bo1PlbgQfdihQtuNxzjpaB064HbRnewUOggLQxVCCyINfStkgmBeQpv1g==} + peerDependencies: + rollup: ^1.20.0 || ^2.0.0 + dependencies: + '@rollup/pluginutils': 3.1.0_rollup@2.77.0 + magic-string: 0.25.9 + rollup: 2.77.0 + dev: true + /@rollup/plugin-typescript/8.3.3_sbpikdwgo7pbmeew3vug7t5zyu: resolution: {integrity: sha512-55L9SyiYu3r/JtqdjhwcwaECXP7JeJ9h1Sg1VWRJKIutla2MdZQodTgcCNybXLMCnqpNLEhS2vGENww98L1npg==} engines: {node: '>=8.0.0'} diff --git a/rollup.config.js b/rollup.config.js index 28284a7b..aa149a29 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,6 +9,19 @@ import typescript from "@rollup/plugin-typescript"; import { name } from "./package.json"; import { terser } from "rollup-plugin-terser"; import { defineConfig } from "rollup"; +import { execSync } from "child_process"; +import replace from "@rollup/plugin-replace"; + +const quoteCommand = (command) => { + return JSON.stringify(execSync(command).toString().trim()); +}; + +const quoteCommandOrEnv = (command, env) => { + if (process.env[env]) { + return JSON.stringify(process.env[env]); + } + return quoteCommand(command); +}; export default defineConfig({ input: "src/main.ts", @@ -29,6 +42,17 @@ export default defineConfig({ return "window"; }, plugins: [ + replace({ + preventAssignment: true, + values: { + __NAME__: JSON.stringify(name.toUpperCase()), + __BRANCH__: quoteCommand("git rev-parse --abbrev-ref HEAD"), + __COMMIT__: quoteCommandOrEnv("git rev-parse HEAD", "GITHUB_SHA"), + __VERSION__: quoteCommand("git describe --tags --dirty --always"), + __REPO_URL__: quoteCommand("git remote get-url origin").replace(".git", ""), + __BUILD_TIME__: JSON.stringify(new Date().toISOString()) + } + }), nodeResolve(), commonjs(), typescript({ include: "src/**/*.ts" }), diff --git a/src/main.ts b/src/main.ts index e856ea2a..04fb0e5d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,3 @@ -import { name, version } from "../package.json"; // allow dynamic updating of secondary info. import "./secondary-info"; // adds three methods to add secondary info to entity rows. @@ -14,8 +13,13 @@ import "./modules/warning"; // adds the canary-card card. import "./modules/canary-card"; -console.info( - `%c ${name.toUpperCase()} %c ${version} `, +console.groupCollapsed( + `%c ${__NAME__} %c ${__VERSION__} `, `color: #212121; background: #fdd835; font-weight: 700;`, `color: #fdd835; background: #212121; font-weight: 700;` ); +console.info(`BRANCH : ${__BRANCH__}`); +console.info(`COMMIT : ${__COMMIT__}`); +console.info(`BUILT AT : ${__BUILD_TIME__}`); +console.info(__REPO_URL__); +console.groupEnd(); diff --git a/src/types.ts b/src/types.ts index 3cc59204..d6cb0500 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,6 +7,13 @@ declare global { interface HTMLElementTagNameMap { "hui-error-card": LovelaceCard; } + + const __NAME__: string; + const __BRANCH__: string; + const __COMMIT__: string; + const __VERSION__: string; + const __REPO_URL__: string; + const __BUILD_TIME__: string; } export interface CanaryCardConfig extends LovelaceCardConfig {