Skip to content

Commit

Permalink
✨ Add --path option in ckeditor4:install command
Browse files Browse the repository at this point in the history
  • Loading branch information
juliomotol committed Nov 5, 2020
1 parent df4d4b6 commit 6361651
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-ckeditor4` will be documented in this file

## 1.0.0 - 2022-09-30
## 1.1.0 - 2020-11-05

- Added `--path` option in `ckeditor4:install` command.

## 1.0.0 - 2020-09-30

- Initial Release!
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ php artisan vendor:publish --provider="JulioMotol\CKEditor4\CKEdtor4ServiceProvi
To publish the CKEditor4 assets, simply run the command:

```bash
# Install ckeditor in default path
php artisan ckeditor4:install

# Install ckeditor to a certain path
php artisan ckeditor4:install --path=public/foo/bar
```

CKEditor4 assets will be published in `./public/js/plugins/ckeditor4`. You can change the [config](#config) to modify the publish path.
> CKEditor4 assets will be published in `./public/js/plugins/ckeditor4` by default.
## Testing

Expand Down
12 changes: 9 additions & 3 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class InstallCommand extends Command
{
const SHOULD_OVERWRITE_QUESTION = 'CKEditor4 is already installed, do you want to overwrite the old installation?';

public $signature = 'ckeditor4:install';
public $signature = 'ckeditor4:install
{--path= : The publish path for the CKEditor4 assests}
{--force : Install CKEditor4 even if installation already exists}';

public $description = 'Install CKEditor4';

Expand All @@ -33,14 +35,18 @@ public function __construct(Filesystem $files)
parent::__construct();

$this->files = $files;
$this->publishPath = config('ckeditor4.publish_path');
$this->ckeditorVendorPath = base_path('vendor/ckeditor/ckeditor');
}

public function handle()
{
$this->publishPath = $this->option('path')
? base_path($this->option('path'))
: config('ckeditor4.publish_path');

if (
$this->files->exists($this->publishPath) &&
! $this->option('force') &&
! $this->confirm(self::SHOULD_OVERWRITE_QUESTION)
) {
return 1;
Expand All @@ -53,7 +59,7 @@ public function handle()
return 0;
}

public function installCKEditor4()
protected function installCKEditor4()
{
$this->files->makeDirectory($this->publishPath, 0755, true, true);

Expand Down
41 changes: 25 additions & 16 deletions tests/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ public function it_installs_ckeditor4()
$this->artisan('ckeditor4:install')
->assertExitCode(0);

$this->assertFileExists($publishPath . '/ckeditor.js');
$this->assertFileExists($publishPath . '/config.js');
$this->assertFileExists($publishPath . '/styles.js');
$this->assertFileExists($publishPath . '/contents.css');
$this->assertDirectoryExists($publishPath . '/adapters');
$this->assertDirectoryExists($publishPath . '/lang');
$this->assertDirectoryExists($publishPath . '/skins');
$this->assertDirectoryExists($publishPath . '/plugins');
$this->assertInstallation($publishPath);
}

/** @test */
public function it_installs_ckeditor4_to_custom_path()
{
$publishPath = 'public/js/ckeditor';

$this->artisan("ckeditor4:install --path={$publishPath}")
->assertExitCode(0);

$this->assertInstallation(base_path($publishPath));
}

/** @test */
Expand All @@ -57,13 +61,18 @@ public function it_overwrites_old_ckeditor4_installation()
->expectsConfirmation(InstallCommand::SHOULD_OVERWRITE_QUESTION, 'yes')
->assertExitCode(0);

$this->assertFileExists($publishPath . '/ckeditor.js');
$this->assertFileExists($publishPath . '/config.js');
$this->assertFileExists($publishPath . '/styles.js');
$this->assertFileExists($publishPath . '/contents.css');
$this->assertDirectoryExists($publishPath . '/adapters');
$this->assertDirectoryExists($publishPath . '/lang');
$this->assertDirectoryExists($publishPath . '/skins');
$this->assertDirectoryExists($publishPath . '/plugins');
$this->assertInstallation($publishPath);
}

private function assertInstallation($publishPath)
{
$this->assertFileExists("{$publishPath}/ckeditor.js");
$this->assertFileExists("{$publishPath}/config.js");
$this->assertFileExists("{$publishPath}/styles.js");
$this->assertFileExists("{$publishPath}/contents.css");
$this->assertDirectoryExists("{$publishPath}/adapters");
$this->assertDirectoryExists("{$publishPath}/lang");
$this->assertDirectoryExists("{$publishPath}/skins");
$this->assertDirectoryExists("{$publishPath}/plugins");
}
}

0 comments on commit 6361651

Please sign in to comment.