UNPKG

@gravityforms/gulp-tasks

Version:
40 lines (30 loc) 1.25 kB
import { createRequire } from 'node:module'; import defaultConfig from './src/defaults/index.js'; const cjsRequire = createRequire( import.meta.url ); const findConfig = cjsRequire( 'find-config' ); const configOpts = { module: true }; let cachedConfig = null; let cachedProjectId = null; function getConfig() { // Return the cached config if it has already been computed if ( cachedConfig && cachedProjectId ) { return { config: cachedConfig, projectId: cachedProjectId }; } // Setup current working directory based on the environment variable if ( process?.env?.PROJECT_DIR ) { configOpts.cwd = process.env.PROJECT_DIR; } // Load or require the project-specific configuration const configModule = findConfig.require( 'gravityforms.config', configOpts ); const projectConfig = configModule?.gulpConfig || {}; const projectId = configModule?.projectId || defaultConfig.gulpConfig.settings.slug; // Use the default configuration as the base and merge with project-specific configuration cachedConfig = { ...defaultConfig.gulpConfig, ...projectConfig, }; cachedProjectId = projectId; // Cache and return the configuration object return { config: cachedConfig, projectId: cachedProjectId }; } export default getConfig;