我的代码有什么问题,文件相关 API 的回调中的 console.logs 在 CLI 中没有显示任何内容。
module.exports = function (grunt) {
var path = require("path"),
fs = require("fs"),
gm = require("gm");
grunt.registerMultiTask("imagesizeslist", "Generate image sizes list", function () {
var files = grunt.file.expandFiles(this.file.src);
grunt.helper('imagesizeslist', files);
});
// grunt.log.write(contents);
grunt.registerHelper('imagesizeslist', function (files) {
files.forEach(function (file) {
basename = path.resolve(file);
var exec = require('child_process').exec,
child;
//using sips
console.log('sips "'+basename+'" -g pixelHeight');
child = exec('sips "'+basename+'" -g pixelHeight',
function (error, stdout, stderr) {
console.log(error);
console.log('stdout: ' + stdout);
});
// using gm
gm(basename).size(function (err, size) {
if (!err)
console.log(size.width > size.height ? 'wider' : 'taller than you');
else
console.log("test");
console.log(size);
});
});
});
};