Skip to content

Commit 2cafd93

Browse files
author
Eugene Matvejev
authored
Merge pull request #1 from eugene-matvejev/rc1
RC1
2 parents 60dd22b + bbb6ac3 commit 2cafd93

File tree

16 files changed

+173
-229
lines changed

16 files changed

+173
-229
lines changed

ScriptHandler.php

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Composer\Script\Event;
66
use EM\CssCompiler\Processor\Processor;
7-
use Leafo\ScssPhp\Formatter\Compact;
87

98
class ScriptHandler
109
{
@@ -19,63 +18,29 @@ public static function compileCSS(Event $event)
1918
$configs = $extras['css-compiler'];
2019

2120
if (!is_array($configs)) {
22-
throw new \InvalidArgumentException('The extra.css-compiler setting must be an array or a configuration object.');
21+
throw new \InvalidArgumentException('The extra.css-compiler setting must be an array of a configuration objects.');
2322
}
2423

2524
if (array_keys($configs) !== range(0, count($configs) - 1)) {
2625
$configs = [$configs];
2726
}
2827

2928
$processor = new Processor($event->getIO());
30-
exec('rm -rf '. __DIR__ .'/var/*');
29+
30+
exec('rm -rf ' . __DIR__ . '/var/*');
31+
3132
foreach ($configs as $config) {
3233
if (!is_array($config)) {
33-
throw new \InvalidArgumentException('The extra.css-compiler setting must be an array of configuration objects.');
34+
throw new \InvalidArgumentException('The extra.css-compiler should contain only configuration objects.');
3435
}
3536

36-
$processor->resetFiles();
3737
foreach ($config['input'] as $item => $value) {
38-
/**
39-
"input": [
40-
"src/assets/scss"
41-
],
42-
*/
43-
$processor->attachFiles(__DIR__ . "/$value");
44-
}
45-
46-
// $formatter =
47-
switch ($config['format'] ?? 'compact') {
48-
case 'compressed':
49-
case 'crunched':
50-
case 'expanded':
51-
case 'nested':
52-
case 'compact':
53-
$formatter = 'Leafo\\ScssPhp\\Formatter\\' . ucfirst($config['format'] ?? 'compact');
54-
break;
55-
default:
56-
if (!is_array($config)) {
57-
throw new \InvalidArgumentException('there\'re avaliable options: if by default: compact');
58-
}
59-
60-
break;
38+
$processor->attachFiles(__DIR__ . "/{$value}", __DIR__ . "/{$config['output']}");
6139
}
6240

63-
$processor->processFiles($formatter);
64-
65-
$output = $processor->concatOutput();
66-
$outputPath = __DIR__ . "/var/${config['output']}";
67-
$outputDir = dirname($outputPath);
68-
if (!is_dir($outputDir)) {
69-
// if (file_exists($outputPath)) {
70-
// $outputDir = dirname($outputPath);
71-
if (!is_dir($dir = dirname($outputDir))) {
72-
// if (!is_dir($outputDir)) {
73-
mkdir($outputDir, 0755, true);
74-
// mkdir($outputDir, 0777);
75-
}
76-
}
77-
file_put_contents(__DIR__ .'/var/output.css', $output);
78-
file_put_contents($outputPath, $output);
41+
$processor->processFiles($config['format'] ?? 'compact');
7942
}
43+
44+
$processor->saveOutput();
8045
}
8146
}

composer.json

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
"php": ">= 7.0.4",
2525
"leafo/lessphp": "^0.5",
2626
"leafo/scssphp": "0.6.3 as dev-master",
27-
"phpunit/phpunit": "^5.4",
2827
"leafo/scssphp-compass": "dev-master"
2928
},
29+
"require-dev": {
30+
"composer/composer": "^1.1",
31+
"phpunit/phpunit": "^5.4"
32+
},
3033
"minimum-stability": "dev",
3134
"scripts": {
3235
"post-update-cmd": "@custom-events",
@@ -38,17 +41,30 @@
3841
"config": {
3942
"bin-dir": "bin/"
4043
},
41-
"require-dev": {
42-
"composer/composer": "^1.1"
43-
},
4444
"extra": {
4545
"css-compiler": [
46+
{
47+
"format": "compact",
48+
"force": true,
49+
"input": [
50+
"tests/shared-fixtures/scss"
51+
],
52+
"output": "var/cache/assets/scss.css"
53+
},
54+
{
55+
"format": "compact",
56+
"force": true,
57+
"input": [
58+
"tests/shared-fixtures/sass"
59+
],
60+
"output": "var/cache/assets/sass.css"
61+
},
4662
{
4763
"format": "compact",
4864
"input": [
49-
"src/assets/scss"
65+
"tests/shared-fixtures/compass/app.scss"
5066
],
51-
"output": "web/assets/app.css"
67+
"output": "var/cache/assets/compass.css"
5268
}
5369
]
5470
}

composer.phar

1.56 MB
Binary file not shown.

src/Container/File.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace EM\CssCompiler\Container;
44

5-
//use Symfony\Component\Yaml\Inline;
6-
//use Symfony\Component\Yaml\Parser;
7-
//use Symfony\Component\Yaml\Yaml;
5+
use EM\CssCompiler\Exception\FileException;
86

97
class File
108
{
11-
const TYPE_SCSS = 'scss';
12-
const TYPE_SASS = 'sass';
13-
const TYPE_LESS = 'less';
9+
const TYPE_SCSS = 'scss';
10+
const TYPE_SASS = 'sass';
11+
const TYPE_COMPASS = 'compass';
12+
const TYPE_LESS = 'less';
1413
/**
1514
* @var string
1615
*/
@@ -32,15 +31,10 @@ class File
3231
*/
3332
private $type;
3433

35-
// public function __construct(string $sourcePath, string $outputPath, string $sourceContent, string $parsedContent, string $type)
36-
public function __construct(string $sourcePath)
34+
public function __construct(string $sourcePath, string $outputPath)
3735
{
3836
$this->setSourcePath($sourcePath);
39-
// $this->sourcePath = $sourcePath;
40-
// $this->outputPath = $outputPath;
41-
// $this->sourceContent = $sourceContent;
42-
// $this->parsedContent = $parsedContent;
43-
// $this->type = $type ?: $this->type;
37+
$this->outputPath = $outputPath;
4438
}
4539

4640
public function getSourcePath() : string
@@ -80,6 +74,13 @@ public function setSourceContent(string $content) : self
8074
return $this;
8175
}
8276

77+
public function setSourceContentFromSourcePath() : self
78+
{
79+
$this->sourceContent = $this->readSourceContentByPath();
80+
81+
return $this;
82+
}
83+
8384
public function getParsedContent() : string
8485
{
8586
return $this->parsedContent;
@@ -113,11 +114,23 @@ private function detectSourceTypeFromPath(string $path)
113114
case 0 !== preg_match('/^.*\.' . static::TYPE_SASS . '/', $path):
114115
$this->type = static::TYPE_SASS;
115116
break;
117+
case 0 !== preg_match('/^.*\.' . static::TYPE_COMPASS . '/', $path):
118+
$this->type = static::TYPE_COMPASS;
119+
break;
116120
case 0 !== preg_match('/^.*\.' . static::TYPE_LESS . '/', $path):
117121
$this->type = static::TYPE_LESS;
118122
break;
119123
default:
120124
$this->type = 'unknown';
121125
}
122126
}
127+
128+
private function readSourceContentByPath()
129+
{
130+
if (!file_exists($this->getSourcePath())) {
131+
throw new FileException("file: {$this->sourcePath} doesn't exists");
132+
}
133+
134+
return file_get_contents($this->getSourcePath());
135+
}
123136
}

src/Exception/CompilerException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace EM\CssCompiler\Exception;
4+
5+
class CompilerException extends \Exception
6+
{
7+
}

src/Exception/FileException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace EM\CssCompiler\Exception;
4+
5+
class FileException extends \Exception
6+
{
7+
}

0 commit comments

Comments
 (0)