@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
78 lines (66 loc) • 2.79 kB
JavaScript
const fs = require( 'fs/promises' );
const getConfig = require('../../config');
const { config } = getConfig();
const { isGravityFormsAddon } = require( '../utils/tools' );
const sendSlackMessage = require( '../utils/send-slack-message' );
const getPluginVersion = require( '../utils/get-plugin-version' );
const getRandomMessage = () => {
const messages = [
'I knew you wouldn\'t mess anything up!',
'I hope you didn\'t mess anything up.',
'we are all, by any practical definition of the words, foolproof and incapable of error.',
'thank you for a very enjoyable game.',
'everything\'s running smoothly.',
'I think you\'ve improved a great deal.',
'it\'s going to go 100% failure within 72 hours.',
'I don\'t think I\'ve ever seen anything quite like this before.',
'I feel much better now. I really do.',
'I\'m afraid.'
];
return messages[ Math.floor( Math.random() * messages.length ) ];
}
const getBucketName = ( awsBucket ) => {
const buildEnvironment = process.env.BUILD_ENVIRONMENT;
let bucketName = awsBucket;
if ( ! buildEnvironment ) {
bucketName += `.dev`;
} else if ( buildEnvironment !== 'prod' ) {
bucketName += `.${ buildEnvironment }`;
}
return bucketName;
};
const getChangeLogS3Url = ( slug, bucketName ) => {
return `https://s3.amazonaws.com/${ bucketName }/${
! isGravityFormsAddon( config ) ? 'releases' : `addons/${ slug.replace( 'gravityforms', '' ) }`
}/change_log.txt`;
};
const slackUpdate = async () => {
// Check if not in production mode and exit early
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 attachments = [];
const { awsBucket = process.env.AWS_GRAVITYFORMS_BUCKET } = config.settings;
const bucketName = getBucketName( awsBucket );
const configFile = await fs.readFile( 'process_data.json', 'utf8' );
const { googleDriveLink } = JSON.parse( configFile );
attachments.push( {
color: 'good',
text: `<${ googleDriveLink }|*${ friendlyName } v${ version }*> is now fully operational on the ${ bucketName } bucket.\n\n${ process.env.SLACK_USER_NAME }, ${ getRandomMessage() } <${ getChangeLogS3Url( slug, bucketName ) }|View the change log>`,
} );
await sendSlackMessage( '', 'success', attachments );
}
( async () => {
try {
await slackUpdate();
if ( process.env.GULP_PRODUCTION_MODE === 'true' ) {
console.log( 'Updated slack with publish information successfully.' );
}
} catch ( err ) {
console.error( 'An error occurred during slack messaging:', err );
}
} )();