import {dest, series, src} from 'gulp'; import process from 'node:process'; import replace from 'gulp-replace'; import * as dartSass from 'sass'; import gulpSass from 'gulp-sass'; import {deleteAsync} from 'del'; import {readdirSync} from 'node:fs'; import {join} from 'node:path'; import {compilePack} from '@foundryvtt/foundryvtt-cli'; const sass = gulpSass(dartSass); function cleanDist() { return deleteAsync(['dist/**']); } function buildStyles() { return src('src/style/**/*.scss') .pipe(sass().on('error', sass.logError)) .pipe(dest('dist/style/')) } function copySource() { return src(['src/**/*', '!src/assets/**/*', '!src/style/**/*.scss', '!src/packs/**/*']) .pipe(dest('dist/')); } function copyAssets() { return src(['src/assets/**/*'], {encoding: false}) .pipe(dest('dist/assets/')) } function updateManifestFile() { return src('dist/system.json') .pipe(replace('{{VERSION}}', process.env.VERSION)) .pipe(dest('dist/')) } function buildDB() { // Determine which source folders to process const PACK_SRC = "src/packs/__source" const PACK_DEST = "dist/packs/" return new Promise(async (resolve, reject) => { const folders = readdirSync(PACK_SRC, {withFileTypes: true}).filter(file => file.isDirectory() ); for (const folder of folders) { const src = join(PACK_SRC, folder.name); const dest = join(PACK_DEST, folder.name); console.info(`Compiling pack ${folder.name}`); await compilePack(src, dest, {recursive: true, log: true, nedb: false}); } resolve() }) } export default series( cleanDist, copySource, copyAssets, buildStyles, buildDB, updateManifestFile )