From f8c109e6222781ac255bd4051d02074d515e2537 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Sat, 19 Oct 2019 19:24:45 +0200
Subject: [PATCH] Copie tout le contenu de src, en plus de convertir les MD.

---
 Gruntfile.js | 31 +++++++++++++++++++++++++------
 package.json |  1 +
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 14988e6..95fa132 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,4 +1,5 @@
-const { readdirSync } = require("fs");
+const readdirp = require("readdirp");
+const { extname } = require("path");
 
 module.exports = grunt => {
   const PUBLIC_HOST = process.env.PUBLIC_HOST || "localhost";
@@ -28,7 +29,7 @@ module.exports = grunt => {
         files: ["Gruntfile.js"]
       },
       presentations: {
-        files: "src/**/*.md",
+        files: "src/**/*",
         tasks: [],
         options: {
           debounceDelay: 1000,
@@ -78,6 +79,12 @@ module.exports = grunt => {
         cwd: "node_modules/reveal.js/.",
         src: revealJsSources,
         dest: "dist/reveal.js/"
+      },
+      sources: {
+        expand: true,
+        cwd: "src/",
+        src: ["**/*", "!**/.*", "!**/*.md"],
+        dest: "dist/"
       }
     },
 
@@ -94,9 +101,14 @@ module.exports = grunt => {
   grunt.registerTask("serve", ["http-server", "build:dev", "watcher"]);
 
   grunt.registerTask("build:revealjs", ["copy:revealjs"]);
+  grunt.registerTask("build:sources", ["copy:sources"]);
 
   grunt.registerTask("build", env =>
-    grunt.task.run(["build:revealjs", `build:pres:${env || "prod"}`])
+    grunt.task.run([
+      "build:revealjs",
+      "build:sources",
+      `build:pres:${env || "prod"}`
+    ])
   );
 
   const enqueueBuilds = (paths, env) =>
@@ -109,9 +121,16 @@ module.exports = grunt => {
         )
     );
 
-  grunt.registerTask("build:pres", env =>
-    enqueueBuilds(readdirSync("src/"), env)
-  );
+  grunt.registerTask("build:pres", function(env) {
+    const done = this.async();
+    readdirp
+      .promise("src/", { fileFilter: "*.md" })
+      .then(entries => enqueueBuilds(entries.map(entry => entry.path), env))
+      .then(done, err => {
+        grunt.log.error(err);
+        done(false);
+      });
+  });
 
   grunt.event.removeAllListeners("chokidar");
   grunt.event.on("chokidar", function(_, filepath, target) {
diff --git a/package.json b/package.json
index 1dac4f1..502d3fa 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
     "grunt-exec": "^3.0.0",
     "grunt-http-server": "^2.1.0",
     "grunt-watcher": "^1.0.0",
+    "readdirp": "^3.2.0",
     "reveal.js": "git+https://gitlab.irstea.fr/guillaume.perreal/reveal.js.git#irstea"
   },
   "devDependencies": {
-- 
GitLab