Created
March 21, 2017 15:28
-
-
Save LukasRos/6d647f7334ad6d835c9b35b5419d20c0 to your computer and use it in GitHub Desktop.
CouchDB Design Document Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "vendor/autoload.php"; | |
use MatthiasMullie\Minify\JS; | |
$baseName = $argv[1]; | |
if (!is_dir($baseName)) { | |
echo "Could not find directory ".$baseName.".\n"; | |
exit(-1); | |
} | |
$output = ['language' => 'javascript']; | |
$baseDir = opendir($baseName); | |
while (false !== ($entry = readdir($baseDir))) { | |
$elements = explode(".", $entry); | |
if (!isset($elements[2]) || $elements[2] != 'js') | |
continue; // ignore non-JS files | |
// Load JS file for minification | |
$minifier = new JS(file_get_contents($baseName."/".$entry)); | |
if ($elements[1] == 'map') { | |
// Add map function | |
$output['views'][$elements[0]]['map'] = $minifier->minify(); | |
echo "views -> ".$elements[0]." -> map added.\n"; | |
} else { | |
echo "Nothing to do with ".$entry.".\n"; | |
} | |
} | |
file_put_contents($baseName.".json", json_encode($output, JSON_PRETTY_PRINT)); | |
echo "Written ".$baseName.".json.\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"matthiasmullie/minify" : "1.3.21" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment