Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
10 / 15
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AssetController
66.67% covered (warning)
66.67%
10 / 15
66.67% covered (warning)
66.67%
2 / 3
10.37
0.00% covered (danger)
0.00%
0 / 1
 watch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 build
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 runAssetCommand
61.54% covered (warning)
61.54%
8 / 13
0.00% covered (danger)
0.00%
0 / 1
8.05
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/pop-bootstrap
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Kettle\Controller;
16
17use Pop\Kettle\Model;
18
19/**
20 * Console asset controller class
21 *
22 * @category   Pop\Kettle
23 * @package    Pop\Kettle
24 * @author     Nick Sagona, III <nick@popphp.org>
25 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
26 * @license    https://www.popphp.org/license     New BSD License
27 * @version    3.0.0
28 */
29class AssetController extends AbstractController
30{
31
32    /**
33     * Watch command
34     *
35     * @return void
36     */
37    public function watch(): void
38    {
39        $this->runAssetCommand('watch');
40    }
41
42    /**
43     * Build command
44     *
45     * @return void
46     */
47    public function build(): void
48    {
49        $this->runAssetCommand('build');
50    }
51
52    /**
53     * Run an asset command (watch/build) after validating the project state
54     *
55     * @param  string $action
56     * @return void
57     */
58    protected function runAssetCommand(string $action): void
59    {
60        $location = getcwd();
61        $asset    = new Model\Asset();
62
63        if (!$asset->isInstalled($location)) {
64            $this->console->write('No front-end has been installed for this project.');
65            return;
66        }
67        if (!$asset->isNpmAvailable()) {
68            $this->console->write('Node/npm was not found on your PATH.');
69            return;
70        }
71
72        match ($action) {
73            'watch' => $asset->watch($location),
74            'build' => $asset->build($location),
75            default => null,
76        };
77    }
78
79}