Skip to content

Commit

Permalink
Handle cases where the plugin folder already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
msaggiorato committed Jun 25, 2021
1 parent e13194e commit e4b7f5b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,23 @@ let pluginAuthorFull = pluginAuthor +' <'+ pluginAuthorEmail + '>';

let sourcePath = path.join( process.cwd(), 'source-' + (new Date()).getTime() );

let sourcePluginPath = path.join( sourcePath, pluginSlug );
var targetPluginPath = path.join( process.cwd(), path.basename( sourcePluginPath ) );
try {
statSync( targetPluginPath );
console.warn( "Plugin already exists." );
process.exit( 1 );
} catch( e ) {
// all good
}

rimraf.sync( sourcePath );

downloadGH( "saucal/WordPress-Plugin-Boilerplate#" + data.branch, sourcePath, function(err) {
if ( err ) {
throw err;
}

let sourcePluginPath = path.join( sourcePath, pluginSlug );
renameSync( path.join( sourcePath, 'plugin-name' ), sourcePluginPath );

walkDirectory( sourcePluginPath, function( f ) {
Expand Down Expand Up @@ -125,7 +134,7 @@ downloadGH( "saucal/WordPress-Plugin-Boilerplate#" + data.branch, sourcePath, fu
} );
} );

renameSync( sourcePluginPath, path.join( process.cwd(), path.basename( sourcePluginPath ) ) );
renameSync( sourcePluginPath, targetPluginPath );

rimraf.sync( sourcePath );
} );

0 comments on commit e4b7f5b

Please sign in to comment.