Skip to content

Commit

Permalink
Installation Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jiten14 committed Sep 9, 2024
1 parent 66d8639 commit a6f106b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/Commands/JitoneAiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ public function handle(): int
$this->info('JitoneAi package has been set up successfully!');
$this->info('Please review the configuration file at config/jitone-ai.php');

// Ask to star the repo
if ($this->confirm('Would you like to star our repo on GitHub?', true)) {
$repoUrl = 'https://github.com/jiten14/jitone-ai';
$this->info("Thanks! You can star the repo here: {$repoUrl}");

if (PHP_OS_FAMILY === 'Darwin') {
exec("open {$repoUrl}");
} elseif (PHP_OS_FAMILY === 'Windows') {
exec("start {$repoUrl}");
} elseif (PHP_OS_FAMILY === 'Linux') {
exec("xdg-open {$repoUrl}");
}
}

return self::SUCCESS;
}
}
38 changes: 28 additions & 10 deletions src/JitoneAiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Jiten14\JitoneAi\Forms\Actions\GenerateContentAction;
use Jiten14\JitoneAi\Services\OpenAIService;
use Jiten14\JitoneAi\Services\ImageGenerationService;
use Spatie\LaravelPackageTools\Commands\InstallCommand;

class JitoneAiServiceProvider extends PackageServiceProvider
{
Expand All @@ -23,15 +22,34 @@ public function configurePackage(Package $package): void
$package
->name(static::$name)
->hasConfigFile()
->hasCommand(JitoneAiCommand::class)
->hasInstallCommand(function (InstallCommand $command) {
$command
->startWith(function (InstallCommand $command) {
$command->call('jitone-ai:install');
})
->publishConfigFile()
->askToStarRepoOnGitHub('jiten14/jitone-ai');
});
->hasCommand(JitoneAiCommand::class);

// Register a post-install hook
$this->app->booted(function () {
$this->registerPostInstallHook();
});
}

protected function registerPostInstallHook()
{
if ($this->app->runningInConsole()) {
$composerJson = json_decode(file_get_contents(base_path('composer.json')), true);
$scripts = $composerJson['scripts'] ?? [];

if (!isset($scripts['post-autoload-dump'])) {
$scripts['post-autoload-dump'] = [];
}

if (!in_array('@php artisan jitone-ai:install', $scripts['post-autoload-dump'])) {
$scripts['post-autoload-dump'][] = '@php artisan jitone-ai:install';
$composerJson['scripts'] = $scripts;

file_put_contents(
base_path('composer.json'),
json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
}
}

public function packageRegistered(): void
Expand Down

0 comments on commit a6f106b

Please sign in to comment.