Skip to content

Commit

Permalink
Merge pull request #17 from donaldp/feature/windows-support
Browse files Browse the repository at this point in the history
Feature/windows support
  • Loading branch information
donaldp authored Mar 14, 2022
2 parents 6eb86ed + ec591bf commit 6057b2e
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 246 deletions.
53 changes: 29 additions & 24 deletions lib/Command.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
function requireDefault$__(obj){
return obj && obj.__esModule ? obj : { default: obj };
};
const Ψ__init__ = Symbol.for('#__init__'), Ψ__initor__ = Symbol.for('#__initor__'), Ψ__inited__ = Symbol.for('#__inited__');
const $10 = Symbol.for('#__init__'), $13 = Symbol.for('#__initor__'), $14 = Symbol.for('#__inited__'), $11 = Symbol.for('#__hooks__');
Object.defineProperty(exports, "__esModule", {value: true});

/*body*/
var _$fsφ = require('fs'/*$path$*/);
var _$fsφ2 = require('fs'/*$path$*/);
var _$fsφ3 = require('fs'/*$path$*/);
var _$pathφ = require('path'/*$path$*/);
var _$pathφ2 = require('path'/*$path$*/);
var _$pathφ3 = require('path'/*$path$*/);
var _$child_processφ = require('child_process'/*$path$*/);
var _$jsonφ = require('../package.json'/*$path$*/);
var _$ImbaRunnerφ = requireDefault$__(require('./ImbaRunner'/*$path$*/));
var $1 = require('fs'/*$path$*/);
var $2 = require('fs'/*$path$*/);
var $3 = require('fs'/*$path$*/);
var $4 = require('path'/*$path$*/);
var $5 = require('path'/*$path$*/);
var $6 = require('path'/*$path$*/);
var $7 = require('child_process'/*$path$*/);
var $8 = require('../package.json'/*$path$*/);
var $9 = requireDefault$__(require('./ImbaRunner'/*$path$*/));

class Command {
[Ψ__init__]($$ = null){
var ;
this.args = ($$ && ( = $$.args) !== undefined) ? () : [];
this.watch = ($$ && ( = $$.watch) !== undefined) ? () : false;
[$10]($$ = null){
var $12;
this.args = ($$ && ($12 = $$.args) !== undefined) ? ($12) : [];
this.watch = ($$ && ($12 = $$.watch) !== undefined) ? ($12) : false;

}
get isRuntime(){
Expand All @@ -28,7 +28,7 @@ class Command {
}

constructor(){
this[Ψ__init__]();
this[$10]();
this.args = process.argv.slice(2);
}

Expand All @@ -41,7 +41,7 @@ class Command {

printVersion(){

return console.log(("Imba Shell v" + _$jsonφ.version + " (imba " + (_$ImbaRunnerφ.default.version) + ")"));
return console.log(("Imba Shell v" + $8.version + " (imba " + ($9.default.version) + ")"));
}

displayHelp(){
Expand Down Expand Up @@ -72,7 +72,7 @@ class Command {

if (this.watch == false && !(this.args[0])) { return this.displayHelp() };

if ((this.args[0] == undefined && this.watch) || (!(_$fsφ.existsSync(_$pathφ.join(process.cwd(),this.args[0]))) && !(this.args[0].trim().startsWith('-')))) {
if ((this.args[0] == undefined && this.watch) || (!($1.existsSync($4.join(process.cwd(),this.args[0]))) && !(this.args[0].trim().startsWith('-')))) {

console.log('Error: Script missing.');

Expand All @@ -92,7 +92,7 @@ class Command {
return this.displayHelp();
};

if (_$fsφ.existsSync(_$pathφ.join(process.cwd(),this.args[0]))) {
if ($1.existsSync($4.join(process.cwd(),this.args[0]))) {

return this.exec();
};
Expand All @@ -104,18 +104,23 @@ class Command {

const fallbackScript = this.createFallbackScript();

if (process.platform === 'win32') {

this.args[0] = fallbackScript || $4.join(process.cwd(),this.args[0]);
};

this.args.splice(1,0,'--');

const watcher = [];

if (this.watch) { watcher.push('-w') };

_$child_processφ.spawnSync(("" + _$ImbaRunnerφ.default.instance().slice(0,-1)),[...watcher,...this.args],{
$7.spawnSync(("" + $9.default.instance()),[...watcher,...this.args],{
stdio: 'inherit',
cwd: process.cwd()
});

if (fallbackScript !== null) { return _$fsφ3.unlinkSync(fallbackScript) };
if (fallbackScript !== null) { return $3.unlinkSync(fallbackScript) };
}

createFallbackScript(){
Expand All @@ -125,13 +130,13 @@ class Command {

if (!(this.args[0].endsWith('.imba'))) {

sourceScript = _$pathφ.join(process.cwd(),this.args[0]);
fallbackScript = _$pathφ.join(process.cwd(),_$pathφ2.dirname(this.args[0]),("." + _$pathφ3.basename(this.args[0]) + ".imba"));
sourceScript = $4.join(process.cwd(),this.args[0]);
fallbackScript = $4.join(process.cwd(),$5.dirname(this.args[0]),("." + $6.basename(this.args[0]) + ".imba"));

try {

_$fsφ2.copyFileSync(sourceScript,fallbackScript);
this.args[0] = _$pathφ.join(_$pathφ2.dirname(this.args[0]),("." + _$pathφ3.basename(this.args[0]) + ".imba"));
$2.copyFileSync(sourceScript,fallbackScript);
this.args[0] = $4.join($5.dirname(this.args[0]),("." + $6.basename(this.args[0]) + ".imba"));
} catch (e) {

fallbackScript = null;
Expand Down
30 changes: 15 additions & 15 deletions lib/ImbaCompiler.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
function requireDefault$__(obj){
return obj && obj.__esModule ? obj : { default: obj };
};
const Ψ__init__ = Symbol.for('#__init__'), Ψ__initor__ = Symbol.for('#__initor__'), Ψ__inited__ = Symbol.for('#__inited__');
const $7 = Symbol.for('#__init__'), $9 = Symbol.for('#__initor__'), $10 = Symbol.for('#__inited__'), $8 = Symbol.for('#__hooks__');
Object.defineProperty(exports, "__esModule", {value: true});

/*body*/
var _$child_processφ = require('child_process'/*$path$*/);
var _$jsonφ = require('../package.json'/*$path$*/);
var _$fsφ = requireDefault$__(require('fs'/*$path$*/));
var _$ImbaRunnerφ = requireDefault$__(require('./ImbaRunner'/*$path$*/));
var _$osφ = requireDefault$__(require('os'/*$path$*/));
var _$pathφ = requireDefault$__(require('path'/*$path$*/));
var $1 = require('child_process'/*$path$*/);
var $2 = require('../package.json'/*$path$*/);
var $3 = requireDefault$__(require('fs'/*$path$*/));
var $4 = requireDefault$__(require('./ImbaRunner'/*$path$*/));
var $5 = requireDefault$__(require('os'/*$path$*/));
var $6 = requireDefault$__(require('path'/*$path$*/));

class ImbaCompiler {
[Ψ__init__]($$ = null){
[$7]($$ = null){
this.code = $$ ? $$.code : undefined;
this.sessionId = $$ ? $$.sessionId : undefined;

Expand All @@ -23,7 +23,7 @@ class ImbaCompiler {
@param {String} sessionId
*/
constructor(code,sessionId){
this[Ψ__init__]();
this[$7]();
if (typeof code !== 'string') {

throw new TypeError('Expected code to be a String.');
Expand All @@ -49,18 +49,18 @@ class ImbaCompiler {

get(){

const directory = _$pathφ.default.join(_$osφ.default.homedir(),("." + _$jsonφ.name));
const directory = $6.default.join($5.default.homedir(),("." + $2.name));

if (!(_$fsφ.default.existsSync(directory))) {
if (!($3.default.existsSync(directory))) {

_$fsφ.default.mkdirSync(directory,{recursive: true});
$3.default.mkdirSync(directory,{recursive: true});
};

_$fsφ.default.writeFileSync(_$pathφ.default.join(directory,this.sessionId),this.code.trim());
$3.default.writeFileSync($6.default.join(directory,this.sessionId),this.code.trim());

const results = _$child_processφ.execSync(("" + _$ImbaRunnerφ.default.instance() + " " + _$pathφ.default.join(directory,this.sessionId) + " --platform=node --format=cjs --print"));
const results = $1.execSync(("" + $4.default.instance(true) + " " + $6.default.join(directory,this.sessionId) + " --platform=node --format=cjs --print"));

_$fsφ.default.rmSync(_$pathφ.default.join(directory,this.sessionId));
$3.default.rmSync($6.default.join(directory,this.sessionId));

return results.toString();
}
Expand Down
58 changes: 29 additions & 29 deletions lib/ImbaRepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ function requireDefault$__(obj){
return obj && obj.__esModule ? obj : { default: obj };
};;
function iter$__(a){ let v; return a ? ((v=a.toIterable) ? v.call(a) : a) : []; };
const Ψ__init__ = Symbol.for('#__init__'), Ψ__initor__ = Symbol.for('#__initor__'), Ψ__inited__ = Symbol.for('#__inited__');
const $9 = Symbol.for('#__init__'), $21 = Symbol.for('#__initor__'), $22 = Symbol.for('#__inited__'), $10 = Symbol.for('#__hooks__');
Object.defineProperty(exports, "__esModule", {value: true});

/*body*/
var _$jsonφ = require('../package.json'/*$path$*/);
var _$ContextHelpersφ = require('./ContextHelpers'/*$path$*/);
var _$ImbaCompilerφ = requireDefault$__(require('./ImbaCompiler'/*$path$*/));
var _$ImbaRunnerφ = requireDefault$__(require('./ImbaRunner'/*$path$*/));
var _$osφ = requireDefault$__(require('os'/*$path$*/));
var _$pathφ = requireDefault$__(require('path'/*$path$*/));
var _$replφ = requireDefault$__(require('repl'/*$path$*/));
var _$UpdateNotifierφ = requireDefault$__(require('./UpdateNotifier'/*$path$*/));
var $1 = require('../package.json'/*$path$*/);
var $2 = require('./ContextHelpers'/*$path$*/);
var $3 = requireDefault$__(require('./ImbaCompiler'/*$path$*/));
var $4 = requireDefault$__(require('./ImbaRunner'/*$path$*/));
var $5 = requireDefault$__(require('os'/*$path$*/));
var $6 = requireDefault$__(require('path'/*$path$*/));
var $7 = requireDefault$__(require('repl'/*$path$*/));
var $8 = requireDefault$__(require('./UpdateNotifier'/*$path$*/));

class ImbaRepl {
[Ψ__init__]($$ = null){
var ;
this.ctxCallbacks = ($$ && ( = $$.ctxCallbacks) !== undefined) ? () : [];
this.cmdCallbacks = ($$ && ( = $$.cmdCallbacks) !== undefined) ? () : [];
this.update = ($$ && ( = $$.update) !== undefined) ? () : null;
this.prompt = ($$ && ( = $$.prompt) !== undefined) ? () : '>>> ';
this.historyPath = ($$ && ( = $$.historyPath) !== undefined) ? () : null;
[$9]($$ = null){
var $11;
this.ctxCallbacks = ($$ && ($11 = $$.ctxCallbacks) !== undefined) ? ($11) : [];
this.cmdCallbacks = ($$ && ($11 = $$.cmdCallbacks) !== undefined) ? ($11) : [];
this.update = ($$ && ($11 = $$.update) !== undefined) ? ($11) : null;
this.prompt = ($$ && ($11 = $$.prompt) !== undefined) ? ($11) : '>>> ';
this.historyPath = ($$ && ($11 = $$.historyPath) !== undefined) ? ($11) : null;

}
/**
@param {String} prompt
@param {String|null} historyPath
*/
constructor(prompt = '>>> ',historyPath = null){
this[Ψ__init__]();
this[$9]();
if (typeof prompt !== 'string') {

throw new TypeError('Expected prompt to be a String.');
Expand Down Expand Up @@ -102,11 +102,11 @@ class ImbaRepl {
throw new TypeError('Expected repl options to be an Object.');
};

console.log(("Imba Shell v" + _$jsonφ.version + " (imba " + (_$ImbaRunnerφ.default.version) + ") by Donald Pakkies"));
console.log(("Imba Shell v" + $1.version + " (imba " + ($4.default.version) + ") by Donald Pakkies"));

if (this.update) { (new _$UpdateNotifierφ.default).check(this.update) };
if (this.update) { (new $8.default).check(this.update) };

const server = await _$replφ.default.start({...{prompt: this.prompt},...options});
const server = await $7.default.start({...{prompt: this.prompt},...options});

if (this.historyPath) {

Expand All @@ -118,27 +118,27 @@ class ImbaRepl {

self.registerCommand('clear',function() {

_$ContextHelpersφ.clear();
$2.clear();
return process.stdout.write(self.prompt);
});

self.registerCommand('exit',function() {

return _$ContextHelpersφ.exit();
return $2.exit();
});

for (let = 0, itemsφ = iter$__(self.ctxCallbacks), lenφ = itemsφ.length; < lenφ; ++) {
let handler = itemsφ[];
for (let $12 = 0, $13 = iter$__(self.ctxCallbacks), $14 = $13.length; $12 < $14; $12++) {
let handler = $13[$12];
handler(server.context);
};

for (let iφ2 = 0, itemsφ2 = iter$__(self.cmdCallbacks), lenφ2 = itemsφ2.length; iφ2 < lenφ2; iφ2++) {
let handler = itemsφ2[iφ2];
for (let $15 = 0, $16 = iter$__(self.cmdCallbacks), $17 = $16.length; $15 < $17; $15++) {
let handler = $16[$15];
server.defineCommand(handler.name,handler.callback);
};

for (let iφ3 = 0, keysφ = Object.keys(_$ContextHelpersφ), = keysφ.length, key, handler; iφ3 < ; iφ3++){
key = keysφ[iφ3];handler = _$ContextHelpersφ[key];
for (let $18 = 0, $19 = Object.keys($2), $20 = $19.length, key, handler; $18 < $20; $18++){
key = $19[$18];handler = $2[key];
server.context[key] = handler;
};

Expand All @@ -148,7 +148,7 @@ class ImbaRepl {

server.eval = function(cmd,context,file,cb) {

const compiledCode = _$ImbaCompilerφ.default.code(cmd,sessionId).get();
const compiledCode = $3.default.code(cmd,sessionId).get();

return cmdEval(compiledCode,context,file,async function(error,results) {

Expand Down
34 changes: 22 additions & 12 deletions lib/ImbaRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@ function requireDefault$__(obj){
Object.defineProperty(exports, "__esModule", {value: true});

/*body*/
var _$child_processφ = require('child_process'/*$path$*/);
var _$fsφ = requireDefault$__(require('fs'/*$path$*/));
var _$ImbaMissingExceptionφ = requireDefault$__(require('./Error/ImbaMissingException'/*$path$*/));
var _$pathφ = requireDefault$__(require('path'/*$path$*/));
var $1 = require('child_process'/*$path$*/);
var $2 = requireDefault$__(require('fs'/*$path$*/));
var $3 = requireDefault$__(require('./Error/ImbaMissingException'/*$path$*/));
var $4 = requireDefault$__(require('path'/*$path$*/));

class ImbaRunner {


static get ext(){

return (process.platform === 'win32') ? '.cmd' : '';
}

static get imba(){

const local = _$pathφ.default.join(process.cwd(),'node_modules','.bin','imbac');
const onboard = _$pathφ.default.join(__dirname,'..','node_modules','.bin','imbac');
const local = $4.default.join(process.cwd(),'node_modules','.bin','imba');
const onboard = $4.default.join(__dirname,'..','node_modules','.bin','imba');

return _$fsφ.default.existsSync(local) ? local : onboard;
return $2.default.existsSync(local) ? local : onboard;
}

static instance(){
/**
@param {Boolean} compiler
*/
static instance(compiler = false){

const file = this.imba + (compiler ? 'c' : '') + this.ext;

if (!(_$fsφ.default.existsSync(this.imba))) {
if (!($2.default.existsSync(file))) {

throw new _$ImbaMissingExceptionφ.default((`Imba not found at $` + (this.imba)));
throw new $3.default((`Imba not found at $` + file));
};

return this.imba;
return file;
}

static get version(){

return _$child_processφ.execSync(("" + this.instance() + " -v")).toString().trim();
return $1.execSync(("" + this.instance(true) + " -v")).toString().trim();
}
};
exports.default = ImbaRunner;
Loading

0 comments on commit 6057b2e

Please sign in to comment.