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

Cecilapp / Cecil / 15071523046

16 May 2025 03:05PM UTC coverage: 83.176%. First build
15071523046

Pull #2172

github

web-flow
Merge 7760cb5ce into c2631b992
Pull Request #2172: Build Command : Allow to partial build

14 of 17 new or added lines in 3 files covered. (82.35%)

3080 of 3703 relevant lines covered (83.18%)

0.83 hits per line

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

76.0
/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\Exception\RuntimeException;
17
use Cecil\Step\AbstractStep;
18
use Cecil\Util;
19
use Symfony\Component\Finder\Finder;
20

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

28
    protected $path = '';
29

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

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

47
        if (!empty($options['renderPath'])) {
1✔
NEW
48
            $this->path = $options['renderPath'];
×
49
        }
50

51
        // reset output directory
52
        if (empty($this->path)) {
1✔
53
            Util\File::getFS()->remove($this->config->getOutputPath());
1✔
54
            Util\File::getFS()->mkdir($this->config->getOutputPath());
1✔
55
        }
56

57
        $this->canProcess = true;
1✔
58
    }
59

60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function process(): void
64
    {
65
        $target = (string) $this->config->get('static.target');
1✔
66
        $exclude = (array) $this->config->get('static.exclude');
1✔
67

68
        // copying assets in debug mode (for source maps)
69
        if ($this->builder->isDebug() && $this->config->isEnabled('assets.compile.sourcemap')) {
1✔
70
            // copying content of '<theme>/assets/' dir if exists
71
            if ($this->config->hasTheme()) {
×
72
                $themes = array_reverse($this->config->getTheme());
×
73
                foreach ($themes as $theme) {
×
74
                    $this->copy($this->config->getThemeDirPath($theme, 'assets'));
×
75
                }
76
            }
77
            // copying content of 'assets/' dir if exists
78
            $this->copy($this->config->getAssetsPath());
×
79
            // cancel exclusion for static files (see below)
80
            $exclude = [];
×
81
        }
82

83
        // copying content of '<theme>/static/' dir if exists
84
        if ($this->config->hasTheme()) {
1✔
85
            $themes = array_reverse($this->config->getTheme());
1✔
86
            foreach ($themes as $theme) {
1✔
87
                $this->copy($this->config->getThemeDirPath($theme, 'static'), $target, $exclude);
1✔
88
            }
89
        }
90

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

94
        // copying mounts
95
        if ($this->config->get('static.mounts')) {
1✔
96
            foreach ((array) $this->config->get('static.mounts') as $source => $destination) {
1✔
97
                $this->copy(Util::joinFile($this->config->getStaticPath(), (string) $source), (string) $destination);
1✔
98
            }
99
        }
100

101
        if ($this->count === 0) {
1✔
102
            $this->builder->getLogger()->info('Nothing to copy');
×
103

104
            return;
×
105
        }
106
        $this->builder->getLogger()->info('Files copied', ['progress' => [$this->count, $this->count]]);
1✔
107
    }
108

109
    /**
110
     * Copying a file or files in a directory from $from (if exists) to $to (relative to output path).
111
     * Exclude files or directories with $exclude array.
112
     */
113
    protected function copy(string $from, ?string $to = null, ?array $exclude = null): void
114
    {
115
        try {
116
            if (Util\File::getFS()->exists($from)) {
1✔
117
                // copy a file
118
                if (is_file($from)) {
1✔
119
                    Util\File::getFS()->copy($from, Util::joinFile($this->config->getOutputPath(), $to), true);
1✔
120

121
                    return;
1✔
122
                }
123
                // copy a directory
124
                $finder = Finder::create()
1✔
125
                    ->files()
1✔
126
                    ->in($from)
1✔
127
                    ->ignoreDotFiles(false);
1✔
128
                // exclude files or directories
129
                if (\is_array($exclude)) {
1✔
130
                    $finder->notPath($exclude);
1✔
131
                    $finder->notName($exclude);
1✔
132
                }
133
                $this->count += $finder->count();
1✔
134
                Util\File::getFS()->mirror(
1✔
135
                    $from,
1✔
136
                    Util::joinFile($this->config->getOutputPath(), $to ?? ''),
1✔
137
                    $finder,
1✔
138
                    ['override' => true]
1✔
139
                );
1✔
140
            }
141
        } catch (\Exception $e) {
×
142
            throw new RuntimeException(\sprintf('Error during static files copy: %s', $e->getMessage()));
×
143
        }
144
    }
145
}
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