mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 18:18:46 +02:00
⬇️ N°4824 rollback scssphp/scssphp update (won't be done in this branch !)
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SCSSPHP
|
||||
*
|
||||
* @copyright 2012-2020 Leaf Corcoran
|
||||
* @copyright 2012-2019 Leaf Corcoran
|
||||
*
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
*
|
||||
@@ -20,26 +19,26 @@ if (version_compare(PHP_VERSION, '5.6') < 0) {
|
||||
include __DIR__ . '/../scss.inc.php';
|
||||
|
||||
use ScssPhp\ScssPhp\Compiler;
|
||||
use ScssPhp\ScssPhp\Exception\SassException;
|
||||
use ScssPhp\ScssPhp\OutputStyle;
|
||||
use ScssPhp\ScssPhp\Parser;
|
||||
use ScssPhp\ScssPhp\Version;
|
||||
|
||||
$style = null;
|
||||
$loadPaths = [];
|
||||
$loadPaths = null;
|
||||
$precision = null;
|
||||
$dumpTree = false;
|
||||
$inputFile = null;
|
||||
$changeDir = false;
|
||||
$debugInfo = false;
|
||||
$lineNumbers = false;
|
||||
$ignoreErrors = false;
|
||||
$encoding = false;
|
||||
$sourceMap = false;
|
||||
$embedSources = false;
|
||||
$embedSourceMap = false;
|
||||
|
||||
/**
|
||||
* Parse argument
|
||||
*
|
||||
* @param int $i
|
||||
* @param string[] $options
|
||||
* @param integer $i
|
||||
* @param array $options
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -62,29 +61,25 @@ function parseArgument(&$i, $options) {
|
||||
}
|
||||
}
|
||||
|
||||
$arguments = [];
|
||||
|
||||
for ($i = 1; $i < $argc; $i++) {
|
||||
if ($argv[$i] === '-?' || $argv[$i] === '-h' || $argv[$i] === '--help') {
|
||||
$exe = $argv[0];
|
||||
|
||||
$HELP = <<<EOT
|
||||
Usage: $exe [options] [input-file] [output-file]
|
||||
Usage: $exe [options] [input-file]
|
||||
|
||||
Options include:
|
||||
|
||||
--help Show this message [-h, -?]
|
||||
--continue-on-error [deprecated] Ignored
|
||||
--debug-info [deprecated] Ignored [-g]
|
||||
--dump-tree [deprecated] Dump formatted parse tree [-T]
|
||||
--continue-on-error Continue compilation (as best as possible) when error encountered
|
||||
--debug-info Annotate selectors with CSS referring to the source file and line number [-g]
|
||||
--dump-tree Dump formatted parse tree [-T]
|
||||
--iso8859-1 Use iso8859-1 encoding instead of default utf-8
|
||||
--line-numbers [deprecated] Ignored [--line-comments]
|
||||
--line-numbers Annotate selectors with comments referring to the source file and line number [--line-comments]
|
||||
--load-path=PATH Set import path [-I]
|
||||
--precision=N [deprecated] Ignored. (default 10) [-p]
|
||||
--precision=N Set decimal number precision (default 10) [-p]
|
||||
--sourcemap Create source map file
|
||||
--embed-sources Embed source file contents in source maps
|
||||
--embed-source-map Embed the source map contents in CSS (default if writing to stdout)
|
||||
--style=FORMAT Set the output style (compressed or expanded) [-s, -t]
|
||||
--style=FORMAT Set the output format (compact, compressed, crunched, expanded, or nested) [-s, -t]
|
||||
--version Print the version [-v]
|
||||
|
||||
EOT;
|
||||
@@ -95,15 +90,13 @@ EOT;
|
||||
exit(Version::VERSION . "\n");
|
||||
}
|
||||
|
||||
// Keep parsing --continue-on-error to avoid BC breaks for scripts using it
|
||||
if ($argv[$i] === '--continue-on-error') {
|
||||
// TODO report it as a warning ?
|
||||
$ignoreErrors = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Keep parsing it to avoid BC breaks for scripts using it
|
||||
if ($argv[$i] === '-g' || $argv[$i] === '--debug-info') {
|
||||
// TODO report it as a warning ?
|
||||
$debugInfo = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -112,9 +105,8 @@ EOT;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Keep parsing it to avoid BC breaks for scripts using it
|
||||
if ($argv[$i] === '--line-numbers' || $argv[$i] === '--line-comments') {
|
||||
// TODO report it as a warning ?
|
||||
$lineNumbers = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -123,16 +115,6 @@ EOT;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($argv[$i] === '--embed-sources') {
|
||||
$embedSources = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($argv[$i] === '--embed-source-map') {
|
||||
$embedSourceMap = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($argv[$i] === '-T' || $argv[$i] === '--dump-tree') {
|
||||
$dumpTree = true;
|
||||
continue;
|
||||
@@ -148,25 +130,34 @@ EOT;
|
||||
$value = parseArgument($i, array('-I', '--load-path'));
|
||||
|
||||
if (isset($value)) {
|
||||
$loadPaths[] = $value;
|
||||
$loadPaths = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Keep parsing --precision to avoid BC breaks for scripts using it
|
||||
$value = parseArgument($i, array('-p', '--precision'));
|
||||
|
||||
if (isset($value)) {
|
||||
// TODO report it as a warning ?
|
||||
$precision = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
$arguments[] = $argv[$i];
|
||||
if (file_exists($argv[$i])) {
|
||||
$inputFile = $argv[$i];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($arguments[0]) && file_exists($arguments[0])) {
|
||||
$inputFile = $arguments[0];
|
||||
if ($inputFile) {
|
||||
$data = file_get_contents($inputFile);
|
||||
|
||||
$newWorkingDir = dirname(realpath($inputFile));
|
||||
$oldWorkingDir = getcwd();
|
||||
|
||||
if ($oldWorkingDir !== $newWorkingDir) {
|
||||
$changeDir = chdir($newWorkingDir);
|
||||
$inputFile = basename($inputFile);
|
||||
}
|
||||
} else {
|
||||
$data = '';
|
||||
|
||||
@@ -180,65 +171,45 @@ if ($dumpTree) {
|
||||
|
||||
print_r(json_decode(json_encode($parser->parse($data)), true));
|
||||
|
||||
fwrite(STDERR, 'Warning: the --dump-tree option is deprecated. Use proper debugging tools instead.');
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
$scss = new Compiler();
|
||||
|
||||
if ($debugInfo) {
|
||||
$scss->setLineNumberStyle(Compiler::DEBUG_INFO);
|
||||
}
|
||||
|
||||
if ($lineNumbers) {
|
||||
$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
|
||||
}
|
||||
|
||||
if ($ignoreErrors) {
|
||||
$scss->setIgnoreErrors($ignoreErrors);
|
||||
}
|
||||
|
||||
if ($loadPaths) {
|
||||
$scss->setImportPaths($loadPaths);
|
||||
$scss->setImportPaths(explode(PATH_SEPARATOR, $loadPaths));
|
||||
}
|
||||
|
||||
if ($precision) {
|
||||
$scss->setNumberPrecision($precision);
|
||||
}
|
||||
|
||||
if ($style) {
|
||||
if ($style === OutputStyle::COMPRESSED || $style === OutputStyle::EXPANDED) {
|
||||
$scss->setOutputStyle($style);
|
||||
} else {
|
||||
fwrite(STDERR, "WARNING: the $style style is deprecated.\n");
|
||||
$scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\' . ucfirst($style));
|
||||
}
|
||||
$scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\' . ucfirst($style));
|
||||
}
|
||||
|
||||
$outputFile = isset($arguments[1]) ? $arguments[1] : null;
|
||||
$sourceMapFile = null;
|
||||
|
||||
if ($sourceMap) {
|
||||
$sourceMapOptions = array(
|
||||
'outputSourceFiles' => $embedSources,
|
||||
);
|
||||
if ($embedSourceMap || $outputFile === null) {
|
||||
$scss->setSourceMap(Compiler::SOURCE_MAP_INLINE);
|
||||
} else {
|
||||
$sourceMapFile = $outputFile . '.map';
|
||||
$sourceMapOptions['sourceMapWriteTo'] = $sourceMapFile;
|
||||
$sourceMapOptions['sourceMapURL'] = basename($sourceMapFile);
|
||||
$sourceMapOptions['sourceMapBasepath'] = getcwd();
|
||||
$sourceMapOptions['sourceMapFilename'] = basename($outputFile);
|
||||
|
||||
$scss->setSourceMap(Compiler::SOURCE_MAP_FILE);
|
||||
}
|
||||
|
||||
$scss->setSourceMapOptions($sourceMapOptions);
|
||||
$scss->setSourceMap(Compiler::SOURCE_MAP_INLINE);
|
||||
}
|
||||
|
||||
if ($encoding) {
|
||||
$scss->setEncoding($encoding);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $scss->compileString($data, $inputFile);
|
||||
} catch (SassException $e) {
|
||||
fwrite(STDERR, 'Error: '.$e->getMessage()."\n");
|
||||
exit(1);
|
||||
}
|
||||
echo $scss->compile($data, $inputFile);
|
||||
|
||||
if ($outputFile) {
|
||||
file_put_contents($outputFile, $result->getCss());
|
||||
|
||||
if ($sourceMapFile !== null && $result->getSourceMap() !== null) {
|
||||
file_put_contents($sourceMapFile, $result->getSourceMap());
|
||||
}
|
||||
} else {
|
||||
echo $result->getCss();
|
||||
if ($changeDir) {
|
||||
chdir($oldWorkingDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user