Completed
Pull Request — newinternal (#542)
by Simon
11:55 queued 02:00
created

RegenerateStylesheetsTask::execute()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 18
rs 9.9
cc 4
nc 8
nop 0
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\ConsoleTasks;
10
11
use Exception;
12
use ScssPhp\ScssPhp\Compiler;
13
use Waca\Tasks\ConsoleTaskBase;
14
use Waca\WebRequest;
15
16
class RegenerateStylesheetsTask extends ConsoleTaskBase
17
{
18
    const RESOURCES_GENERATED = 'resources/generated';
19
20
    public function execute()
21
    {
22
        $scss = new Compiler();
23
        $scss->setImportPaths('resources/scss');
24
25
        if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) {
26
            $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed');
27
            $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE);
28
        }
29
30
        if (!is_dir(self::RESOURCES_GENERATED)) {
31
            mkdir(self::RESOURCES_GENERATED);
32
        }
33
34
        foreach (['bootstrap-main', 'bootstrap-alt'] as $file) {
35
            file_put_contents(
36
                self::RESOURCES_GENERATED . '/' . $file . '.css',
37
                $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";'));
38
        }
39
    }
40
}
41