|
| 1 | +import { Prop } from '@formidablejs/console' |
1 | 2 | import { Command } from '../Command' |
2 | 3 | import { homedir } from 'os' |
3 | 4 | import { ImbaRepl } from 'imba-shell' |
4 | 5 | import { join } from 'path' |
| 6 | +import { existsSync } from 'fs-extra' |
5 | 7 | import type { REPLServer } from 'repl' |
6 | 8 |
|
7 | 9 | export class ShellCommand < Command |
8 | 10 |
|
| 11 | + get language |
| 12 | + const appPackage = join(process.cwd!, 'package.json') |
| 13 | + |
| 14 | + if !existsSync(appPackage) |
| 15 | + return 'imba' |
| 16 | + |
| 17 | + const value = require(appPackage).language || 'imba' |
| 18 | + |
| 19 | + value.toLowerCase! |
| 20 | + |
9 | 21 | get signature |
10 | | - 'shell' |
| 22 | + 'shell {?--language}' |
11 | 23 |
|
12 | 24 | get description |
13 | 25 | 'Interact with your application' |
14 | 26 |
|
| 27 | + get props |
| 28 | + { |
| 29 | + language: Prop.options('Language to use inside the shell').options(['imba', 'typescript']).default(language) |
| 30 | + } |
| 31 | + |
15 | 32 | get history |
16 | 33 | join homedir!, '.formidable_shell_history' |
17 | 34 |
|
18 | 35 | def handle |
19 | | - const repl = new ImbaRepl '>>> ', history |
| 36 | + const imbaRepl = new ImbaRepl option('language'), '>>> ', history |
20 | 37 |
|
21 | | - repl.registerCallback do(ctx) |
| 38 | + imbaRepl.registerCallback do(ctx) |
22 | 39 | const context = app.context.registered |
23 | 40 |
|
24 | 41 | Object.keys(context).forEach do(key) if !ctx[key] then ctx[key] = context[key] |
25 | 42 |
|
26 | | - const server\REPLServer = await repl.run! |
| 43 | + const server\REPLServer = await imbaRepl.run! |
27 | 44 |
|
28 | 45 | server.on 'exit', do self.exit! |
0 commit comments