From 6a34320e4d927d44f410d222b3407a4dc60e7046 Mon Sep 17 00:00:00 2001
From: ezsh <ezsh.junk@gmail.com>
Date: Wed, 17 Mar 2021 00:07:16 +0100
Subject: [PATCH] gulpfile: do not run tweego three times in a row

Gulp runs shell pipe for each source file, which are now 3. Redefine the
tweego task as a simple shell command to run tweego only once.
---
 gulpfile.js | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index 724b0d54e98..46efaa33821 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -44,6 +44,15 @@ function tweeCompilerExecutable() {
 	return res;
 }
 
+function tweeCompileCommand() {
+	let sources = [path.join(cfg.dirs.intermediate, "story")];
+	sources.push(...cfg.sources.story.media);
+
+	let modules = [path.join(cfg.dirs.intermediate, "module")];
+	let moduleArgs = modules.map(fn => `--module=${fn}`);
+	return `${tweeCompilerExecutable()} -f ${cfg.twineformat} --head=${cfg.sources.head} -o ${path.join(cfg.dirs.intermediate, htmlOut)} ${moduleArgs.join(' ')} ${sources.join(' ')}`;
+}
+
 function concatFiles(srcGlob, destDir, destFileName) {
 	return gulp.src(srcGlob)
 		.pipe(sort())
@@ -126,18 +135,7 @@ function cleanupGit(cb) {
 	}
 }
 
-function compileStory() {
-	let sources = [path.join(cfg.dirs.intermediate, "story")];
-	sources.push(...cfg.sources.story.media);
-
-	let modules = [path.join(cfg.dirs.intermediate, "module")];
-	let moduleArgs = modules.map(fn => `--module=${fn}`);
-	const cmdLine = `${tweeCompilerExecutable()} -f ${cfg.twineformat} --head=${cfg.sources.head} -o ${path.join(cfg.dirs.intermediate, htmlOut)} ${moduleArgs.join(' ')} ${sources.join(' ')}`;
-
-	log.info(cmdLine);
-	return gulp.src(sources, {read: false})
-		.pipe(shell(cmdLine, {env: cfg.options.twee.environment}));
-}
+gulp.task('compileStory', shell.task(tweeCompileCommand(), {env: cfg.options.twee.environment, verbose: true}));
 
 const processors = {
 	"css": {
@@ -189,9 +187,9 @@ function prepare(cb) {
 }
 
 if (fs.statSync('.git').isDirectory()) {
-	gulp.task('buildHTML', gulp.series(prepare, compileStory, cleanupGit));
+	gulp.task('buildHTML', gulp.series(prepare, 'compileStory', cleanupGit));
 } else {
-	gulp.task('buildHTML', gulp.series(prepare, compileStory));
+	gulp.task('buildHTML', gulp.series(prepare, 'compileStory'));
 }
 
 exports.clean = clean;
-- 
GitLab