From ba5a3e0b41f9c2a01ad9d704c3f97c20c5d7cfe3 Mon Sep 17 00:00:00 2001
From: Julian Maurice <julian.maurice@biblibre.com>
Date: Tue, 17 Oct 2023 17:13:55 +0200
Subject: [PATCH] Bug 35079: Replace --force-extract by
 --generate-pot={always,auto,never}

This restores the original behaviour of always building the POT file
in order to not break existing workflows
Option --force-extract is deleted in favor of a new option
--generate-pot that can have 3 values:

* always: always build the POT file. This is the default value
* auto: build the POT file only if it does not exist
* never: never build the POT file

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 gulpfile.js | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index 8cea78b04c6..1c119663ce1 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -19,7 +19,7 @@ const exec = require('gulp-exec');
 const merge = require('merge-stream');
 const through2 = require('through2');
 const Vinyl = require('vinyl');
-const args = require('minimist')(process.argv.slice(2));
+const args = require('minimist')(process.argv.slice(2), { default: { 'generate-pot': 'always' } });
 const rename = require('gulp-rename');
 
 const STAFF_CSS_BASE = "koha-tmpl/intranet-tmpl/prog/css";
@@ -262,7 +262,11 @@ function po_create_type (type) {
 
     // Generate .pot only if it doesn't exist or --force-extract is given
     const extract = () => stream.finished(poTasks[type].extract());
-    const p = args['force-extract'] ? extract() : access(pot).catch(extract);
+    const p =
+        args['generate-pot'] === 'always' ? extract() :
+        args['generate-pot'] === 'auto' ? access(pot).catch(extract) :
+        args['generate-pot'] === 'never' ? Promise.resolve(0) :
+        Promise.reject(new Error('Invalid value for option --generate-pot: ' + args['generate-pot']))
 
     return p.then(function () {
         const languages = getLanguages();
@@ -299,7 +303,11 @@ function po_update_type (type) {
 
     // Generate .pot only if it doesn't exist or --force-extract is given
     const extract = () => stream.finished(poTasks[type].extract());
-    const p = args['force-extract'] ? extract() : access(pot).catch(extract);
+    const p =
+        args['generate-pot'] === 'always' ? extract() :
+        args['generate-pot'] === 'auto' ? access(pot).catch(extract) :
+        args['generate-pot'] === 'never' ? Promise.resolve(0) :
+        Promise.reject(new Error('Invalid value for option --generate-pot: ' + args['generate-pot']))
 
     return p.then(function () {
         const languages = getLanguages();
-- 
2.34.1