Refactor source of Git commit build info (closes #661)

This commit is contained in:
Keavon Chambers
2022-05-24 14:33:58 -07:00
parent c73f8a64a0
commit eca9797597
17 changed files with 126 additions and 118 deletions
+3 -3
View File
@@ -258,10 +258,10 @@ img {
<script lang="ts">
import { defineComponent } from "vue";
import { createBuildMetadataManager } from "@/io-managers/build-metadata";
import { createClipboardManager } from "@/io-managers/clipboard";
import { createHyperlinkManager } from "@/io-managers/hyperlinks";
import { createInputManager } from "@/io-managers/input";
import { createLocalizationManager } from "@/io-managers/localization";
import { createPanicManager } from "@/io-managers/panic";
import { createPersistenceManager } from "@/io-managers/persistence";
import { createDialogState, DialogState } from "@/state-providers/dialog";
@@ -276,10 +276,10 @@ import LayoutRow from "@/components/layout/LayoutRow.vue";
import MainWindow from "@/components/window/MainWindow.vue";
const managerDestructors: {
createBuildMetadataManager?: () => void;
createClipboardManager?: () => void;
createHyperlinkManager?: () => void;
createInputManager?: () => void;
createLocalizationManager?: () => void;
createPanicManager?: () => void;
createPersistenceManager?: () => void;
} = {};
@@ -332,10 +332,10 @@ export default defineComponent({
async mounted() {
// Initialize managers, which are isolated systems that subscribe to backend messages to link them to browser API functionality (like JS events, IndexedDB, etc.)
Object.assign(managerDestructors, {
createBuildMetadataManager: createBuildMetadataManager(this.editor),
createClipboardManager: createClipboardManager(this.editor),
createHyperlinkManager: createHyperlinkManager(this.editor),
createInputManager: createInputManager(this.editor, this.$el.parentElement, this.dialog, this.portfolio, this.fullscreen),
createLocalizationManager: createLocalizationManager(this.editor),
createPanicManager: createPanicManager(this.editor, this.dialog),
createPersistenceManager: await createPersistenceManager(this.editor, this.portfolio),
});
@@ -1,26 +0,0 @@
import { Editor } from "@/wasm-communication/editor";
// Gets metadata populated in the `process.env` namespace by code in `frontend/vue.config.js`.
// TODO: Move that functionality to a build.rs file so our web build system is more lightweight.
export function createBuildMetadataManager(editor: Editor): void {
// Release
const release = process.env.VUE_APP_RELEASE_SERIES;
// Timestamp
const date = new Date(process.env.VUE_APP_COMMIT_DATE || "");
const timezoneName = Intl.DateTimeFormat(undefined, { timeZoneName: "long" })
.formatToParts(new Date())
.find((part) => part.type === "timeZoneName");
const dateString = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
const timeString = `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
const timezoneNameString = timezoneName?.value;
const timestamp = `${dateString} ${timeString} ${timezoneNameString}`;
// Hash
const hash = (process.env.VUE_APP_COMMIT_HASH || "").substring(0, 8);
// Branch
const branch = process.env.VUE_APP_COMMIT_BRANCH;
editor.instance.populate_build_metadata(release || "", timestamp, hash, branch || "");
}
+25
View File
@@ -0,0 +1,25 @@
import { Editor } from "@/wasm-communication/editor";
import { TriggerAboutGraphiteLocalizedCommitDate } from "@/wasm-communication/messages";
export function createLocalizationManager(editor: Editor): void {
function localizeTimestamp(utc: string): string {
// Timestamp
const date = new Date(utc);
if (Number.isNaN(date.getTime())) return utc;
const timezoneName = Intl.DateTimeFormat(undefined, { timeZoneName: "long" })
.formatToParts(new Date())
.find((part) => part.type === "timeZoneName");
const dateString = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
const timeString = `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
const timezoneNameString = timezoneName?.value;
return `${dateString} ${timeString} ${timezoneNameString}`;
}
// Subscribe to process backend event
editor.subscriptions.subscribeJsMessage(TriggerAboutGraphiteLocalizedCommitDate, (triggerAboutGraphiteLocalizedCommitDate) => {
const localized = localizeTimestamp(triggerAboutGraphiteLocalizedCommitDate.commit_date);
editor.instance.request_about_graphite_dialog_with_localized_commit_date(localized);
});
}
@@ -522,6 +522,10 @@ export class TriggerTextCopy extends JsMessage {
readonly copy_text!: string;
}
export class TriggerAboutGraphiteLocalizedCommitDate extends JsMessage {
readonly commit_date!: string;
}
export class TriggerViewportResize extends JsMessage {}
// `any` is used since the type of the object should be known from the Rust side
@@ -546,6 +550,7 @@ export const messageMakers: Record<string, MessageMaker> = {
TriggerRasterDownload,
TriggerTextCommit,
TriggerTextCopy,
TriggerAboutGraphiteLocalizedCommitDate,
TriggerViewportResize,
TriggerVisitLink,
UpdateActiveDocument,
+6 -11
View File
@@ -1,15 +1,10 @@
/* eslint-disable @typescript-eslint/no-var-requires, no-console */
const { execSync, spawnSync } = require("child_process");
const { spawnSync } = require("child_process");
const path = require("path");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin");
process.env.VUE_APP_COMMIT_DATE = execSync("git log -1 --format=%cd", { encoding: "utf-8" }).trim();
process.env.VUE_APP_COMMIT_HASH = execSync("git rev-parse HEAD", { encoding: "utf-8" }).trim();
process.env.VUE_APP_COMMIT_BRANCH = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf-8" }).trim();
process.env.VUE_APP_RELEASE_SERIES = "Alpha Milestone 1";
module.exports = {
lintOnSave: "warning",
// https://cli.vuejs.org/guide/webpack.html
@@ -91,7 +86,7 @@ function formatThirdPartyLicenses(jsLicenses) {
if (rustLicenses === null) {
// This is probably caused by cargo about not being installed
console.error(`
Could not run 'cargo about', which is required to generate license information.
Could not run \`cargo about\`, which is required to generate license information.
To install cargo-about on your system, you can run:
cargo install cargo-about
License information is required on production builds. Aborting.`);
@@ -178,18 +173,18 @@ ${license.licenseText}
}
function generateRustLicenses() {
console.info("Generating license information for rust code");
console.info("Generating license information for Rust code");
const { stdout, stderr, status } = spawnSync("cargo", ["about", "generate", "about.hbs"], {
cwd: path.join(__dirname, ".."),
encoding: "utf8",
timeout: 60000, // one minute
timeout: 60000, // One minute
shell: true,
windowsHide: true, // hide the DOS window on windows
windowsHide: true, // Hide the terminal on Windows
});
if (status !== 0) {
if (status !== 101) {
// cargo returns 101 when the subcommand wasn't found
// Cargo returns 101 when the subcommand wasn't found
console.error("cargo-about failed", status, stderr);
}
return null;
+4 -5
View File
@@ -239,14 +239,13 @@ impl JsEditorHandle {
self.dispatch(message);
}
pub fn populate_build_metadata(&self, release: String, timestamp: String, hash: String, branch: String) {
let new = editor::communication::BuildMetadata { release, timestamp, hash, branch };
let message = Message::PopulateBuildMetadata { new };
pub fn request_about_graphite_dialog(&self) {
let message = DialogMessage::RequestAboutGraphiteDialog;
self.dispatch(message);
}
pub fn request_about_graphite_dialog(&self) {
let message = DialogMessage::RequestAboutGraphiteDialog;
pub fn request_about_graphite_dialog_with_localized_commit_date(&self, localized_commit_date: String) {
let message = DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate { localized_commit_date };
self.dispatch(message);
}