From 4b91746648c0d224446fc4ee5b29e81b03eaf0ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Thu, 1 Dec 2022 09:45:46 +0100
Subject: [PATCH] refactor(doc): output generated PDFs to dist rather than to
 src

refs #578
---
 .gitignore                        |  3 ---
 mkdocs2pdf.py                     |  2 +-
 package.json                      |  6 +++---
 scripts/mkdocs-postprocess.js     |  3 ---
 scripts/mkdocs2pdf-postprocess.js | 13 +++++++++++++
 5 files changed, 17 insertions(+), 10 deletions(-)
 create mode 100644 scripts/mkdocs2pdf-postprocess.js

diff --git a/.gitignore b/.gitignore
index 8938871aa..78a09cc0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,9 +5,6 @@
 /tmp
 /out-tsc
 /src/assets/docs
-/compodoc-fr
-/docs/fr/pdf
-/docs/en/pdf
 /release
 /build
 
diff --git a/mkdocs2pdf.py b/mkdocs2pdf.py
index 45f9dd85a..a4f15b0dc 100644
--- a/mkdocs2pdf.py
+++ b/mkdocs2pdf.py
@@ -23,7 +23,7 @@ import shutil
 baseDir = os.getcwd();
 latexSourceDir = os.path.join(baseDir, 'docs/latex')
 buildDir = os.path.join(baseDir, 'build/pdf_build')
-outputDir = os.path.join(baseDir, 'src/assets/docs/pdf')
+outputDir = os.path.join(baseDir, 'dist/assets/docs/pdf')
 
 latexModelDir = 'latex_models'
 modelDir = os.path.join(buildDir, latexModelDir)
diff --git a/package.json b/package.json
index cc09431f4..31400d75d 100644
--- a/package.json
+++ b/package.json
@@ -15,12 +15,12 @@
     "e2equick": "node scripts/check-translations.js && npm run ng -- e2e --dev-server-target= --suite=regular --webdriver-update=false",
     "monkeytest": "npm run ng -- e2e --dev-server-target= --suite=monkeyTest --webdriver-update=false",
     "mkdocs": "python3 -m mkdocs build -f mkdocs-fr.yml && python3 -m mkdocs build -f mkdocs-en.yml && node scripts/mkdocs-postprocess.js",
-    "mkdocs2pdf": "node scripts/extract-nghyd-version.js build/cassiopee_version.tex && python3 mkdocs2pdf.py",
-    "clean": "rm -rf build dist release src/date_revision.ts src/assets/docs compodoc-fr docs/fr/pdf docs/en/pdf docs/pdf_build docs/cassiopee_version.tex",
+    "mkdocs2pdf": "node scripts/extract-nghyd-version.js build/cassiopee_version.tex && python3 mkdocs2pdf.py && node scripts/mkdocs2pdf-postprocess.js",
+    "clean": "rm -rf build dist release src/date_revision.ts src/assets/docs",
     "preprocess": "mkdir -p build; node scripts/preprocessors.js",
     "start": "npm run preprocess && npm run mkdocs && npm run ng serve -- --host 0.0.0.0 --poll 5000",
     "build-no-pdf": "npm run preprocess && npm run mkdocs && npm run ng build -- --configuration production",
-    "build": "npm run preprocess && npm run mkdocs && npm run mkdocs2pdf && npm run ng build -- --configuration production",
+    "build": "npm run preprocess && npm run mkdocs && npm run ng build -- --configuration production && npm run mkdocs2pdf",
     "update-dist-index-mimetypes": "node scripts/update-dist-index-mimetypes.js",
     "electron": "npm run update-dist-index-mimetypes && \"node_modules/.bin/electron\" .",
     "release-linux-nocompile": "npm run update-dist-index-mimetypes && \"node_modules/.bin/electron-builder\"",
diff --git a/scripts/mkdocs-postprocess.js b/scripts/mkdocs-postprocess.js
index 61d0abe11..558e8300f 100644
--- a/scripts/mkdocs-postprocess.js
+++ b/scripts/mkdocs-postprocess.js
@@ -52,6 +52,3 @@ fs.copySync("docs/matomo-tracking.js", destPath_EN_JS + "/matomo-tracking.js");
 fs.copySync("node_modules/mermaid/dist/mermaid.min.js", destPath_JS + "/mermaid.min.js");
 fs.copySync("node_modules/mermaid/dist/mermaid.min.js", destPath_FR_JS + "/mermaid.min.js");
 fs.copySync("node_modules/mermaid/dist/mermaid.min.js", destPath_EN_JS + "/mermaid.min.js");
-
-// copy illustrated guide (not related to MkDocs, but still a part of the doc)
-fs.copySync("docs/cassiopee_notice_illustree_fr.pdf", "src/assets/docs/pdf/cassiopee_notice_illustree_fr.pdf");
diff --git a/scripts/mkdocs2pdf-postprocess.js b/scripts/mkdocs2pdf-postprocess.js
new file mode 100644
index 000000000..0752898f8
--- /dev/null
+++ b/scripts/mkdocs2pdf-postprocess.js
@@ -0,0 +1,13 @@
+'use strict';
+
+/*
+ * mkdocs2pdf post processing.
+ * - copy illustrated guide (not related to MkDocs, but still a part of the doc) to dist/assets/docs/pdf
+ */
+
+const fs = require('fs-extra');
+
+const destPath_PDF = "dist/assets/docs/pdf"; // pour la doc illustrée
+
+fs.ensureDirSync(destPath_PDF);
+fs.copySync("docs/cassiopee_notice_illustree_fr.pdf", destPath_PDF + "/cassiopee_notice_illustree_fr.pdf");
-- 
GitLab