UNPKG

@gravityforms/gulp-tasks

Version:
48 lines (43 loc) 1.77 kB
import fs from 'node:fs'; import path from 'node:path'; import { promisify } from 'node:util'; import { createRequire } from 'node:module'; import getConfig from '../../config.js'; import getPluginVersion from '../utils/get-plugin-version.js'; import sendSlackMessage from '../utils/send-slack-message.js'; const cjsRequire = createRequire( import.meta.url ); const gulp = cjsRequire( 'gulp' ); const hashsum = cjsRequire( 'gulp-hashsum' ); const rename = promisify( fs.rename ); const { config } = getConfig(); export default Object.assign( {}, { release() { const version = process.env.GRAVITY_PLUGIN_VERSION || getPluginVersion( config.paths.root, config.settings.rootPluginFile ); const checksumFilename = `${ config.settings.slug }_${ version }.md5`; const checksumDir = path.join( config.paths.root, 'checksums' ); const destPath = path.join( checksumDir, checksumFilename ); if ( ! fs.existsSync( checksumDir ) ) { fs.mkdirSync( checksumDir, { recursive: true } ); } return gulp.src( config?.checksum?.release?.src || [] ) .pipe( hashsum( { dest: config.paths.root, filename: checksumFilename, } ) ) .on( 'error', async function( err ) { console.error( 'Checksum creation error:', err ); await sendSlackMessage( `Failed to create checksums during build: ${ err }`, 'error' ); process.exit( 1 ); } ) .on( 'end', async () => { const srcPath = path.join( config.paths.root, checksumFilename ); try { await rename( srcPath, destPath ); console.log( `Checksum file moved to ${ destPath }` ); } catch ( err ) { await sendSlackMessage( `Failed to move checksums during build: ${ err }`, 'error' ); process.exit( 1 ); } } ); }, }, config?.tasks?.builtins?.checksum || {} );