Created
March 7, 2012 22:49
-
-
Save johnmdonahue/1996846 to your computer and use it in GitHub Desktop.
EpicEditor Jakefile - Not a working/complete version.
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
// This is a broken Jakefile to build epiceditor | |
var fs = require('fs') | |
, path = require('path') | |
, spawn = require('child_process').spawn | |
, exec = require('child_process').exec | |
, epicAscii = '' + | |
' \n' + | |
' ______ _ ______ ___ __ \n' + | |
' / ____/___ (_)____/ ____/___/ (_) /_____ _____ \n' + | |
' / __/ / __ \\/ / ___/ __/ / __ / / __/ __ \\/ ___/ \n' + | |
' / /___/ /_/ / / /__/ /___/ /_/ / / /_/ /_/ / / \n' + | |
' /_____/ .___/_/\\___/_____/\\__,_/_/\\__/\\____/_/ \n' + | |
' /_/ \n' | |
function colorize(str, color) { | |
var colors = { | |
'blue': '34m' | |
, 'cyan': '36m' | |
, 'green': '32m' | |
, 'magenta': '35m' | |
, 'red': '31m' | |
, 'yellow': '33m' | |
} | |
return colors[color] ? '\033[' + colors[color] + str + '\033[39m' : str; | |
} | |
console.log(colorize(epicAscii, 'yellow')); | |
desc('Build tmp from core code and run through JSHint'); | |
task('lint', [], function () { | |
// TODO: Add fullscreen when ready | |
var files = ['./src/intro.js', './src/editor.js', './src/outro.js'] | |
, tmpStr = '' | |
, cat | |
, jshint | |
cat = spawn('cat', files); | |
cat.stdout.on("data", function (data) { | |
tmpStr += data; | |
}); | |
cat.stdout.on("end", function () { | |
var tmpPath = path.join(process.cwd() + '/src/epiceditor.tmp.js') | |
, jshintErrors = '' | |
console.log(colorize('Creating tmp build... ', 'gray') + tmpPath); | |
fs.writeFile(tmpPath, tmpStr, function (err, written, buffer) { | |
if (err) { | |
console.log('ERROR:', err); | |
} else { | |
console.log(colorize('Running JSHint...', 'yellow')); | |
jshint = spawn('jshint', [tmpPath]); | |
jshint.stdout.on('data', function (data) { | |
jshintErrors += new Buffer(data).toString("utf-8") | |
}); | |
jshint.stdout.on('end', function () { | |
console.log(colorize('Removing tmp build... ', 'gray') + tmpPath) | |
fs.unlink(tmpPath); | |
if (jshintErrors) { | |
console.log(jshintErrors) | |
console.log(colorize('Lint failed.', 'red') + '\n') | |
} else { | |
console.log(colorize('Lint success! Giddyup.', 'red')) | |
} | |
}); | |
jshint.stderr.on('data', function (data) { | |
console.log('ERROR:', new Buffer(data).toString("utf-8")) | |
}); | |
} | |
}); | |
}); | |
}); | |
desc('Hint and build epiceditor.js and epiceditor.min.js'); | |
task('build', [], function () { | |
var destDir = path.join(process.cwd() + '/epiceditor/js/') | |
, srcDir = path.join(process.cwd() + '/src/') | |
, srcPaths = [ | |
srcDir + 'intro.js' | |
, srcDir + 'epicShowdown.js' | |
, srcDir + 'fullscreen.js' | |
, srcDir + 'editor.js' | |
, srcDir + 'outro.js' | |
] | |
, dstPath = destDir + 'epiceditor.js' | |
, dstPathMin = destDir + 'epiceditor.min.js' | |
, i = 0 | |
, j = 0 | |
, buff | |
, uglify | |
, origCode = '' | |
, minCode = '' | |
if (!path.existsSync(destDir)) { | |
fs.mkdirSync(destDir) | |
} | |
// ************************************************* | |
// This is where I left off... and it breaks hard ;) | |
// Just didn't have any more time to play around | |
// Probs have to do async here no execAsync/spawnAsync | |
for (; i < srcPaths.length; i++) { | |
if (path.existsSync(srcPaths[i])) { | |
buff = fs.readFileSync(srcPaths[i]) | |
origCode += buff | |
// minCode.push(exec('uglifyjs', buff)) | |
} | |
} | |
fs.writeFileSync(dstPath, origCode) | |
uglify = spawn('uglifyjs', [origCode.toString()]) | |
uglify.stdout.on('data', function (data) { | |
minCode += data; | |
}); | |
uglify.stdout.on('end', function () { | |
fs.writeFileSync(dstPathMin, minCode) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment