UNPKG

sai-language

Version:

An object-oriented language designed to afford code comprehension and maintenance. Transpiles in-place to Javascript.

137 lines (132 loc) 4.54 kB
// Javascript source for builder.sai transpiled by SAI // "use strict"; var $AI=require("sai-library"); var prototype=new $AI._prototype(); // Generated code follows var __context={"name":"builder.sai","loader":"SAI.GetSourceFromPaths","path":"./builder.sai","mtime":"2018-02-02T04:39:35.833Z","fetched":"2018-02-02T04:48:40.870Z"}; var _FS = require('fs'); var _PATH = require('path'); var isa = prototype.isa = 'Builder'; prototype.isof['Builder'] = { version: '0.0.0-unspecified', isa: isa, context: __context, main: true, }; prototype.__tobelocked = prototype.__tobelocked.concat(["'Instantiate'", "isa"]); prototype.__tobefrozen = prototype.__tobefrozen.concat(["isof"]); var $1g = prototype['Instantiate']; prototype['Instantiate'] = function(p) { var $11, _argv, $10, $5, $4, _candidate, _leaf, _ProcessArg, $3, _name, $2, $1, _objectName, _src, _Build, _MkPath, $0, _dest, _branch, _DestPath, _path, _IsDirectory, _Banner, _flags, _SAI = p, $ = this; { if (!(_SAI)) { $AI.debug('Cannot use Builder as a runtime module.'); process.exit(1); } _flags = {}; _Banner = function(p) { { $AI.debug('sai-build -- command-line compiler for .sai scripts' + '\n' + '' + '\n' + 'USAGE' + '\n' + 'sai-build [path/object name] - compiles file to native JS ' + '\n' + '' + '\n' + 'OPTIONS' + '\n' + '-o [path] -- set output folder' + '\n' + '-v -- print input and output filenames' + '\n' + '-t -- don\'t save output, just compile' + '\n' + '' + '\n' + 'EXAMPLES' + '\n' + 'sai-build HelloWorld.sai' + '\n' + 'sai-build -o bin src/bin -o lib src/lib' + '\n' + ''); process.exit(); } }; _IsDirectory = function(p) { var _path = p; { return _FS.lstatSync(_path).isDirectory(); } }; _DestPath = function(p, _branch) { var _path = p; { if (($0 = (_dest))) { _path = _PATH.join(_dest, _branch, _PATH.basename(_path));; } _path = _path.replace('.sai', '.js'); return _path; } }; _MkPath = function(p) { var _path = p; { if (!(_FS.existsSync(_path))) { _MkPath(_PATH.dirname(_path)); _FS.mkdirSync(_path); } } }; _Build = function(p, _dest) { var _src = p; { let _objectName = _PATH.basename(_src); _SAI.Clean(); _SAI.Configure({ paths: [_PATH.dirname(_src)] }); try { _SAI.Require(_objectName); if (!(_flags.test)) { _MkPath(_PATH.dirname(_dest)); _FS.writeFileSync(_dest, _SAI.GetSource(_objectName)); } if (($1 = (_flags.verbose))) { $AI.debug('' + _src + ' -> ' + _dest);; } } catch ($3) { $AI.debug('' + _src + ' -> ERROR'); if (($2 = ($3.message.indexOf('Contractually required')))) { $AI.debug($3.message); } else { $AI.debug('Could not load ' + _name); process.exit(); } } } }; _ProcessArg = function(p, _branch) { var _path = p; { if (($10 = (_IsDirectory(_path)))) { var $6 = $AI.kviterate(_FS.readdirSync(_path)), $7 = $6.next(); if (!$7.done) for (; !$7.done; $7 = $6.next()) { _leaf = $7.value[1]; $8 = $7.value[0]; let _candidate = _PATH.join(_path, _leaf); if (($4 = (('.sai' === _PATH.extname(_leaf))))) { _ProcessArg(_candidate, _branch); } else if (($5 = (((_leaf !== '.') && ((_leaf !== '..') && _IsDirectory(_candidate)))))) { _ProcessArg(_candidate, _PATH.join(_branch, _leaf)); }; } } else { _Build(_path, _DestPath(_path, _branch)); } } }; _argv = $AI.slice((process.argv), 2, undefined); if (!(_argv.length)) { _Banner(); } var $12; while ($12 = (_argv.shift())) { switch ($11 = ($12)) { case ('-o'): _dest = _argv.shift(); break; case ('-v'): _flags.verbose = true; break; case ('-t'): _flags.test = true; break; default: _ProcessArg($12, ''); break; } } } }; // End of generated code $AI.finalizePrototype(prototype); var pro=prototype.constructor; exports=pro; try { module.exports=pro; } catch(e) {} if (prototype.isof[isa].main) var main=pro(); return pro;