UNPKG

@gravityforms/gulp-tasks

Version:
37 lines (28 loc) 1.15 kB
const findConfig = require( 'find-config' ); const defaultConfig = require( './src/defaults' ); 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 }; } module.exports = getConfig;