diff --git a/.gitignore b/.gitignore index 1aa8760..5ae26f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /node_modules /public +/dist .env .env.backup npm-debug.log diff --git a/README.md b/README.md index b021660..bebb3fc 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,12 @@ To start using `imba-shell`, run the following command: imba-shell ``` +To enable TypeScript, you can pass the `--ts` flag: + +```bash +imba-shell --ts +``` + > Note, you can also use `imbas` instead of `imba-shell`. ### Multiline @@ -129,7 +135,8 @@ Imba: ```py import { ImbaRepl } from 'imba-shell' -const repl = new ImbaRepl 'imba> ' +# you can also pass "typescript" instead of "imba" +const repl = new ImbaRepl 'imba', 'imba> ' repl.run! ``` @@ -139,7 +146,8 @@ JavaScript: ```js const { ImbaRepl } = require('imba-shell'); -const repl = new ImbaRepl('imba> '); +/** you can also pass "typescript" instead of "imba" */ +const repl = new ImbaRepl('imba', 'imba> '); repl.run(); ``` @@ -157,7 +165,7 @@ import { ImbaRepl } from 'imba-shell' import os from 'os' import path from 'path' -const repl = new ImbaRepl 'imba> ', path.join(os.homedir!, '.my_repl_history') +const repl = new ImbaRepl 'imba', 'imba> ', path.join(os.homedir!, '.my_repl_history') repl.run! ``` @@ -169,7 +177,7 @@ const { ImbaRepl } = require('imba-shell'); const os = require('os'); const path = require('path'); -const repl = new ImbaRepl('imba> ', path.join(os.homedir(), '.my_repl_history')); +const repl = new ImbaRepl('imba', 'imba> ', path.join(os.homedir(), '.my_repl_history')); repl.run(); ``` @@ -227,12 +235,25 @@ When calling `foo` in the REPL, it will return `bar`. Todo ------- -- ☑ Code completion. -- ☑ Multiline Editor. -- ☑ Async/Await. -- ☑ Extensible API. -- ☒ Syntax highlighting. -- ☒ Imba Compile Errors. +- [x] Language Support. + - [x] Imba. + - [x] TypeScript. +- [x] Code completion. + - [x] Imba. + - [x] TypeScript. +- [x] Multiline Editor. + - [x] Imba. + - [x] TypeScript. +- [x] Async/Await. + - [x] Imba. + - [x] TypeScript. +- [x] Extensible API. +- [ ] Syntax highlighting. + - [ ] Imba. + - [ ] TypeScript. +- [ ] Compile Errors. + - [ ] Imba. + - [x] TypeScript. Development ----- diff --git a/bin/repl b/bin/repl index 17ed1ab..9b8c216 100755 --- a/bin/repl +++ b/bin/repl @@ -1,24 +1,29 @@ #!/usr/bin/env node -const { Command, ImbaRepl } = require('../lib'); +const { Command, ImbaRepl } = require('../dist'); const imba = require('imba'); const os = require('os'); const path = require('path'); class ReplCommand extends Command { - handle() { - const repl = new ImbaRepl('>>> ', path.join(os.homedir(), '.imba_shell_history')); + /** + * @param {string} language + */ + handle(language) { + const repl = new ImbaRepl(language, '>>> ', path.join(os.homedir(), '.imba_shell_history')); - /** load imba. */ - repl.registerCallback((ctx) => { - Object.keys(imba).forEach((key) => { - if (!ctx[key]) { - ctx[key] = imba[key]; - } + if (language == 'imba') { + /** load imba. */ + repl.registerCallback((ctx) => { + Object.keys(imba).forEach((key) => { + if (!ctx[key]) { + ctx[key] = imba[key]; + } + }); }); - }); + } - repl.shouldUpdate().run({ ignoreUndefined: true }); + repl.shouldUpdate().run({ ignoreUndefined: true, useColors: language == 'typescript' }); } } diff --git a/bin/runtime b/bin/runtime index fed9be1..1fd624c 100755 --- a/bin/runtime +++ b/bin/runtime @@ -1,6 +1,6 @@ #!/usr/bin/env node -const { Command } = require('../lib'); +const { Command } = require('../dist'); class RuntimeCommand extends Command { get isRuntime() { diff --git a/lib/Command.js b/lib/Command.js deleted file mode 100644 index 757bc9c..0000000 --- a/lib/Command.js +++ /dev/null @@ -1,154 +0,0 @@ -function requireDefault$__(obj){ - return obj && obj.__esModule ? obj : { default: obj }; -}; -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 $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 { - [$10]($$ = null){ - var $12; - this.args = ($$ && ($12 = $$.args) !== undefined) ? ($12) : []; - this.watch = ($$ && ($12 = $$.watch) !== undefined) ? ($12) : false; - - } - get isRuntime(){ - - return false; - } - - constructor(){ - this[$10](); - this.args = process.argv.slice(2); - } - - enableWatcher(){ - - this.watch = true; - - return this.args = this.args.filter(function(arg) { return !(['-w','--watch'].includes(arg)); }); - } - - printVersion(){ - - return console.log(("Imba Shell v" + $8.version + " (imba " + ($9.default.version) + ")")); - } - - displayHelp(){ - - console.log("\x1b[32mUsage:\x1b[0m\n [\x1b[2m