Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fs to determine if dest is a directory #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 13 additions & 18 deletions tasks/pot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

'use strict';

var fs = require('fs');

module.exports = function(grunt) {

grunt.registerMultiTask('pot', 'Scan files and create a .pot file using xgettext', function() {
Expand Down Expand Up @@ -35,10 +37,11 @@ module.exports = function(grunt) {
grunt.verbose.writeflags(options, 'Pot options');

var potFile = options.dest;
//If destination is a directory, build a file based on text domain
if( options.dest && detectDestType(options.dest) === 'directory' ) {
potFile = options.dest.replace(/\/$/, "") + "/"+options.text_domain+".pot";
}

// If destination is a directory, build a file based on text domain
if( options.dest && fs.lstatSync(options.dest).isDirectory() ){
potFile = options.dest.replace(/\/$/, "") + "/" + options.text_domain + ".pot";
}

if( !grunt.file.exists(potFile) ){
grunt.file.write(potFile);
Expand Down Expand Up @@ -93,11 +96,11 @@ module.exports = function(grunt) {
//Compile and run command
var exec = require('child_process').exec;
var command = 'xgettext' + join + ' --default-domain=' + options.text_domain + ' -o '+potFile + language + encoding + keywords + headerOptions + inputFiles;
var done = grunt.task.current.async();
var done = grunt.task.current.async();

grunt.verbose.writeln('Executing: ' + command);
exec( command,

exec( command,
function(error, stdout, stderr){

grunt.verbose.writeln('stderr: ' + stderr);
Expand All @@ -121,18 +124,10 @@ module.exports = function(grunt) {

}

done( error ); //error will be null if command executed without errors.
done( error ); //error will be null if command executed without errors.
}
);

});

var detectDestType = function(dest) {
if (grunt.util._.endsWith(dest, '/')) {
return 'directory';
} else {
return 'file';
}
};
});

};