@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
43 lines (34 loc) • 1.72 kB
JavaScript
const getConfig = require( '../../config' );
const { config } = getConfig();
const getPluginVersion = require( './get-plugin-version' );
const path = require( 'path' );
const fs = require( 'fs' ); // Import the filesystem module
async function getGoogleDriveConfig() {
const { slug, rootPluginSlug, googleDriveRootFolder, rootPluginFile } = config.settings;
const version = process.env.GRAVITY_PLUGIN_VERSION || getPluginVersion( config.paths.root, rootPluginFile );
const isMasterOrMain = process.env.GRAVITY_CURRENT_BRANCH === 'master' || process.env.GRAVITY_CURRENT_BRANCH === 'main';
let obj = {
path: '',
files: []
};
if ( googleDriveRootFolder ) {
obj.path = `${ googleDriveRootFolder }/${ isMasterOrMain ? 'Releases' : `Branches/${ process.env.GRAVITY_CURRENT_BRANCH }` }`;
} else if ( slug === 'gravityforms' ) {
obj.path = `Gravity Forms/${ isMasterOrMain ? 'Releases' : `Branches/${ process.env.GRAVITY_CURRENT_BRANCH }` }`;
} else {
obj.path = `Gravity Forms/Addons/${ rootPluginSlug }${ ! isMasterOrMain ? `/branches/${ process.env.GRAVITY_CURRENT_BRANCH }` : '' }`;
}
const basePath = path.join( config.paths.root, slug );
let potentialFiles = [
`${ basePath }_${ version }.zip`,
`${ basePath }_${ version }_wpcom.zip`,
];
// add checksum file path if the branch is master or main and GRAVITY_GULP_TASK is 'publish'
if ( isMasterOrMain && process.env.GRAVITY_GULP_TASK === 'publish' ) {
potentialFiles.push( path.join( config.paths.root, `checksums/${ slug }_${ version }.md5` ) );
}
// Filter the files array to only include existing files
obj.files = potentialFiles.filter( file => fs.existsSync( file ) );
return obj;
}
module.exports = getGoogleDriveConfig;