diff --git a/.gitignore b/.gitignore index 32421de853e3cedece91cd22372d33bc5bf2284f..78a09cc0fddf6a5df8b83f762a55c96a25f888bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,11 +5,8 @@ /tmp /out-tsc /src/assets/docs -/compodoc-fr -/docs/fr/pdf -/docs/en/pdf /release -docs/pdf_build +/build # dependencies /node_modules diff --git a/docs/latex/cassiopee_doc_en.tex b/docs/latex/cassiopee_doc_en.tex index 66d99b1dc9aeb5f7d29e838e8b3ca316cf4ae15c..7f86d9a6b60419d05a409e67eaf47f3b55dd61b6 100644 --- a/docs/latex/cassiopee_doc_en.tex +++ b/docs/latex/cassiopee_doc_en.tex @@ -13,15 +13,16 @@ % Insertion des différents préambules au document \input{rapport/english/preambule_rapport_english} \input{rapport_inrae/preambule_inrae} - +% Cassiopée version in the form \newcommand{\cassiopeeversion}{x.y.z} +\input{cassiopee_version} %******************************************************************************* %Données de titre et d'auteur pour la page de garde, les entêtes et pieds de page %******************************************************************************* % Le titre doit être relativement court mais assez explicite \newcommand{\service}{UMR G-EAU} -\newcommand{\titre}{Cassiopée 4 software} -\newcommand{\sousTitre}{User documentation} +\newcommand{\titre}{Cassiopée software} +\newcommand{\sousTitre}{version \cassiopeeversion\\User documentation} %Statut du document [rapport final, rapport intermédiaire] % auteur intellectuel, rédacteur du document, il peut y avoir plusieurs auteurs ; chaque auteur est renseigné sous la forme « Prénom NOM » \newcommand{\auteur}{David DORCHIES, Mathias CHOUET, François GRAND} diff --git a/docs/latex/cassiopee_doc_fr.tex b/docs/latex/cassiopee_doc_fr.tex index ca5a85f9a344642ade7dbc5d6bc2a65ba95a3ad9..3360b058313a441e29f778790ae30aac12ad9abc 100644 --- a/docs/latex/cassiopee_doc_fr.tex +++ b/docs/latex/cassiopee_doc_fr.tex @@ -13,15 +13,16 @@ % Insertion des différents préambules au document \input{rapport/francais/preambule_rapport_francais} \input{rapport_inrae/preambule_inrae} - +% version de Cassiopée sous la forme \newcommand{\cassiopeeversion}{x.y.z} +\input{cassiopee_version} %******************************************************************************* %Données de titre et d'auteur pour la page de garde, les entêtes et pieds de page %******************************************************************************* % Le titre doit être relativement court mais assez explicite \newcommand{\service}{UMR G-EAU} -\newcommand{\titre}{Logiciel Cassiopée 4} -\newcommand{\sousTitre}{Documentation utilisateur} +\newcommand{\titre}{Logiciel Cassiopée} +\newcommand{\sousTitre}{version \cassiopeeversion\\Documentation utilisateur} %Statut du document [rapport final, rapport intermédiaire] % auteur intellectuel, rédacteur du document, il peut y avoir plusieurs auteurs ; chaque auteur est renseigné sous la forme « Prénom NOM » \newcommand{\auteur}{David DORCHIES, Mathias CHOUET, François GRAND} diff --git a/mkdocs-en.yml b/mkdocs/mkdocs-en.yml similarity index 100% rename from mkdocs-en.yml rename to mkdocs/mkdocs-en.yml diff --git a/mkdocs-fr.yml b/mkdocs/mkdocs-fr.yml similarity index 100% rename from mkdocs-fr.yml rename to mkdocs/mkdocs-fr.yml diff --git a/package.json b/package.json index e13bbb080a559fc297fb8a1f39213574cc934117..27d885816f2f7b7dc53a758efd9d5fb9cd90d4d0 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,13 @@ "e2e": "npm run preprocess && node scripts/check-translations.js && npm run ng -- e2e --suite=regular --webdriver-update=false", "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": "node scripts/python3.js -m mkdocs build -f mkdocs-fr.yml && node scripts/python3.js -m mkdocs build -f mkdocs-en.yml && node scripts/mkdocs-postprocess.js", - "mkdocs2pdf": "node scripts/python3.js mkdocs2pdf.py", - "preprocess": "node scripts/preprocessors.js && npm run mkdocs", - "start": "npm run preprocess && npm run ng serve -- --host 0.0.0.0 --poll 5000", - "build-no-pdf": "npm run preprocess && npm run ng build -- --configuration production", - "build": "npm run preprocess && npm run mkdocs2pdf && npm run ng build -- --configuration production", + "mkdocs": "bash scripts/prepare_mkdocs.sh; cd build; python3 -m mkdocs build -f mkdocs-fr.yml && python3 -m mkdocs build -f mkdocs-en.yml && cd .. && node scripts/mkdocs-postprocess.js", + "mkdocs2pdf": "node scripts/extract-nghyd-version.js build/cassiopee_version.tex && python3 scripts/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 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/extract-nghyd-version.js b/scripts/extract-nghyd-version.js new file mode 100644 index 0000000000000000000000000000000000000000..aff3a3dd01a1b015880534983b5f0bdac5895b12 --- /dev/null +++ b/scripts/extract-nghyd-version.js @@ -0,0 +1,65 @@ +/* + * extract Cassiopée version from package.json and write files according to provided paths extension : + * - a LateX file defining a variable in the form \newcommand\{\cassiopeeversion}{x.y.z} for path(s) with .tex extension + * - a plain text file with version value (x.y.z) for path(s) without extension + */ + +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +if (process.argv.length < 3) { + console.error("ERROR : missing output file path(s)\n"); + console.error("syntax : extract-nghyd-version <path> [<path> ...]"); + console.error(" extract ngHyd current version to given files according to extension"); + console.error(" available extensions : .tex (LateX file with variable), <none (plain version in text file)>"); + process.exit(1); +} + +function createMissingDirs(p) { + const targetDir = path.dirname(p); + if (!fs.existsSync(targetDir)) { + console.log("creating output directory", targetDir) + fs.mkdirSync(targetDir, { recursive: true }); + } +} + +function writeTex(outPath, ver) { + // make LateX variable + const s = `\\newcommand\{\\cassiopeeversion\}\{${ver}\}`; + + // create intermediate folders if necessary + createMissingDirs(outPath) + + // write file + console.log("writing LateX file", outPath); + fs.writeFileSync(outPath, s); +} + +function writePlain(outPath, ver) { + // create intermediate folders if necessary + createMissingDirs(outPath) + + // write file + console.log("writing plain file", outPath); + fs.writeFileSync(outPath, ver); +} + +// read package.json +console.log("reading package.json"); +var fdata = fs.readFileSync('package.json', 'utf8'); +var data = JSON.parse(fdata) + +// get Cassiopée version +const ver = data.version +console.log("got ngHyd version", ver); + +for (let i = 2; i < process.argv.length; i++) { + const p = process.argv[i]; + if (p.endsWith(".tex")) { + writeTex(p, ver); + } else { + writePlain(p, ver); + } +} diff --git a/scripts/mkdocs-postprocess.js b/scripts/mkdocs-postprocess.js index 61d0abe11e823477c9cbe239a6ddc8c7f60ac110..558e8300fe0d45f43ee54530b3a9208fb2725d07 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 0000000000000000000000000000000000000000..0752898f8f37391cbaced681ebda9bea5bcd3261 --- /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"); diff --git a/mkdocs2pdf.py b/scripts/mkdocs2pdf.py similarity index 75% rename from mkdocs2pdf.py rename to scripts/mkdocs2pdf.py index c83f54033c7e7552d95cde47f9be82610c89d94b..6e3cf68040aa15e43debd48019a955e3e13d9b2a 100644 --- a/mkdocs2pdf.py +++ b/scripts/mkdocs2pdf.py @@ -20,19 +20,24 @@ import yaml import re import shutil -baseDir = os.getcwd(); - -buildDir = os.path.join(baseDir, 'docs/pdf_build') -outputDir = os.path.join(baseDir, 'src/assets/docs/pdf') +baseDir = os.getcwd() +buildDir = os.path.join(baseDir, 'build') +latexSourceDir = os.path.join(baseDir, 'docs/latex') +pdfBuildDir = os.path.join(buildDir, 'pdf_build') +outputDir = os.path.join(baseDir, 'dist/assets/docs/pdf') latexModelDir = 'latex_models' -modelDir = os.path.join(buildDir, latexModelDir) +modelDir = os.path.join(pdfBuildDir, latexModelDir) mergedDocFilenamePrefix = 'cassiopee_doc_contents_' filenamePrefix = 'cassiopee_doc_' latexModelRepository = 'https://gitlab.irstea.fr/david.dorchies/latex_models.git' +def runCommand(cmd): + if os.waitstatus_to_exitcode(os.system(cmd)) != 0: + raise RuntimeError("error executing:",cmd) + # Reads an MkDocs configuration file def readConfig(sYAML): f = open(sYAML, 'r') @@ -71,7 +76,7 @@ def exploreAndMerge(docs_dir, nav, output = '', level = 0): filepath = os.path.join(docs_dir, d) f = open(filepath, 'r') # Triple "../" because file will be compiled from pdf_build/latex_models - path = os.path.join('../../..', os.path.dirname(filepath)) + path = os.path.join(baseDir, os.path.dirname(filepath)) s = f.read() + "\n" # Modification of image and links paths s = re.sub(r'(\!\[.+\]\()(.+)(\))', r'\1'+path+r'/\2\3', s) @@ -93,7 +98,7 @@ def exploreAndMerge(docs_dir, nav, output = '', level = 0): # Creates a filePath.tex LaTeX contents file based on filePath.md def convertMdToTex(filePath): # Convert .md to .tex - os.system( + runCommand( 'pandoc {0}.md -f markdown -t latex -s -o {0}.tex'.format(filePath) ) # Remove header of tex file @@ -124,8 +129,8 @@ def convertMdToTex(filePath): def getLatexModel(): # Clone Git repository - os.chdir(buildDir) - os.system( + os.chdir(pdfBuildDir) + runCommand( 'git clone {} {}'.format(latexModelRepository, latexModelDir) ) # back to original working drectory @@ -141,22 +146,34 @@ def injectContentIntoModel(mergedDocFilenameTex, lang): # Symlink necessary resources os.chdir(modelDir) relPathToMergedTexDoc = os.path.join('..', mergedDocFilenameTex) - os.system( + runCommand( 'ln -s {} .'.format(relPathToMergedTexDoc) ) - latexTemplate = 'cassiopee_doc_' + lang + '.tex' - relPathToLatexTemplate = os.path.join('../../latex', latexTemplate) - os.system( - 'ln -s {} .'.format(relPathToLatexTemplate) + latexTemplate = filenamePrefix + lang + '.tex' + relPathToLatexTemplate = os.path.join(latexSourceDir, latexTemplate) + runCommand( + 'ln -s {}'.format(relPathToLatexTemplate) ) - os.system( - 'ln -s ../../latex/logo_pole.png .' + runCommand( + 'ln -s {}'.format(os.path.join(latexSourceDir, 'logo_pole.png')) ) - os.system( + runCommand( + 'ln -s {}/schema_rugosite_fond.png'.format(os.path.join(baseDir, 'docs', lang, 'calculators', 'pam')) + ) + runCommand( + 'ln -s {}/bloc_cylindre.png'.format(os.path.join(baseDir, 'docs', lang, 'calculators', 'pam')) + ) + runCommand( + 'ln -s {}/bloc_face_arrondie.png'.format(os.path.join(baseDir, 'docs', lang, 'calculators', 'pam')) + ) + runCommand( + 'ln -s {}/bloc_base_carree.png'.format(os.path.join(baseDir, 'docs', lang, 'calculators', 'pam')) + ) + runCommand( 'rm rapport_inrae/logos.tex' ) - os.system( - 'ln -s ../../../latex/logos.tex rapport_inrae/' + runCommand( + 'ln -s {} rapport_inrae/'.format(os.path.join(latexSourceDir, 'logos.tex')) ) # back to original working drectory os.chdir(baseDir) @@ -165,8 +182,13 @@ def injectContentIntoModel(mergedDocFilenameTex, lang): def buildPDF(lang): # Compile LaTeX source os.chdir(modelDir) - sourceTexFile = 'cassiopee_doc_' + lang + '.tex' - outputPdfFile = 'cassiopee_doc_' + lang + '.pdf' + sourceTexFile = filenamePrefix + lang + '.tex' + outputPdfFile = filenamePrefix + lang + '.pdf' + + # copy Cassiopée version LateX file + cvt = os.path.join(buildDir, 'cassiopee_version.tex') + shutil.copy(cvt, modelDir) + os.system( 'latexmk -f -xelatex -pdf -interaction=nonstopmode {} > /dev/null 2>&1'.format(sourceTexFile) ) @@ -179,19 +201,19 @@ def buildPDF(lang): def buildDocForLang(lang): # Prepare temporary build directory - os.makedirs(buildDir, exist_ok=True) + os.makedirs(pdfBuildDir, exist_ok=True) # Prepare output directory os.makedirs(outputDir, exist_ok=True) # Read config - yamlPath = 'mkdocs-' + lang + '.yml' + yamlPath = 'mkdocs/mkdocs-' + lang + '.yml' dMkdocsYaml = readConfig(yamlPath) # Create string with merged MarkDown s = exploreAndMerge(dMkdocsYaml['docs_dir'], dMkdocsYaml['nav']) # Save the merged .md file mergedDocFilename = mergedDocFilenamePrefix + lang - mergedDocOutputPath = os.path.join(buildDir, mergedDocFilename) + mergedDocOutputPath = os.path.join(pdfBuildDir, mergedDocFilename) # remove internal links @TODO convert them to hyperref ? s = re.sub(r'\[([^/]+)\]\([^ ]+\.md\)', r'\1', s) with open('{}.md'.format(mergedDocOutputPath), 'w') as f: @@ -208,7 +230,8 @@ def buildDocForLang(lang): buildPDF(lang) # Clean build dir - shutil.rmtree(buildDir) + shutil.rmtree(pdfBuildDir) + #raise RuntimeError() if __name__ == '__main__': diff --git a/scripts/prepare_mkdocs.sh b/scripts/prepare_mkdocs.sh new file mode 100644 index 0000000000000000000000000000000000000000..af53d10dcba3d84c8ab5c753c75b72cd513fd3da --- /dev/null +++ b/scripts/prepare_mkdocs.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -o errexit + +BUILD_DIR=build +VER_FILE=$BUILD_DIR/cassiopee_version + +function prepareMkdocs +{ + local lang=$1 + + # copy and modify Mkdocs configuration file : + # - add Cassiopée version + # - modify path to input files + # - modify path to output files + cat mkdocs/mkdocs-$lang.yml \ + | sed "/^site_name:/ s/$/ v$VER/" \ + | sed "/^docs_dir:/ s/docs_dir: /docs_dir: ..\//" \ + | sed "/^site_dir:/ s/site_dir: /site_dir: ..\//" > $BUILD_DIR/mkdocs-$1.yml +} + +node scripts/extract-nghyd-version.js $VER_FILE +VER=$(cat $VER_FILE) + +prepareMkdocs fr +prepareMkdocs en diff --git a/scripts/python3.js b/scripts/python3.js deleted file mode 100644 index 00ee016d7596dd3146f23e3a51a272adde966fd0..0000000000000000000000000000000000000000 --- a/scripts/python3.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -const exec = require("child_process").execSync; -const os = require("os"); - -let py = "python3"; -if (os.platform() === "win32") { - py = "python"; -} - -const command = py + " " + process.argv.slice(2).join(" "); -console.log("executing", command); - -const ret = exec(command); -console.log(ret.toString());