Comparing version 3.1.0 to 3.2.0
@@ -32,3 +32,3 @@ #!/usr/bin/env node | ||
var Esmall = require('../lib'); | ||
var esmall = new Esmall(); | ||
var {success, error} = require('./logger'); | ||
@@ -52,46 +52,41 @@ | ||
function minifyText(err, data) { | ||
if (err) { | ||
error('Something has gone wrong', err); | ||
process.exit(1); | ||
} | ||
esmall.minify(data.toString(), handleMinified); | ||
} | ||
var input; | ||
var output; | ||
var esmall = new Esmall(); | ||
function handleMinified(err, minified) { | ||
if (!argv.o) { | ||
process.stdout.write(minified); | ||
process.exit(0); | ||
} | ||
fs.writeFile(resolve(argv.o), minified, cleanup); | ||
} | ||
esmall.on('error', (err) => { | ||
error('Minification failed', err); | ||
process.exit(1); | ||
}) | ||
function cleanup(err) { | ||
if (err) { | ||
error('Writing to file failed', err); | ||
process.exit(1); | ||
} | ||
success('It worked 🎉'); | ||
process.exit(0); | ||
} | ||
if (process.stdin.isTTY) { | ||
fs.open(resolve(argv._[0]), 'r', function(err, fd) { | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
error(`${argv._[0]} does not exist`); | ||
process.exit(1); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
fs.readFile(fd, minifyText); | ||
input = fs.createReadStream(resolve(argv._[0])); | ||
input.on('error', (err) => { | ||
error('Error reading file', err); | ||
}); | ||
} | ||
else { | ||
input = process.stdin; | ||
} | ||
if (argv.o) { | ||
output = fs.createWriteStream(resolve(argv.o)); | ||
output.on('error', (err) => { | ||
error('Error writing file', err); | ||
process.exit(1) | ||
}) | ||
} | ||
else { | ||
process.stdin.pipe(concat((data) => { | ||
minifyText(null, data); | ||
})); | ||
output = process.stdout; | ||
} | ||
input | ||
.pipe(esmall) | ||
.pipe(output) | ||
.on('end', _ => { | ||
success('It worked 🎉'); | ||
}) | ||
.on('error', (err) => { | ||
error('It did not work', err); | ||
process.exit(1); | ||
}); |
{ | ||
"name": "esmall", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Pretty Naive", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96740
284