Created
August 11, 2015 12:46
-
-
Save MatthewBarker/e204f17dc4c13ac7adf2 to your computer and use it in GitHub Desktop.
Gulp tasks to build, lint & document actionscript / Flash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Also depends on: npm install --save-dev flash-sdk | |
var colors = require('colors'), | |
flash = require('gulp-flash'), | |
flexPmd = require('flexpmd'), | |
fs = require('fs'), | |
gulp = require('gulp'), | |
process = require('child_process'), | |
xpath = require('xpath'), | |
xmldom = require('xmldom'), | |
config = { | |
src: 'src/main.as', | |
dist: 'dist', | |
doc: 'doc' | |
}; | |
gulp.task('default', function () { | |
return gulp.src(config.src) | |
.pipe(flash(config.dist)); | |
}); | |
gulp.task('doc', function (cb) { | |
var cmd = './node_modules/flex-sdk/lib/flex_sdk/bin/asdoc -doc-sources ' + config.src + ' -output ' + config.doc; | |
process.exec(cmd, function (err, stdout, stderr) { | |
console.log(stdout); | |
console.log(stderr); | |
cb(err); | |
}); | |
}) | |
gulp.task('lint', function (cb) { | |
var args = ['-Xmx256m', '-jar', flexPmd.cmd, '-s', config.src, '-o', 'lint']; | |
process.execFile('java', args, function (err, stdout, stderr) { | |
var xml = fs.readFileSync('lint/pmd.xml', { encoding: 'utf8' }), | |
doc = (new xmldom.DOMParser()).parseFromString(xml), | |
nodes = xpath.select('//violation', doc), | |
message; | |
nodes.forEach(function (node) { | |
message = []; | |
message.push('package: ' + node.getAttribute('package')); | |
message.push('class: ' + node.getAttribute('class')); | |
message.push('begin: ' + node.getAttribute('beginline') + ':' + node.getAttribute('begincolumn')); | |
message.push('end: ' + node.getAttribute('endline') + ':' + node.getAttribute('endcolumn')); | |
message.push(node.firstChild.data); | |
console.log(message.join(', ').red); | |
}); | |
if (nodes.length) { | |
err = 'See lint report'; | |
} | |
console.log(stdout); | |
console.log(stderr); | |
cb(err); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment