Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
test/sample-project/node_modules
tags
*.swp
*.swo
76 changes: 38 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var inputMinType = "uglifyjs";
var compressor = require("node-minify");
const fs = require("fs");
const path = require("path");
const minify = require('@node-minify/core');
const babelMinify = require('@node-minify/babel-minify');

var walk = function(currentDirPath, callback) {
fs.readdirSync(currentDirPath).forEach(function(name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory()) {
walk(filePath, callback);
}
});
function walk (currentDirPath, callback) {
fs.readdirSync(currentDirPath).forEach(function(name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory()) {
walk(filePath, callback);
}
});
}

var minifyAll = function(dir, options, callback){
options = options || {};
options.type = options.type || inputMinType;
function minifyAll (dir, options, callback){
options = options || {};

walk(dir, function(path, result){
if (path.substr(-3) === ".js" || path.substr(-4) === ".css"){
if (!options.silent){
console.log("found file: " + path);
}
new compressor.minify({
type: options.type,
fileIn: path,
fileOut: path,
callback: callback || function(err, min){
if(err){
console.log(err);
}
}
});
walk(dir, function(path, result){
if (path.substr(-3) === ".js"){
if (!options.silent){
console.log("found file: " + path);
}
minify({
compressor: babelMinify,
input: path,
output: path,
callback: callback || function(err, min){
if(err){
console.log(err);
}
}
});
});
}
});
};

if (require.main === module) {
var input = process.argv,
inputDir = input[2],
inputMinType = input[3] || inputMinType;
minifyAll(inputDir);
var input = process.argv;
var inputDir = input[2];
minifyAll(inputDir);

} else {
module.exports = minifyAll;
module.exports = minifyAll;
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minify-all",
"version": "1.2.2",
"version": "1.2.3",
"description": "A tool that minifies all .js files in a folder and its nested folders",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -44,7 +44,8 @@
"mocha": "^2.2.5"
},
"dependencies": {
"node-minify": "^1.1.0",
"promise": "^7.0.3"
"@node-minify/babel-minify": "^6.1.0",
"@node-minify/core": "^6.1.0",
"@node-minify/uglify-js": "^6.1.0"
}
}
Loading