@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
46 lines (37 loc) • 1.57 kB
JavaScript
import fs from 'node:fs/promises';
import getConfig from '../../config.js';
import getPluginVersion from '../utils/get-plugin-version.js';
import sendSlackMessage from '../utils/send-slack-message.js';
import { isGravityFormsAddon } from '../utils/tools.js';
const { config } = getConfig();
const slackUpdate = async () => {
if ( process.env.GULP_PRODUCTION_MODE !== 'true' ) {
console.log( 'Skipping updating slack because GULP_PRODUCTION_MODE is not set to true.' );
return;
}
const { friendlyName, slug, rootPluginFile } = config.settings;
const version = process.env.GRAVITY_PLUGIN_VERSION || getPluginVersion( config.paths.root, rootPluginFile );
const branch = process.env.GRAVITY_CURRENT_BRANCH;
const isMasterOrMain = branch === 'master' || branch === 'main';
const attachments = [];
const configFile = await fs.readFile( 'process_data.json', 'utf8' );
const { googleDriveLink } = JSON.parse( configFile );
attachments.push( {
color: '#00f',
text: `<@${ process.env.SLACK_USER_ID }> I have built ${
isMasterOrMain ? '' : `the ${ branch } branch of ${ slug }: ${ ! isGravityFormsAddon( config ) ? '' : 'the ' }`
}<${ googleDriveLink }|*${ friendlyName } v${ version }*>`,
} );
await sendSlackMessage( '', 'success', attachments );
};
( async () => {
try {
await slackUpdate();
if ( process.env.GULP_PRODUCTION_MODE === 'true' ) {
console.log( 'Updated slack with build information successfully.' );
}
} catch ( err ) {
console.error( 'An error occurred during slack messaging:', err );
}
} )();