Parcourir la source

Write sha1 log to *.revision.txt file

jherve il y a 1 an
Parent
commit
c98459611d
1 fichiers modifiés avec 18 ajouts et 0 suppressions
  1. 18 0
      to_pdf.js

+ 18 - 0
to_pdf.js

@@ -3,6 +3,7 @@
 const fs = require("fs");
 const path = require("path");
 const yaml = require("yaml");
+const { exec } = require("child_process");
 
 const puppeteer = require("puppeteer");
 const pug = require("pug");
@@ -41,6 +42,7 @@ function exportToPdf(htmlFile, pdfPath) {
 
 function exportRenderToPdf(dataFilePath, templatePath, assetsPath, outputPath, outputBasename) {
   const data = parseData(dataFilePath);
+  const revPath = path.join(outputPath, `${outputBasename}.revision.txt`);
   const htmlPath = path.join(outputPath, `${outputBasename}.html`);
   const pdfPath = path.join(outputPath, `${outputBasename}.pdf`);
   const newAssetsPath = path.join(outputPath, "assets");
@@ -54,6 +56,22 @@ function exportRenderToPdf(dataFilePath, templatePath, assetsPath, outputPath, o
 
   exportToPdf(htmlPath, pdfPath);
   console.log(`Wrote PDF file to ${pdfPath}`);
+
+  writeGitRevisionFile(dataFilePath, templatePath, assetsPath, revPath);
+}
+
+function writeGitRevisionFile(dataFilePath, templatePath, assetsPath, revPath) {
+  const cmd = `git log --format="%H" ${dataFilePath} ${templatePath} ${assetsPath} | head -1`;
+  exec(cmd, (err, stdout, stderr) => {
+    if (err) {
+      return;
+    }
+
+    fs.writeFile(revPath, stdout, (err) => {
+      if (err) throw err;
+    });
+    console.log(`Wrote file revision data to ${revPath}`);
+  });
 }
 
 const [inputPath, variantName, outputPath] = process.argv.slice(2);