I'm trying to create a Gulp task script to process language-specific data files (resources/{lang}/data.json
), transform the data, and generate JSON files for each entry. When executing my Gulp tasks, no errors are reported, yet no files are being generated:
╰─❯ npx gulp
[14:21:29] Using gulpfile ~/repos/cemeteries/gulpfile.js
[14:21:29] Starting 'default'...
[14:21:29] Starting 'cleanCemeteryDir'...
[14:21:29] Finished 'cleanCemeteryDir' after 14 ms
[14:21:29] Starting 'generateContentFiles'...
[14:21:29] Starting 'bound generateContentFilesForLang'...
[14:21:29] Starting 'bound generateContentFilesForLang'...
[14:21:29] Finished 'bound generateContentFilesForLang' after 17
[14:21:29] Finished 'bound generateContentFilesForLang' after 21
[14:21:29] Finished 'generateContentFiles' after 22 ms
[14:21:29] Finished 'default' after 38 ms
File Friedhof-1.json created in content/de/friedhof
File Friedhof-2.json created in content/de/friedhof
File Cemetery-2.json created in content/en/cemetery
File Cemetery-2.json created in content/en/cemetery
...
╰─❯ ls content/en/cemetery
ls: cannot access 'content/en/cemetery': No such file or directory
Has anyone an idea, what the problem might be?
The corresponding gulpfile:
import gulp from 'gulp';
import jsonTransform from 'gulp-json-transform';
import rename from 'gulp-rename';
import slugify from 'slugify';
import clean from 'gulp-clean';
const languages = ['de', 'en'];
function cleanCemeteryDir() {
return gulp.src(['content/{en,de}/{friedhof,cemetery}'], { read: false, allowEmpty: true })
.pipe(clean({ force: true }));
}
function generateContentFilesForLang(lang) {
const slugs = new Set();
return gulp.src(`resources/${lang}/data.json`)
.pipe(jsonTransform((data, file) => {
const baseDir = `content/${lang}`;
const cemeteryDir = `${baseDir}/${lang === 'de' ? 'friedhof' : 'cemetery'}`;
return data.cemeteries.map(cemetery => {
const slug = slugify(cemetery.title);
const cemeteryData = {
...cemetery,
slug,
head: {
meta: [
{
hid: "description",
name: "description",
content: cemetery.description
}
]
}
};
const jsonFilename = `${slug}.json`;
// Save each cemetery as a separate JSON file
return gulp.src('dummy.json', { allowEmpty: true }) // Dummy source to trigger the task
.pipe(jsonTransform(() => [cemeteryData]))
.pipe(rename(jsonFilename))
.pipe(gulp.dest(cemeteryDir))
.on('end', () => console.log(`File ${jsonFilename} created in ${cemeteryDir}`))
});
});
}));
}
function generateContentFiles(done) {
const tasks = languages.map(lang => generateContentFilesForLang.bind(null, lang));
gulp.parallel(...tasks)(done);
}
export default gulp.series(cleanCemeteryDir, generateContentFiles);