• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 13038372355

29 Jan 2025 06:54PM UTC coverage: 83.418% (-0.05%) from 83.465%
13038372355

push

github

ArnaudLigny
fix: do not exclude static copy if debug

5 of 6 new or added lines in 1 file covered. (83.33%)

38 existing lines in 1 file now uncovered.

2948 of 3534 relevant lines covered (83.42%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.57
/src/Step/StaticFiles/Copy.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Step\StaticFiles;
15

16
use Cecil\Step\AbstractStep;
17
use Cecil\Util;
18
use Symfony\Component\Finder\Finder;
19

20
/**
21
 * Copying static files to site root.
22
 */
23
class Copy extends AbstractStep
24
{
25
    protected $count = 0;
26

27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getName(): string
31
    {
32
        return 'Copying static';
1✔
33
    }
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function init(array $options): void
39
    {
40
        if ($options['dry-run']) {
1✔
41
            return;
×
42
        }
43

44
        // reset output directory
45
        Util\File::getFS()->remove($this->config->getOutputPath());
1✔
46
        Util\File::getFS()->mkdir($this->config->getOutputPath());
1✔
47

48
        $this->canProcess = true;
1✔
49
    }
50

51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function process(): void
55
    {
56
        $target = $this->config->get('static.target');
1✔
57
        $exclude = $this->config->get('static.exclude');
1✔
58

59
        // abord exclude if in debug mode + sourcemap
60
        if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap')) {
1✔
NEW
61
            $exclude = [];
×
62
        }
63

64
        // copying content of '<theme>/static/' dir if exists
65
        if ($this->config->hasTheme()) {
1✔
66
            $themes = array_reverse($this->config->getTheme());
1✔
67
            foreach ($themes as $theme) {
1✔
68
                $this->copy($this->config->getThemeDirPath($theme, 'static'), $target, $exclude);
1✔
69
            }
70
        }
71

72
        // copying content of 'static/' dir if exists
73
        $this->copy($this->config->getStaticPath(), $target, $exclude);
1✔
74

75
        // copying assets in debug mode (for source maps)
76
        if ($this->builder->isDebug() && (bool) $this->config->get('assets.compile.sourcemap')) {
1✔
77
            // copying content of '<theme>/assets/' dir if exists
78
            if ($this->config->hasTheme()) {
×
79
                $themes = array_reverse($this->config->getTheme());
×
80
                foreach ($themes as $theme) {
×
81
                    $this->copy(
×
82
                        $this->config->getThemeDirPath($theme, 'assets')
×
83
                    );
×
84
                }
85
            }
86
            // copying content of 'assets/' dir if exists
87
            $this->copy(
×
88
                $this->config->getAssetsPath()
×
89
            );
×
90
        }
91

92
        if ($this->count === 0) {
1✔
93
            $this->builder->getLogger()->info('Nothing to copy');
×
94

95
            return;
×
96
        }
97
        $this->builder->getLogger()->info('Files copied', ['progress' => [$this->count, $this->count]]);
1✔
98
    }
99

100
    /**
101
     * Copying (mirror) files.
102
     */
103
    protected function copy(string $from, ?string $to = null, ?array $exclude = null): bool
104
    {
105
        if (Util\File::getFS()->exists($from)) {
1✔
106
            $finder = Finder::create()
1✔
107
                ->files()
1✔
108
                ->in($from)
1✔
109
                ->ignoreDotFiles(false);
1✔
110
            if (\is_array($exclude)) {
1✔
111
                $finder->notPath($exclude);
1✔
112
                $finder->notName($exclude);
1✔
113
            }
114
            $this->count += $finder->count();
1✔
115
            Util\File::getFS()->mirror(
1✔
116
                $from,
1✔
117
                Util::joinFile($this->config->getOutputPath(), $to ?? ''),
1✔
118
                $finder,
1✔
119
                ['override' => true]
1✔
120
            );
1✔
121

122
            return true;
1✔
123
        }
124

125
        return false;
×
126
    }
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc