@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
26 lines (21 loc) • 713 B
JavaScript
const fs = require( 'fs' ); // Use fs for synchronous operations
const path = require( 'path' );
const extractVersion = ( fileContent ) => {
const versionRegex = /Version:\s*(\S+)/;
const match = fileContent.match( versionRegex );
if ( match && match[ 1 ] ) {
return match[ 1 ];
} else {
throw new Error( 'Version not found for the plugin.' );
}
};
const getPluginVersion = ( rootPath, fileName ) => {
const filePath = path.join( rootPath, fileName );
try {
const content = fs.readFileSync( filePath, { encoding: 'utf8' } );
return extractVersion( content );
} catch ( error ) {
console.error( `Error processing ${ filePath }: ${ error.message }` );
}
};
module.exports = getPluginVersion;