Skip to content

Commit c9041a0

Browse files
improve file processor
1 parent 83aba8b commit c9041a0

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

src/Processor/Processor.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,26 @@ public function attachFiles($inputPath, $outputPath)
7676
}
7777
}
7878

79+
/**
80+
* @return File[]
81+
*/
82+
public function getFiles()
83+
{
84+
return $this->files;
85+
}
86+
7987
/**
8088
* @return string[]
8189
*/
82-
public function concatOutput()
90+
protected function concatOutput()
8391
{
8492
$outputMap = [];
8593
foreach ($this->files as $file) {
8694
if (!isset($outputMap[$file->getOutputPath()])) {
87-
$outputMap[$file->getOutputPath()] = $file->getParsedContent();
88-
} else {
89-
$outputMap[$file->getOutputPath()] .= $file->getParsedContent();
95+
$outputMap[$file->getOutputPath()] = '';
9096
}
97+
98+
$outputMap[$file->getOutputPath()] .= $file->getParsedContent();
9199
}
92100

93101
return $outputMap;
@@ -117,26 +125,39 @@ public function saveOutput()
117125
*/
118126
public function processFiles($formatter)
119127
{
128+
$this->sass->setFormatter($this->getFormatterClass($formatter));
129+
$this->io->write("<info>use '{$formatter}' formatting</info>");
130+
120131
foreach ($this->files as $file) {
121132
$this->io->write("<info>processing</info>: {$file->getSourcePath()}");
122133
$file->setSourceContentFromSourcePath();
123134

124-
switch ($file->getType()) {
125-
case File::TYPE_COMPASS:
126-
case File::TYPE_SCSS:
127-
case File::TYPE_SASS:
128-
$this->sass->setFormatter($this->getFormatterClass($formatter));
129-
$content = $this->sass->compile($file->getSourceContent());
130-
break;
131-
case File::TYPE_LESS:
132-
$content = $this->less->compile($file->getSourceContent());
133-
break;
134-
default:
135-
throw new CompilerException('unknown compiler');
135+
try {
136+
$this->processFile($file);
137+
} catch (CompilerException $e) {
138+
$this->io->writeError("<error>failed to process: {$file->getSourcePath()}</error>");
136139
}
140+
}
141+
}
137142

138-
$file->setParsedContent($content);
143+
/**
144+
* @param File $file
145+
*
146+
* @return File
147+
* @throws CompilerException
148+
*/
149+
public function processFile(File $file)
150+
{
151+
switch ($file->getType()) {
152+
case File::TYPE_COMPASS:
153+
case File::TYPE_SCSS:
154+
case File::TYPE_SASS:
155+
return $file->setParsedContent($this->sass->compile($file->getSourceContent()));
156+
case File::TYPE_LESS:
157+
return $file->setParsedContent($this->less->compile($file->getSourceContent()));
139158
}
159+
160+
throw new CompilerException('unknown compiler');
140161
}
141162

142163
/**

0 commit comments

Comments
 (0)