import { join } from "path";
import { execute } from "../helpers/execute";
import chalk from "chalk";

export default class Local {
  private volume: string;
  private build: string;

  constructor(servicePath: string, build: string) {
    this.build = build;
    this.volume = join(servicePath);
  }

  private async run() {
    const args: string[] = ["-c", `'${this.build}'`];

    this.printCommand(args);

    await execute('sh', args, {
      cwd: this.volume,
      stdio: 'inherit',
      shell: true
    });
  }

  private async printCommand(args: string[]) {
    console.log(chalk.gray("$ sh", args.join(" ")));
  }

  static async start(servicePath: string, build: string) {
    const local: Local = new Local(servicePath, build);
    return await local.run();
  }

  static async stop(servicePath: string, build: string) {
    // TODO::STOP
  }
}
