Skip to content

Commit 56d0e8b

Browse files
init commit
0 parents  commit 56d0e8b

19 files changed

+3399
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin/
2+
var/
3+
vendor/

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: php
2+
#
3+
#sudo: false
4+
#
5+
#cache:
6+
# directories:
7+
# - $HOME/.composer/cache/files
8+
#
9+
#matrix:
10+
# include:
11+
## - php: 5.6
12+
# - php: 7.0
13+
# - php: hhvm
14+
#
15+
#before_script:
16+
# - if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
17+
# - composer update $COMPOSER_FLAGS
18+
#
19+
#script: phpunit --coverage-text --coverage-clover=coverage.clover
20+
#
21+
#after_script:
22+
# - wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Eugene Matvejev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Whitespace-only changes.

ScriptHandler.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace EM\CssCompiler\Handler;
4+
5+
use Composer\Script\Event;
6+
use EM\CssCompiler\Processor\Processor;
7+
use Leafo\ScssPhp\Formatter\Compact;
8+
9+
class ScriptHandler
10+
{
11+
public static function compileCSS(Event $event)
12+
{
13+
$extras = $event->getComposer()->getPackage()->getExtra();
14+
15+
if (!isset($extras['css-compiler'])) {
16+
throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.css-compiler setting.');
17+
}
18+
19+
$configs = $extras['css-compiler'];
20+
21+
if (!is_array($configs)) {
22+
throw new \InvalidArgumentException('The extra.css-compiler setting must be an array or a configuration object.');
23+
}
24+
25+
if (array_keys($configs) !== range(0, count($configs) - 1)) {
26+
$configs = [$configs];
27+
}
28+
29+
$processor = new Processor($event->getIO());
30+
exec('rm -rf '. __DIR__ .'/var/*');
31+
foreach ($configs as $config) {
32+
if (!is_array($config)) {
33+
throw new \InvalidArgumentException('The extra.css-compiler setting must be an array of configuration objects.');
34+
}
35+
36+
$processor->resetFiles();
37+
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;
61+
}
62+
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);
79+
}
80+
}
81+
}

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "eugenematvejev/css_compiler",
3+
"description": "compiles css assets from sass or less on composer events",
4+
"type": "lib",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Eugene Matvejev",
9+
"email": "eugene.matvejev@gmail.com"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"EM\\CssCompiler\\Handler\\": "",
15+
"EM\\CssCompiler\\": "src/"
16+
}
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"EM\\Tests\\CssCompiler\\": "tests/"
21+
}
22+
},
23+
"require": {
24+
"php": ">= 7.0.4",
25+
"leafo/lessphp": "^0.5",
26+
"leafo/scssphp": "0.6.3 as dev-master",
27+
"phpunit/phpunit": "^5.4",
28+
"leafo/scssphp-compass": "dev-master"
29+
},
30+
"minimum-stability": "dev",
31+
"scripts": {
32+
"post-update-cmd": "@custom-events",
33+
"post-install-cmd": "@custom-events",
34+
"custom-events": [
35+
"EM\\CssCompiler\\Handler\\ScriptHandler::compileCSS"
36+
]
37+
},
38+
"config": {
39+
"bin-dir": "bin/"
40+
},
41+
"require-dev": {
42+
"composer/composer": "^1.1"
43+
},
44+
"extra": {
45+
"css-compiler": [
46+
{
47+
"format": "compact",
48+
"input": [
49+
"src/assets/scss"
50+
],
51+
"output": "web/assets/app.css"
52+
}
53+
]
54+
}
55+
}

0 commit comments

Comments
 (0)