UNPKG

adcutil

Version:

Utilities tools for Askia Design Control

184 lines (163 loc) 6.11 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">var common = require(&#39;../common/common.js&#39;); var InteractiveADXShell = require(&#39;../common/InteractiveADXShell.js&#39;).InteractiveADXShell; var pathHelper = require(&#39;path&#39;); var errMsg = common.messages.error; <span id='ADC-Show'>/** </span> * Compile, execute and display the output of an ADC * * @class ADC.Show * @private */ function Show(adcDirPath) { <span id='ADC-Show-property-rootdir'> /** </span> * Root dir of the current ADCUtil */ this.rootdir = pathHelper.resolve(__dirname, &quot;../../&quot;); <span id='ADC-Show-property-adcDirectoryPath'> /** </span> * Path to the ADC directory * @type {string} */ this.adcDirectoryPath = adcDirPath ? pathHelper.normalize(adcDirPath) : process.cwd(); } <span id='ADC-Show-method-constructor'>/** </span> * Create a new instance of ADC Show * * @constructor * @param {String} adcDirPath Path of the ADC directory */ Show.prototype.constructor = Show; <span id='ADC-Show-method-writeError'>/** </span> * Write an error output in the console * @param {String} text Text to write in the console */ Show.prototype.writeError = function writeError(text) { common.writeError.apply(common, arguments); }; <span id='ADC-Show-method-writeWarning'>/** </span> * Write a warning output in the console * @param {String} text Text to write in the console */ Show.prototype.writeWarning = function writeWarning(text) { common.writeWarning.apply(common, arguments); }; <span id='ADC-Show-method-writeSuccess'>/** </span> * Write a success output in the console * @param {String} text Text to write in the console */ Show.prototype.writeSuccess = function writeSuccess(text) { common.writeSuccess.apply(common, arguments); }; <span id='ADC-Show-method-writeMessage'>/** </span> * Write an arbitrary message in the console without specific prefix * @param {String} text Text to write in the console */ Show.prototype.writeMessage = function writeMessage(text) { common.writeMessage.apply(common, arguments); }; <span id='ADC-Show-method-show'>/** </span> * Show an ADC output * * @param {Object} options Options * @param {String} options.output Name of the ADC Output to use * @param {String} options.fixture FileName of the ADC fixture to use * @param {String} [options.masterPage] Path of the master page to use * @param {String} [options.properties] ADC properties (in url query string format: &#39;param1=value1&amp;param2-value2&#39;) * @param {InteractiveADXShell} [options.adxShell] Interactive ADXShell process * @param {Boolean} [options.silent=false] Silent mode: Don&#39;t message in the console but only through the callback * @param {Function} callback Callback function * @param {Error} callback.err Error * @param {String} callback.output Output string */ Show.prototype.show = function show(options, callback) { if (!options || !options.output) { if (!options.silent) { this.writeError(errMsg.noOutputDefinedForShow); } if (typeof callback === &#39;function&#39;) { callback(new Error(errMsg.noOutputDefinedForShow)); } return; } if (!options || !options.fixture) { if (!options.silent) { this.writeError(errMsg.noFixtureDefinedForShow); } if (typeof callback === &#39;function&#39;) { callback(new Error(errMsg.noFixtureDefinedForShow)); } return; } var execFile = require(&#39;child_process&#39;).execFile, args = [ &#39;show&#39;, &#39;&quot;-output:&#39; + options.output + &#39;&quot;&#39;, &#39;&quot;-fixture:&#39; + options.fixture + &#39;&quot;&#39; ]; if (options.masterPage) { args.push(&#39;&quot;-masterPage:&#39; + pathHelper.resolve(options.masterPage) + &#39;&quot;&#39;); } if (options.properties) { args.push(&#39;&quot;-properties:&#39; + options.properties + &#39;&quot;&#39;); } args.push(&#39;&quot;&#39; + this.adcDirectoryPath + &#39;&quot;&#39;); var self = this; function execCallback(err, stdout, stderr) { if (err &amp;&amp; typeof callback === &#39;function&#39;) { callback(err, null); return; } if (!options.silent) { self.writeMessage(stdout); } if (!stderr &amp;&amp; typeof callback === &#39;function&#39;) { callback(null, stdout); } if (stderr) { if (!options.silent) { self.writeError(&quot;\r\n&quot; + stderr); } if (typeof callback === &#39;function&#39;) { callback(new Error(stderr)); } } } if (!options.adxShell) { execFile(&#39;.\\&#39; + common.ADC_UNIT_PROCESS_NAME, args, { cwd : pathHelper.join(self.rootdir, common.ADC_UNIT_DIR_PATH), env : process.env }, execCallback); } else { options.adxShell.exec(args.join(&#39; &#39;), execCallback); } }; // Make it public exports.Show = Show; /* * Show an ADC output * * @param {Command} program Commander object which hold the arguments pass to the program * @param {String} path Path of the ADC to directory */ exports.show = function show(program, path) { var showInstance = new Show(path); showInstance.show(program); };</pre> </body> </html>