From 98878bd6b604401ad5a7b2ceba82af0c9d896d13 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 17 May 2023 22:21:30 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9tecte=20si=20un=20th=C3=A8me=20est=20d?= =?UTF-8?q?=C3=A9j=C3=A0=20pr=C3=A9sent=20Et=20ignore=20sa=20g=C3=A9n?= =?UTF-8?q?=C3=A9ration=20dans=20ce=20cas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/build-manifest.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/build-manifest.js b/src/build-manifest.js index 559facc..a1572ca 100644 --- a/src/build-manifest.js +++ b/src/build-manifest.js @@ -1,18 +1,23 @@ const fs = require("fs"); const path = require("path"); const iptc = require("node-iptc"); +const { exit } = require("process"); -// find all images +// Fetch envs to target the right folder const slug = process.env["PACKAGE_NAME"]; const root = process.env["ENTRY_FOLDER"]; +if (!slug || !root) exit(1); let workingDirectory = path.join(root, slug); // extract metadata from them fs.readdir(workingDirectory, (err, files) => { - if (err) { throw err }; + if (err) { throw err }; // If IO error, exit with an error message - // construct a JSON file + // If there is already a theme.json silentely exit and let mocha running afterwards + if (!files.find(file => path.extname(file) == '.json')) exit(0); + + // construct a JSON object let theme = new Object(); theme.dayImageList = []; theme.nightImageList = []; @@ -63,7 +68,7 @@ fs.readdir(workingDirectory, (err, files) => { break; } }); - + // make it the theme.json fs.writeFileSync(path.join(workingDirectory, 'theme.json'), JSON.stringify(theme)); });