UNPKG

jeefo-preprocessor

Version:
55 lines (46 loc) 1.29 kB
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. * File Name : index.js * Created at : 2017-04-07 * Updated at : 2017-04-07 * Author : jeefo * Purpose : * Description : _._._._._._._._._._._._._._._._._._._._._.*/ //ignore:start "use strict"; /* global */ /* exported */ /* exported */ //ignore:end var path = require("path"), spawn = require("child_process").spawn; var GCCPreprocessor = function (filepath) { this.args = ["-E", "-P", "-x", 'c', "-imacros", this.MACROS_PATH, filepath]; this.error = ''; this.result = ''; this.filepath = filepath; }; GCCPreprocessor.prototype = { MACROS_PATH : path.join(__dirname, "js_macros.h"), process : function (callback) { var instance = this, processor = spawn("gcc", instance.args); processor.stdout.on("data", function (buffer) { instance.result += buffer.toString("utf8", 0, buffer.length - 1); }); processor.stderr.on("data", function (buffer) { instance.error += buffer.toString(); }); processor.on("close", function (exit_code) { if (exit_code === 0) { callback(null, instance.result); } else { callback(instance.error); } }); } }; module.exports = function (filepath, callback) { var preprocessor = new GCCPreprocessor(filepath); preprocessor.process(callback); };