grunt-pugpig-issues-xml
Version:
Generate issues XML file for PugPig publications.
73 lines (59 loc) • 1.8 kB
JavaScript
/*
* grunt-pugpig-issues-xml
*
*
* Copyright (c) 2014 Daniel Furze
* Licensed under the MIT license
*
*
* @todo: Generate xml with more than one 'part'
*
*/
;
module.exports = function (grunt) {
// Require dependencies
var builder = require('xmlbuilder'),
fs = require('fs'),
superb = require('superb'),
chalk = require('chalk');
grunt.registerMultiTask('pugpig_issues_xml', 'Generate issues XML file for PugPig.', function () {
// Merge task-specific and/or target-specific options with these defaults
var options = this.options({
root: 'content.xml',
fileName: 'issues'
});
// Need these outside the forEach
var path,
fileSize;
// Get file size of each file
this.files.forEach(function(f) {
// Set full path
path = f.src.join('');
// Actual file
var file = fs.statSync(path);
// Set file size
fileSize = (file.size);
});
// Build XML string
var issuesXml = builder.create({
package: {
'@root': options.root,
part: {
'@name': options.partName,
'@src': options.partSrc, //@todo: get this from filename dynamically
'@size': fileSize,
'@modified': grunt.template.today('yyyy-mm-dd"T"HH:MM:ss+00:00'),
}
}
});
// Format XML string
var xmlString = issuesXml.end({ pretty: true, indent: ' ', newline: '\n' }),
fileName = options.fileName + '.xml';
// Write XML to file
grunt.file.write(options.dest + fileName, xmlString);
// Format and print a success message!
var sup = superb();
sup = sup.charAt(0).toUpperCase() + sup.slice(1) + '!';
grunt.log.writeln(chalk.yellow(sup) + chalk.blue(' File "' + options.dest + fileName + '" created.'));
});
};