Skip to content

Commit 868cd9f

Browse files
author
Eugene Matvejev
authored
Merge pull request #1 from eugene-matvejev/master
1.0.0-beta1
2 parents 183b936 + 2cafd93 commit 868cd9f

19 files changed

+3323
-1
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 learn-symfony
3+
Copyright (c) 2016 Eugene Matvejev
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

ScriptHandler.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace EM\CssCompiler\Handler;
4+
5+
use Composer\Script\Event;
6+
use EM\CssCompiler\Processor\Processor;
7+
8+
class ScriptHandler
9+
{
10+
public static function compileCSS(Event $event)
11+
{
12+
$extras = $event->getComposer()->getPackage()->getExtra();
13+
14+
if (!isset($extras['css-compiler'])) {
15+
throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.css-compiler setting.');
16+
}
17+
18+
$configs = $extras['css-compiler'];
19+
20+
if (!is_array($configs)) {
21+
throw new \InvalidArgumentException('The extra.css-compiler setting must be an array of a configuration objects.');
22+
}
23+
24+
if (array_keys($configs) !== range(0, count($configs) - 1)) {
25+
$configs = [$configs];
26+
}
27+
28+
$processor = new Processor($event->getIO());
29+
30+
exec('rm -rf ' . __DIR__ . '/var/*');
31+
32+
foreach ($configs as $config) {
33+
if (!is_array($config)) {
34+
throw new \InvalidArgumentException('The extra.css-compiler should contain only configuration objects.');
35+
}
36+
37+
foreach ($config['input'] as $item => $value) {
38+
$processor->attachFiles(__DIR__ . "/{$value}", __DIR__ . "/{$config['output']}");
39+
}
40+
41+
$processor->processFiles($config['format'] ?? 'compact');
42+
}
43+
44+
$processor->saveOutput();
45+
}
46+
}

composer.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
"leafo/scssphp-compass": "dev-master"
28+
},
29+
"require-dev": {
30+
"composer/composer": "^1.1",
31+
"phpunit/phpunit": "^5.4"
32+
},
33+
"minimum-stability": "dev",
34+
"scripts": {
35+
"post-update-cmd": "@custom-events",
36+
"post-install-cmd": "@custom-events",
37+
"custom-events": [
38+
"EM\\CssCompiler\\Handler\\ScriptHandler::compileCSS"
39+
]
40+
},
41+
"config": {
42+
"bin-dir": "bin/"
43+
},
44+
"extra": {
45+
"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+
},
62+
{
63+
"format": "compact",
64+
"input": [
65+
"tests/shared-fixtures/compass/app.scss"
66+
],
67+
"output": "var/cache/assets/compass.css"
68+
}
69+
]
70+
}
71+
}

0 commit comments

Comments
 (0)