From d3972ea14af590a78c8360b3dd55549d083f805e Mon Sep 17 00:00:00 2001
From: Grzegorz Rola <grola@seostudio.pl>
Date: Mon, 16 Aug 2021 12:16:58 +0000
Subject: [PATCH] Feature/no dev

---
 CHANGELOG.md                                  |  4 ++++
 src/ActivationReminder/Composer/Plugin.php    |  4 +++-
 .../PrepareActivationReminderCommand.php      | 23 +++++++++++++++----
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 529bf17..61e1228 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## [1.1.0] - 2021-08-16
+### Added
+- no-dev option handling
+
 ## [1.0.2] - 2021-08-12
 ### Added
 - Popup
diff --git a/src/ActivationReminder/Composer/Plugin.php b/src/ActivationReminder/Composer/Plugin.php
index 8e2cd87..98c63a3 100644
--- a/src/ActivationReminder/Composer/Plugin.php
+++ b/src/ActivationReminder/Composer/Plugin.php
@@ -82,7 +82,9 @@ class Plugin implements PluginInterface, Capable, EventSubscriberInterface {
 	 * @param Event $event
 	 */
 	public function generateReminder(Event $event) {
-		passthru("composer prepare-activation-reminder" );
+		global $argv;
+		$arg = in_array( '--no-dev', $argv, true ) ? '--no-dev' : '';
+		passthru("composer prepare-activation-reminder $arg" );
 	}
 
 }
diff --git a/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php b/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php
index 62e0e3e..7d083ae 100644
--- a/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php
+++ b/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php
@@ -19,7 +19,8 @@ class PrepareActivationReminderCommand extends BaseCommand
     {
         $this
             ->setName('prepare-activation-reminder')
-            ->setDescription('Prepares activation reminder for WP Desk plugin.');
+            ->setDescription('Prepares activation reminder for WP Desk plugin.')
+            ->addOption( 'no-dev' );
     }
 
     /**
@@ -54,11 +55,24 @@ class PrepareActivationReminderCommand extends BaseCommand
 		    $this->prepare_class( $random_class . $random_letter, $target_file, $popup_javascript_file, $popup_css_file, $settings );
 	    }
 
-	    $this->regenerate_autoload( $target_file );
+	    $this->regenerate_autoload( $target_file, $input );
 
 	    $output->writeln( "Activation reminder created." );
     }
 
+    private function create_or_get_target_file_name( array $class_map, $random_class, $random_letter ) {
+    	$target_file_store = 'vendor/wpdesk/wp-wpdesk-activation-reminder/target-file';
+    	if ( ! file_exists( $target_file_store ) ) {
+		    $target_file = $class_map[ $random_class ];
+		    $target_file = str_replace( '.php', $random_letter . '.php', $target_file );
+		    $target_file = str_replace( getcwd() . '/vendor/composer/../../', '', $target_file );
+
+		    file_put_contents( $target_file_store, $target_file );
+	    }
+
+    	return file_get_contents( $target_file_store );
+    }
+
     private function create_or_get_target_file_name( array $class_map, $random_class, $random_letter ) {
     	$target_file_store = 'vendor/wpdesk/wp-wpdesk-activation-reminder/target-file';
     	if ( ! file_exists( $target_file_store ) ) {
@@ -74,8 +88,9 @@ class PrepareActivationReminderCommand extends BaseCommand
 
 	/**
 	 * @param string $class_file
+	 * @param InputInterface $input
 	 */
-    private function regenerate_autoload( $class_file ) {
+    private function regenerate_autoload( $class_file, InputInterface $input ) {
 	    $composer = $this->getComposer();
 	    $config = $composer->getConfig();
 	    $localRepo = $composer->getRepositoryManager()->getLocalRepository();
@@ -88,7 +103,7 @@ class PrepareActivationReminderCommand extends BaseCommand
 	    $autoload['files'][] = $class_file;
 	    $package->setAutoload( $autoload );
 
-	    $composer->getAutoloadGenerator()->setDevMode( true );
+	    $composer->getAutoloadGenerator()->setDevMode( ! $input->getOption( 'no-dev' ) );
 	    $composer->getAutoloadGenerator()->dump( $config, $localRepo, $package, $installationManager, 'composer', $optimize );
     }
 
-- 
GitLab