From 47e9044c3f63a02c8c5858d0a32861031126387c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 22 Mar 2022 19:40:18 +0100 Subject: [PATCH] Add the config files --- config/app.php | 80 ++++++ config/commands.php | 91 ++++++ config/hyde.php | 138 +++++++++ config/logo.php | 85 ++++++ config/torchlight.php | 92 ++++++ config/view.php | 12 + src/Commands/HydePublishConfigsCommand.php | 313 +++++++++++++++++++++ src/HydeServiceProvider.php | 5 +- 8 files changed, 815 insertions(+), 1 deletion(-) create mode 100644 config/app.php create mode 100644 config/commands.php create mode 100644 config/hyde.php create mode 100644 config/logo.php create mode 100644 config/torchlight.php create mode 100644 config/view.php create mode 100644 src/Commands/HydePublishConfigsCommand.php diff --git a/config/app.php b/config/app.php new file mode 100644 index 00000000..8aec1cc0 --- /dev/null +++ b/config/app.php @@ -0,0 +1,80 @@ + config('hyde.name', 'HydePHP'), + + /* + |-------------------------------------------------------------------------- + | Application Version + |-------------------------------------------------------------------------- + | + | This value determines the "version" your application is currently running + | in. You may want to follow the "Semantic Versioning" - Given a version + | number MAJOR.MINOR.PATCH when an update happens: https://semver.org. + | + */ + + 'version' => app('git.version'), + + /* + |-------------------------------------------------------------------------- + | Application Environment + |-------------------------------------------------------------------------- + | + | This value determines the "environment" your application is currently + | running in. This may determine how you prefer to configure various + | services the application utilizes. This can be overridden using + | the global command line "--env" option when calling commands. + | + | When using Hyde this setting should always be set to `production`. + | However, when developing the Hyde Core, set it to `development` + | in your .env to unlock the development commands. + | + */ + + 'env' => env('env', 'production'), + + /* + |-------------------------------------------------------------------------- + | Autoloaded Service Providers + |-------------------------------------------------------------------------- + | + | The service providers listed here will be automatically loaded on the + | request to your application. Feel free to add your own services to + | this array to grant expanded functionality to your applications. + | + */ + + 'providers' => [ + App\Providers\AppServiceProvider::class, + Hyde\Framework\HydeServiceProvider::class, + ], + + 'aliases' => [ + 'Hyde' => Hyde\Framework\Hyde::class, + ], + +]; diff --git a/config/commands.php b/config/commands.php new file mode 100644 index 00000000..0b2542ce --- /dev/null +++ b/config/commands.php @@ -0,0 +1,91 @@ + NunoMaduro\LaravelConsoleSummary\SummaryCommand::class, + + /* + |-------------------------------------------------------------------------- + | Commands Paths + |-------------------------------------------------------------------------- + | + | This value determines the "paths" that should be loaded by the console's + | kernel. Foreach "path" present on the array provided below the kernel + | will extract all "Illuminate\Console\Command" based class commands. + | + */ + + 'paths' => [app_path('Commands')], + + /* + |-------------------------------------------------------------------------- + | Added Commands + |-------------------------------------------------------------------------- + | + | You may want to include a single command class without having to load an + | entire folder. Here you can specify which commands should be added to + | your list of commands. The console's kernel will try to load them. + | + */ + + 'add' => [ + Hyde\Framework\Commands\BuildStaticSiteCommand::class, + Hyde\Framework\Commands\Debug::class, + Hyde\Framework\Commands\InspireCommand::class, + Hyde\Framework\Commands\MakePostCommand::class, + Hyde\Framework\Commands\MakeValidatorCommand::class, + Hyde\Framework\Commands\HydePublishViewsCommand::class, + Hyde\Framework\Commands\HydePublishConfigsCommand::class, + Hyde\Framework\Commands\Validate::class, + ], + + /* + |-------------------------------------------------------------------------- + | Hidden Commands + |-------------------------------------------------------------------------- + | + | Your application commands will always be visible on the application list + | of commands. But you can still make them "hidden" specifying an array + | of commands below. All "hidden" commands can still be run/executed. + | + */ + + 'hidden' => [ + NunoMaduro\LaravelConsoleSummary\SummaryCommand::class, + Symfony\Component\Console\Command\DumpCompletionCommand::class, + Symfony\Component\Console\Command\HelpCommand::class, + Illuminate\Console\Scheduling\ScheduleRunCommand::class, + Illuminate\Console\Scheduling\ScheduleListCommand::class, + Illuminate\Console\Scheduling\ScheduleFinishCommand::class, + LaravelZero\Framework\Commands\StubPublishCommand::class, + Hyde\Framework\Commands\MakeValidatorCommand::class, + Hyde\Framework\Commands\Debug::class, + ], + + /* + |-------------------------------------------------------------------------- + | Removed Commands + |-------------------------------------------------------------------------- + | + | Do you have a service provider that loads a list of commands that + | you don't need? No problem. Laravel Zero allows you to specify + | below a list of commands that you don't to see in your app. + | + */ + + 'remove' => [ + Illuminate\Console\Scheduling\ScheduleRunCommand::class, + ], + +]; diff --git a/config/hyde.php b/config/hyde.php new file mode 100644 index 00000000..822da0e8 --- /dev/null +++ b/config/hyde.php @@ -0,0 +1,138 @@ + 'HydePHP', + + + /* + |-------------------------------------------------------------------------- + | Features + |-------------------------------------------------------------------------- + | + | Some of Hyde's features are optional. Feel free to disable the features + | you don't need by removing or commenting them out from this array. + | This config concept is directly inspired by Laravel Jetstream. + | + */ + + 'features' => [ + Features::blogPosts(), + Features::bladePages(), + Features::markdownPages(), + Features::documentationPages(), + ], + + + /* + |-------------------------------------------------------------------------- + | Footer Text + |-------------------------------------------------------------------------- + | + | Most websites have a footer with copyright details and contact information. + | You probably want to change the Markdown to include your information, + | though you are of course welcome to keep the attribution link! + | + | You can also customize the blade view if you want a more complex footer. + | You can disable it completely by setting `enabled` to `false`. + | + */ + + 'footer' => [ + 'enabled' => true, + 'markdown' => 'Site built with the Free and Open Source [HydePHP](https://github.com/hydephp/hyde). + License [MIT](https://github.com/hydephp/hyde/blob/master/LICENSE.md).' + ], + + + /* + |-------------------------------------------------------------------------- + | Custom Navigation Menu Links + |-------------------------------------------------------------------------- + | + | If you are looking to add custom navigation menu links, this is the place! + | + | Linking to an external site? Supply the full URI to the 'destination'. + | Keeping it internal? Pass the 'slug' relative to the document root. + | + | To get started quickly, you can uncomment the defaults here. + | Tip: Only the title and slug parameters are required. + | + */ + + 'navigationMenuLinks' => [ + // [ + // 'title' => 'GitHub', + // 'destination' => 'https://github.com/hydephp/hyde', + // 'priority' => 1200, + // ], + // [ + // 'title' => 'Featured Blog Post', + // 'slug' => 'posts/hello-world', + // ] + ], + + + /* + |-------------------------------------------------------------------------- + | Navigation Menu Blacklist + |-------------------------------------------------------------------------- + | There may be pages you want to exclude from the automatic navigation menu, + | such as error pages. Add their slugs here and they will not be included. + | + */ + + 'navigationMenuBlacklist' => [ + '404' + ], + + + /* + |-------------------------------------------------------------------------- + | Documentation Sidebar Page Order + |-------------------------------------------------------------------------- + | + | In the generated Documentation pages the navigation links in the sidebar + | are sorted alphabetically by default. As this rarely makes sense, you + | can reorder the page slugs in the list and the links will be sorted + | in that order. Link items without an entry here will have fall + | back to the default priority of 999, putting them last. + | + */ + + 'documentationPageOrder' => [ + 'readme', + 'installation', + 'getting-started', + ] + +]; diff --git a/config/logo.php b/config/logo.php new file mode 100644 index 00000000..13bb28aa --- /dev/null +++ b/config/logo.php @@ -0,0 +1,85 @@ + true, + + /* + |-------------------------------------------------------------------------- + | Logo Name + |-------------------------------------------------------------------------- + | + | This value determines the text that is rendered for the logo. + | It defaults to the app name, but it can be any other text + | value if the logo should be different to the app name. + | + */ + 'name' => ' ' . config('app.name'), + + /* + |-------------------------------------------------------------------------- + | Default Font + |-------------------------------------------------------------------------- + | + | This option defines the font which should be used for rendering. + | By default, one default font is shipped. However, you are free + | to download and use additional fonts: http://www.figlet.org. + | + */ + + // 'font' => \LaravelZero\Framework\Components\Logo\FigletString::DEFAULT_FONT, + 'font' => base_path('vendor/hyde/framework/resources/fonts/smslant.flf'), + + /* + |-------------------------------------------------------------------------- + | Output Width + |-------------------------------------------------------------------------- + | + | This option defines the maximum width of the output string. This is + | used for word-wrap as well as justification. Be careful when using + | small values, because they may result in an undefined behavior. + | + */ + + 'outputWidth' => 80, + + /* + |-------------------------------------------------------------------------- + | Justification + |-------------------------------------------------------------------------- + | + | This option defines the justification of the logo text. By default, + | justification is provided, which will work well on most of your + | console apps. Of course, you are free to change this value. + | + */ + + 'justification' => null, + + /* + |-------------------------------------------------------------------------- + | Right To Left + |-------------------------------------------------------------------------- + | + | This option defines the option in which the text is written. By, default + | the setting of the font-file is used. When justification is not defined, + | a text written from right-to-left is automatically right-aligned. + | + | Possible values: "right-to-left", "left-to-right", null + | + */ + + 'rightToLeft' => null, + +]; diff --git a/config/torchlight.php b/config/torchlight.php new file mode 100644 index 00000000..00e07d24 --- /dev/null +++ b/config/torchlight.php @@ -0,0 +1,92 @@ + [ + 'enabled' => true, + 'markdown' => ' +

+ + Syntax highlighting by Torchlight.dev + +

' + ], + + // The Torchlight client caches highlighted code blocks. Here + // you can define which cache driver you'd like to use. If + // leave this blank your default app cache will be used. + 'cache' => env('TORCHLIGHT_CACHE_DRIVER'), + + // Cache blocks for 30 days. + 'cache_seconds' => env('TORCHLIGHT_CACHE_TTL', 60 * 60 * 24 * 30), + + // Which theme you want to use. You can find all the themes at + // https://torchlight.dev/docs/themes. + 'theme' => env('TORCHLIGHT_THEME', 'material-theme-palenight'), + + // If you want to use two separate themes for dark and light modes, + // you can use an array to define both themes. Torchlight renders + // both on the page, and you will be responsible for hiding one + // or the other depending on the dark / light mode via CSS. + // 'theme' => [ + // 'dark' => 'github-dark', + // 'light' => 'github-light', + // ], + + // Your API token from torchlight.dev. + 'token' => env('TORCHLIGHT_TOKEN'), + + // If you want to register the blade directives, set this to true. + 'blade_components' => true, + + // The Host of the API. + 'host' => env('TORCHLIGHT_HOST', 'https://api.torchlight.dev'), + + // We replace tabs in your code blocks with spaces in HTML. Set + // the number of spaces you'd like to use per tab. Set to + // `false` to leave literal tabs in the HTML. + 'tab_width' => 4, + + // If you pass a filename to the code component or in a markdown + // block, Torchlight will look for code snippets in the + // following directories. + 'snippet_directories' => [ + resource_path() + ], + + // Global options to control blocks-level settings. + // https://torchlight.dev/docs/options + 'options' => [ + // Turn line numbers on or off globally. + // 'lineNumbers' => false, + + // Control the `style` attribute applied to line numbers. + // 'lineNumbersStyle' => '', + + // Turn on +/- diff indicators. + // 'diffIndicators' => true, + + // If there are any diff indicators for a line, put them + // in place of the line number to save horizontal space. + // 'diffIndicatorsInPlaceOfLineNumbers' => true, + + // When lines are collapsed, this is the text that will + // be shown to indicate that they can be expanded. + // 'summaryCollapsedIndicator' => '...', + ] +]; diff --git a/config/view.php b/config/view.php new file mode 100644 index 00000000..1e7310c4 --- /dev/null +++ b/config/view.php @@ -0,0 +1,12 @@ + [ + Hyde\Framework\Hyde::viewPath(), + ], + + 'compiled' => env( + 'VIEW_COMPILED_PATH', + realpath(storage_path('framework/views')) + ), +]; diff --git a/src/Commands/HydePublishConfigsCommand.php b/src/Commands/HydePublishConfigsCommand.php new file mode 100644 index 00000000..3d1f9949 --- /dev/null +++ b/src/Commands/HydePublishConfigsCommand.php @@ -0,0 +1,313 @@ +files = $files; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $this->tags = array_flip(array_filter( + array_flip(ServiceProvider::publishableGroups()), + fn($key) => str_starts_with($key, 'configs'), + ARRAY_FILTER_USE_KEY + )); + + foreach ($this->tags ?: [null] as $tag) { + $this->publishTag($tag); + } + + $this->info('Publishing complete.'); + } + + /** + * Determine the provider or tag(s) to publish. + * + * @return void + */ + protected function determineWhatShouldBePublished() + { + if ($this->option('all')) { + + return; + } + + if (!$this->tags) { + $this->promptForProviderOrTag(); + } + } + + /** + * Prompt for which tag to publish. + * + * @return void + */ + protected function promptForProviderOrTag() + { + $choice = $this->choice( + "Which view categories (tags) would you like to publish?", + $choices = $this->publishableChoices() + ); + + if ($choice == $choices[0] || is_null($choice)) { + $this->tags = array_flip(array_filter( + array_flip(ServiceProvider::publishableGroups()), + fn($key) => str_starts_with($key, 'hyde-'), + ARRAY_FILTER_USE_KEY + )); + return; + } + + $this->parseChoice($choice); + } + + /** + * The choices available via the prompt. + * + * @return array + */ + protected function publishableChoices() + { + return array_merge( + ['Publish files from all tags listed below'], + preg_filter('/^/', 'Tag: ', Arr::sort( + array_flip(array_filter( + array_flip(ServiceProvider::publishableGroups()), + fn($key) => str_starts_with($key, 'hyde-'), + ARRAY_FILTER_USE_KEY + )) + )) + ); + } + + /** + * Parse the answer that was given via the prompt. + * + * @param string $choice + * @return void + */ + protected function parseChoice($choice) + { + [$type, $value] = explode(': ', strip_tags($choice)); + + if ($type === 'Provider') { + $this->provider = $value; + } elseif ($type === 'Tag') { + $this->tags = [$value]; + } + } + + /** + * Publishes the assets for a tag. + * + * @param string $tag + * @return mixed + */ + protected function publishTag($tag) + { + $published = false; + + $pathsToPublish = $this->pathsToPublish($tag); + + foreach ($pathsToPublish as $from => $to) { + $this->publishItem($from, $to); + + $published = true; + } + + if ($published === false) { + $this->comment('No publishable resources for tag ['.$tag.'].'); + } else { + $this->laravel['events']->dispatch(new VendorTagPublished($tag, $pathsToPublish)); + } + } + + /** + * Get all of the paths to publish. + * + * @param string $tag + * @return array + */ + protected function pathsToPublish($tag) + { + return ServiceProvider::pathsToPublish( + $this->provider, $tag + ); + } + + + /** + * Publish the given item from and to the given location. + * + * @param string $from + * @param string $to + * @return void + */ + protected function publishItem($from, $to) + { + if ($this->files->isFile($from)) { + return $this->publishFile($from, $to); + } elseif ($this->files->isDirectory($from)) { + return $this->publishDirectory($from, $to); + } + + $this->error("Can't locate path: <{$from}>"); + } + + /** + * Publish the file to the given path. + * + * @param string $from + * @param string $to + * @return void + */ + protected function publishFile($from, $to) + { + if (! $this->files->exists($to) || $this->option('force')) { + $this->createParentDirectory(dirname($to)); + + $this->files->copy($from, $to); + + $this->status($from, $to, 'File'); + } + } + + /** + * Publish the directory to the given directory. + * + * @param string $from + * @param string $to + * @return void + */ + protected function publishDirectory($from, $to) + { + $visibility = PortableVisibilityConverter::fromArray([], Visibility::PUBLIC); + + $this->moveManagedFiles(new MountManager([ + 'from' => new Flysystem(new LocalAdapter($from)), + 'to' => new Flysystem(new LocalAdapter($to, $visibility)), + ])); + + $this->status($from, $to, 'Directory'); + } + + /** + * Move all the files in the given MountManager. + * + * @param \League\Flysystem\MountManager $manager + * @return void + */ + protected function moveManagedFiles($manager) + { + foreach ($manager->listContents('from://', true) as $file) { + $path = Str::after($file['path'], 'from://'); + + if ($file['type'] === 'file' && (! $manager->fileExists('to://'.$path) || $this->option('force'))) { + $manager->write('to://'.$path, $manager->read($file['path'])); + } + } + } + + /** + * Create the directory to house the published files if needed. + * + * @param string $directory + * @return void + */ + protected function createParentDirectory($directory) + { + if (! $this->files->isDirectory($directory)) { + $this->files->makeDirectory($directory, 0755, true); + } + } + + /** + * Write a status message to the console. + * + * @param string $from + * @param string $to + * @param string $type + * @return void + */ + protected function status($from, $to, $type) + { + $from = str_replace(base_path(), '', realpath($from)); + + $to = str_replace(base_path(), '', realpath($to)); + + $this->line('Copied '.$type.' ['.$from.'] To ['.$to.']'); + } +} diff --git a/src/HydeServiceProvider.php b/src/HydeServiceProvider.php index 11dad424..9a3846d1 100644 --- a/src/HydeServiceProvider.php +++ b/src/HydeServiceProvider.php @@ -14,7 +14,7 @@ class HydeServiceProvider extends ServiceProvider */ public function register() { - // + } /** @@ -28,6 +28,9 @@ public function boot() $this->loadViewsFrom(__DIR__.'/../resources/views', 'hyde'); + $this->publishes([ + __DIR__.'/../config' => config_path(''), + ], 'configs'); $this->publishes([ __DIR__.'/../resources/views/layouts' => resource_path('views/vendor/hyde/layouts'),