-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8f9cdc
commit fd8b047
Showing
12 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { cli } from '../../cli.js' | ||
import { RunCommand } from '../run.js' | ||
|
||
describe('leon run', () => { | ||
it('should be instance of the command', () => { | ||
const command = cli.process(['run']) | ||
expect(command).toBeInstanceOf(RunCommand) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Command, Option } from 'clipanion' | ||
import execa from 'execa' | ||
|
||
import { LeonInstance } from '../services/LeonInstance.js' | ||
import { log } from '../services/Log.js' | ||
import { CheckCommand } from './check.js' | ||
import { StartCommand } from './start.js' | ||
|
||
interface Builtin { | ||
[key: string]: (leonInstance: LeonInstance) => Promise<void> | ||
} | ||
|
||
const BUILTIN_COMMANDS: Builtin = { | ||
start: StartCommand.run, | ||
check: CheckCommand.run | ||
} | ||
|
||
const BUILTIN_COMMANDS_KEYS = Object.keys(BUILTIN_COMMANDS) | ||
|
||
export class RunCommand extends Command { | ||
static paths = [['run']] | ||
|
||
static usage = { | ||
description: | ||
'Run a npm script from a Leon Instance (e.g: `leon run train` runs `npm run train` in the leon instance folder).' | ||
} | ||
|
||
public name = Option.String('--name', { | ||
description: 'Name of the Leon instance.' | ||
}) | ||
|
||
public script = Option.Proxy() | ||
|
||
async execute(): Promise<number> { | ||
try { | ||
const script = this.script.join(' ') | ||
const command = 'npm run ' + script | ||
const leonInstance = LeonInstance.get(this.name) | ||
const isBuiltin = BUILTIN_COMMANDS_KEYS.includes(script) | ||
if (isBuiltin) { | ||
const runCommand = BUILTIN_COMMANDS[script] | ||
await runCommand(leonInstance) | ||
return 0 | ||
} | ||
process.chdir(leonInstance.path) | ||
await execa.command(command, { stdio: 'inherit' }) | ||
return 0 | ||
} catch (error) { | ||
log.error({ | ||
error, | ||
commandPath: 'run' | ||
}) | ||
return 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import execa from 'execa' | ||
|
||
export const test5Run = (): void => { | ||
test('leon run', async () => { | ||
const result = await execa('leon', ['run', 'train']) | ||
expect(result.exitCode).toEqual(0) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters