Skip to content

Commit

Permalink
Include build information in bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Jul 18, 2022
1 parent 2620bc7 commit a1e0200
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

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

24 changes: 24 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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" }),
Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a1e0200

Please sign in to comment.