Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Add runTask. #14

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Release Notes

## [Unreleased](https://github.com/surgiie/blade-cli/compare/v3.1.0...master)
## [Unreleased](https://github.com/surgiie/blade-cli/compare/v3.2.0...master)

## [v3.2.0](https://github.com/surgiie/blade-cli/compare/v3.1.0...v3.2.0) - 2022-11-14
- Bring back `runTask` not that flicker is fixed by @surgiie in https://github.com/surgiie/blade-cli/pull/14
## [v3.1.0](https://github.com/surgiie/blade-cli/compare/v3.0.0...v3.1.0) - 2022-11-09
- Remove `runTask` usages and update surgiie/console due to overhead and bad flicker from spinner process by @surgiie in https://github.com/surgiie/blade-cli/pull/12

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ You may install the binary via composer globally:

Then be sure the global composer packages path is executable:

*Note* The pctnl extension is recommended to be installed, otherwise install with `composer global require surgiie/blade-cli --ignore-platform-reqs`

```bash
# may vary on systems:
export PATH=~/.config/composer/vendor/bin:$PATH
Expand Down
12 changes: 5 additions & 7 deletions app/Commands/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ class ClearCommand extends ConsoleCommand

public function handle()
{
$dir = config('app.compiled_path');

$fs = new Filesystem;

$fs->deleteDirectory($dir, preserve: true);

$this->components->info("Cleared $dir directory");
$this->runTask('Clear compiled files directory', function ($task) {
$dir = config('app.compiled_path');
$fs = new Filesystem;
$fs->deleteDirectory($dir, preserve: true);
}, finishedText: 'Cleared compiled files directory');
}
}
27 changes: 18 additions & 9 deletions app/Commands/RenderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function renderDirectoryFiles(string $path, array $variables, ?string
$fs = (new Filesystem);
$fs->deleteDirectory($saveToPath, preserve: true);

if (! $this->data->get('force', false) && ! $this->components->confirm("Are you sure you want to render ALL files in the $path directory?")) {
if (! $this->data->get('force', false) && ! $this->components->confirm("Are you sure you want to render ALL files in the '$path' directory?")) {
$this->exit('Canceled');
}

Expand Down Expand Up @@ -206,16 +206,26 @@ protected function renderFile(string $path, array $variables, string $saveTo)
$this->exit("The rendered file '$saveTo' already exists, use --force to overwrite.");
}

try {
$contents = $this->blade()->compile($path, $variables);
$this->components->info("Rendered $path to $saveTo");
} catch (\Exception $e) {
$this->components->error('Compile Error: '.$e->getMessage());
$task = $this->runTask("Render file $path to $saveTo", function ($task) use ($path, $variables, $saveTo) {
try {
$contents = $this->blade()->compile($path, $variables);

return file_put_contents($saveTo, $contents) !== false;
} catch (\Exception $e) {
$task->data(['exception' => $e]);

return false;
}

return file_put_contents($saveTo, $contents) !== false;
}, finishedText: "Rendered $saveTo");

$data = $task->getData();

if (! $task->succeeded() && $data['exception'] ?? false) {
$this->components->error('Compile Error: '.$data['exception']->getMessage());
$this->exit();
}

return file_put_contents($saveTo, $contents) !== false;
}

/**
Expand Down Expand Up @@ -267,7 +277,6 @@ protected function dryRun(string $path, array $variables = []): static
} else {
$files[] = $path;
}

foreach ($files as $file) {
$dryRun($file);
$this->newLine();
Expand Down
1 change: 1 addition & 0 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"files": [
"composer.json"

],
"exclude-dev-files": false,
"exclude-composer-files": false,
Expand Down
Binary file removed builds/blade
Binary file not shown.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"guzzlehttp/guzzle": "^7.4",
"illuminate/http": "^9.0",
"intonate/tinker-zero": "^1.2",
"surgiie/console": "^0.8.0"
"surgiie/console": "^0.13.0"
},
"require-dev": {
"laravel-zero/framework": "^9.2",
Expand Down