diff --git a/app/Console/Commands/FissionInstall.php b/app/Console/Commands/FissionInstall.php new file mode 100644 index 0000000..c42a5cd --- /dev/null +++ b/app/Console/Commands/FissionInstall.php @@ -0,0 +1,192 @@ +detectEnvironment(function () { + return 'local'; + }); + + info('Starting Fission installation...'); + + $this->copyAuthJson(); + + // Run npm install + if (! File::exists('node_modules')) { + info('Running npm install...'); + exec('npm install'); + } else { + warning('Node modules already exist. Skipping npm install.'); + } + + // Run flux:activate only if auth.json doesn't exist + if (! $this->authJsonExists) { + info('Activating Flux...'); + $this->call('flux:activate'); + } else { + info('auth.json found. Skipping Flux manual activation.'); + } + + $this->setupEnvFile(); + $this->reloadEnvironment(); + $this->generateAppKey(); + $this->runMigrations(); + $this->installPan(); + $this->setProjectName(); + + $this->cleanup(); + + info('Fission installation completed successfully! ☢️'); + info('👉 Run `php artisan solo` or `composer run dev` to start the local server.'); + info('Keep creating. 🫡'); + } + + private function setupEnvFile() + { + info('Setting up .env file...'); + if (! File::exists('.env')) { + File::copy('.env.example', '.env'); + info('.env file created successfully.'); + } else { + warning('.env file already exists. Skipping creation.'); + } + + // Ensure APP_ENV is set to local + $envContent = File::get('.env'); + if (! preg_match('/^APP_ENV=/', $envContent)) { + $this->updateEnv('APP_ENV', 'local'); + info('APP_ENV set to local.'); + } else { + $envContent = preg_replace('/^APP_ENV=(.*)$/m', 'APP_ENV=local', $envContent); + $this->updateEnv('APP_ENV', 'local'); + info('APP_ENV updated to local.'); + } + } + + private function generateAppKey() + { + info('Checking application key...'); + if (empty(env('APP_KEY'))) { + $this->call('key:generate'); + } else { + warning('Application key already exists. Skipping.'); + } + } + + private function runMigrations() + { + if (confirm('Do you want to run database migrations?', true)) { + info('Running database migrations...'); + $this->call('migrate', [ + '--force' => true, // This will bypass the production check + ]); + } + } + + private function setProjectName() + { + $defaultName = $this->argument('name') ?: basename(getcwd()); + $name = text( + label: 'What is the name of your project?', + placeholder: $defaultName, + default: $defaultName, + required: true + ); + + $this->updateEnv('APP_NAME', $name); + + $defaultUrl = 'http://localhost:8000'; + $url = text( + label: 'What is the URL of your project?', + placeholder: $defaultUrl, + default: $defaultUrl, + required: true + ); + + $this->updateEnv('APP_URL', $url); + } + + private function updateEnv($key, $value) + { + $path = base_path('.env'); + + if (File::exists($path)) { + file_put_contents($path, preg_replace( + "/^{$key}=.*/m", + "{$key}=\"{$value}\"", + file_get_contents($path) + )); + } + } + + private function cleanup() + { + if (confirm('Do you want to remove the installation files?', true)) { + info('Removing installation files...'); + + // Remove the entire Commands folder + File::deleteDirectory(app_path('Console')); + + // Remove the install.sh script + File::delete(base_path('install.sh')); + + info('Installation files removed.'); + } else { + info('Installation files kept. You can manually remove them later if needed.'); + } + } + + private function reloadEnvironment() + { + $app = app(); + $app->bootstrapWith([ + \Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class, + ]); + } + + private function installPan() + { + $this->call('install:pan'); + } + + private function copyAuthJson() + { + $sourceAuthJson = $_SERVER['HOME'].'/Code/flux-auth.json'; + $destinationAuthJson = base_path('auth.json'); + + if (File::exists($sourceAuthJson)) { + info('Found auth.json in ~/Code/ directory. Copying to application...'); + File::copy($sourceAuthJson, $destinationAuthJson); + info('auth.json copied successfully.'); + + // Run composer install again to ensure Flux Pro is properly installed + info('Running composer install to activate Flux Pro...'); + exec('composer install'); + info('Flux Pro activated.'); + + $this->authJsonExists = true; + } else { + warning('No preset auth.json found. You can add your credentials for Flux in a bit.'); + $this->authJsonExists = false; + } + } +} diff --git a/database/migrations/2024_11_12_163449_create_pan_analytics_table.php b/database/migrations/2024_11_12_163449_create_pan_analytics_table.php deleted file mode 100644 index 6a38f65..0000000 --- a/database/migrations/2024_11_12_163449_create_pan_analytics_table.php +++ /dev/null @@ -1,31 +0,0 @@ -id(); - $table->string('name'); - - $table->unsignedBigInteger('impressions')->default(0); - $table->unsignedBigInteger('hovers')->default(0); - $table->unsignedBigInteger('clicks')->default(0); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('pan_analytics'); - } -}; diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..b342b9e --- /dev/null +++ b/install.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Ensure script is run from the project root +if [ ! -f "composer.json" ]; then + echo "Please run this script from the project root directory." + exit 1 +fi + +# Run composer install +echo "Installing Composer dependencies..." +composer install + +# Run the Fission installation +php artisan fission:install diff --git a/package-lock.json b/package-lock.json index d1f0d76..64b81ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "clouddemo", + "name": "fission", "lockfileVersion": 3, "requires": true, "packages": {