admin: added git method to get modified date.
This commit is contained in:
parent
fe6916955f
commit
40f64b4db3
@ -1,7 +1,11 @@
|
||||
import { dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { run } from "./run.js";
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
// Returns the most recent git commit hash for a given filename
|
||||
export async function getGitTag(filename) {
|
||||
const result = await run("git", ["log", "-n", "1", "--", filename]);
|
||||
const result = await run("git", ["log", "-n", "1", "--", filename], __dirname);
|
||||
if (!result.ok) {
|
||||
throw new Error(`git log error`);
|
||||
}
|
||||
@ -15,6 +19,28 @@ export async function getGitTag(filename) {
|
||||
}
|
||||
return hashMatch[1];
|
||||
}
|
||||
export async function getModifiedTime(filename) {
|
||||
const result = await run("git", ["log", "-n", "1", "--", filename], __dirname);
|
||||
if (!result.ok) {
|
||||
throw new Error(`git log error`);
|
||||
}
|
||||
let log = result.stdout.trim();
|
||||
if (!log) {
|
||||
return null;
|
||||
}
|
||||
for (let line of log.split("\n")) {
|
||||
line = line.trim();
|
||||
if (!line) {
|
||||
break;
|
||||
}
|
||||
const match = line.match(/^date:\s+(.*)$/i);
|
||||
if (match) {
|
||||
return (new Date(match[1].trim())).getTime();
|
||||
;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export async function getGitLog(filename, limit) {
|
||||
if (limit == null) {
|
||||
limit = 100;
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAgB;IAC5C,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,CAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAE,CAAC,CAAC;IACtE,IAAI,CAA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,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAC3D;iBAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;gBACjC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACzD;iBAAM;gBACH,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;aACjF;SACJ;KACL;IAED,0BAA0B;IAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;IAEb,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
@ -1,8 +1,14 @@
|
||||
import { dirname } from "path";
|
||||
import { fileURLToPath } from "url"
|
||||
|
||||
import { run } from "./run.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
// Returns the most recent git commit hash for a given filename
|
||||
export async function getGitTag(filename: string): Promise<null | string> {
|
||||
const result = await run("git", [ "log", "-n", "1", "--", filename ]);
|
||||
const result = await run("git", [ "log", "-n", "1", "--", filename ], __dirname);
|
||||
if (!result.ok) { throw new Error(`git log error`); }
|
||||
|
||||
let log = result.stdout.trim();
|
||||
@ -13,6 +19,24 @@ export async function getGitTag(filename: string): Promise<null | string> {
|
||||
return hashMatch[1];
|
||||
}
|
||||
|
||||
export async function getModifiedTime(filename: string): Promise<null | number> {
|
||||
const result = await run("git", [ "log", "-n", "1", "--", filename ], __dirname);
|
||||
if (!result.ok) { throw new Error(`git log error`); }
|
||||
|
||||
let log = result.stdout.trim();
|
||||
if (!log) { return null; }
|
||||
|
||||
for (let line of log.split("\n")) {
|
||||
line = line.trim();
|
||||
if (!line) { break; }
|
||||
const match = line.match(/^date:\s+(.*)$/i);
|
||||
if (match) {
|
||||
return (new Date(match[1].trim())).getTime();;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
export interface GitLog {
|
||||
commit: string;
|
||||
author: string;
|
||||
|
Loading…
Reference in New Issue
Block a user