function drush_speedy_min_module in Speedy 7
Command callback to minify JS using UglifyJS.
This is a command that walks through a particular Drupal module's codebase and produces minified JavaScript files.
File
- ./
speedy.drush.inc, line 122 - Drush integration for the speedy module.
Code
function drush_speedy_min_module($module) {
$directory = drupal_get_path('module', $module);
$directory_strlen = strlen($directory);
$all_files = file_scan_directory($directory, '/.js/');
// Walk though each file.
foreach ($all_files as $k => $file) {
if (!strstr($file->filename, '.min.js')) {
// Minify and store the file.
$new_path = DRUPAL_ROOT . '/' . $directory . substr(str_replace('.js', '.min.js', $file->uri), $directory_strlen);
// Delete an old version if it exists.
if (file_exists($new_path)) {
$result = drupal_unlink($new_path);
}
$pathinfo = pathinfo($new_path);
if (is_dir($pathinfo['dirname'])) {
chmod($pathinfo['dirname'], 0775);
}
$return = drush_shell_exec('/usr/local/bin/uglifyjs' . ' ' . $file->uri . ' > ' . $new_path);
if ($return) {
drush_log(dt('!filename was minified.', array(
'!filename' => $file->filename,
)), 'success');
}
else {
drush_log(dt('There was an error when trying to minify !filename.', array(
'!filename' => $file->filename,
)), 'error');
}
}
}
}