Skip to content

Commit 8b9ddc6

Browse files
committed
Refactor code
1 parent 3422d65 commit 8b9ddc6

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Paths to bridge.js and Node are specified only through the constructor:
167167
$compiler = new Compiler('/path/to/bridge.js', '/path/to/node');
168168
```
169169

170-
| Option | Type | Description | Possible values |
170+
| Parameter | Type | Description | Possible values |
171171
|--------|------|-------------|-----------------|
172172
| syntax | string | Input syntax | 'scss' for SCSS, 'indented' or 'sass' for SASS |
173173
| style | string | Output style | 'compressed' or 'expanded' |

src/Compiler.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,30 +150,31 @@ protected function runCompile(array $payload): string
150150

151151
protected function processSourceMap(array $sourceMap, array $options): string
152152
{
153-
if (! empty($options['sourceMapPath'])) {
154-
$mapFile = (string) $options['sourceMapPath'];
155-
156-
$isUrl = filter_var($mapFile, FILTER_VALIDATE_URL) !== false;
157-
if ($isUrl) {
158-
$sourceMappingUrl = $mapFile;
159-
} else {
160-
if (is_dir($mapFile)) {
161-
$sourceFilename = $this->getSourceFilenameFromUrl($options['url'] ?? '');
162-
$mapFile .= DIRECTORY_SEPARATOR . $sourceFilename . '.map';
163-
} elseif (strtolower(substr($mapFile, -4)) !== '.map') {
164-
$mapFile .= '.map';
165-
}
166-
167-
file_put_contents($mapFile, json_encode($sourceMap));
168-
$sourceMappingUrl = basename($mapFile);
169-
}
170-
171-
return "\n/*# sourceMappingURL=" . $sourceMappingUrl . " */";
172-
} else {
153+
if (empty($options['sourceMapPath'])) {
173154
$mapData = json_encode($sourceMap);
174155
$encodedMap = base64_encode($mapData);
156+
175157
return "\n/*# sourceMappingURL=data:application/json;base64," . $encodedMap . " */";
176158
}
159+
160+
$mapFile = (string) $options['sourceMapPath'];
161+
162+
$isUrl = filter_var($mapFile, FILTER_VALIDATE_URL) !== false;
163+
if ($isUrl) {
164+
$sourceMappingUrl = $mapFile;
165+
} else {
166+
if (is_dir($mapFile)) {
167+
$sourceFilename = $this->getSourceFilenameFromUrl($options['url'] ?? '');
168+
$mapFile .= DIRECTORY_SEPARATOR . $sourceFilename . '.map';
169+
} elseif (strtolower(substr($mapFile, -4)) !== '.map') {
170+
$mapFile .= '.map';
171+
}
172+
173+
file_put_contents($mapFile, json_encode($sourceMap));
174+
$sourceMappingUrl = basename($mapFile);
175+
}
176+
177+
return "\n/*# sourceMappingURL=" . $sourceMappingUrl . " */";
177178
}
178179

179180
protected function getSourceFilenameFromUrl(string $url): string

src/CompilerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public function getOptions(): array;
1111
public function compileString(string $source, array $options = []): string;
1212

1313
public function compileFile(string $filePath, array $options = []): string;
14+
15+
public function compileFileAndSave(string $inputPath, string $outputPath, array $options = []): bool;
1416
}

0 commit comments

Comments
 (0)