Instantly share code, notes, and snippets.

Embed
What would you like to do?
CouchDB Design Document Manager
<?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";
{
"require": {
"matthiasmullie/minify" : "1.3.21"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment