Skip to content

Instantly share code, notes, and snippets.

@LukasRos
Created March 21, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukasRos/6d647f7334ad6d835c9b35b5419d20c0 to your computer and use it in GitHub Desktop.
Save LukasRos/6d647f7334ad6d835c9b35b5419d20c0 to your computer and use it in GitHub Desktop.
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