Skip to content

Commit

Permalink
feat(commands/up): new task composer install on lvl up
Browse files Browse the repository at this point in the history
Composer installing new task added on `lvl up`

fix badassery#13
  • Loading branch information
panchaldeep009 committed Oct 10, 2019
1 parent d97263a commit 74498ca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/commands/composer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Command, flags } from "@oclif/command";
import * as shelljs from "shelljs";
import { execAsync } from "../providers/execAsync";

export default class Composer extends Command {
static description = "Executes a composer command";
Expand Down Expand Up @@ -37,7 +38,9 @@ export default class Composer extends Command {
commandText = commandText = `${commandText} --help`;
}

shelljs.exec(commandText, {
// waiting for complete standard output of shalljs.exec

await execAsync(commandText, {
silent: flags.silent && !flags["command-help"]
});
}
Expand Down
31 changes: 21 additions & 10 deletions src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "../actions";
import Listr from "listr";
import * as ip from "ip";
import Composer from "./composer";
import { execAsync } from "../providers/execAsync";

export default class Up extends Command {
static description = "Spins Up your local dev environment";
Expand Down Expand Up @@ -41,26 +43,35 @@ export default class Up extends Command {
const xdebugIp = ip.address();

const tasks = new Listr([
// {
// title: "Checking Composer install",
// task: noop,
// skip: () => "Packages are already installed"
// },
{
title: `Setting XDebug Remote Host to ${xdebugIp}`,
task: () => configureXdebug(directory, xdebugIp)
task: async (ctx, task) => {
await configureXdebug(directory, xdebugIp);
task.title = `Setup XDebug Remote Host to ${xdebugIp}`;
}
},
{
title: "Starting Docker Services",
task: async () => {
const output = await shelljs
.exec("docker-compose up -d", { silent: !flags.verbose })
.stderr.toString();
task: async (ctx, task) => {
const { stderr } = await execAsync("docker-compose up -d", {
silent: !flags.verbose
});

const output = stderr.toString();
task.title = "Setup Docker Services";

if (output.includes("ERROR")) {
throw new Error("Failed to start Docker Services");
}
}
},
{
title: "Composer",
task: async (ctx, task) => {
task.output = "Installing";
await Composer.run(["install", "-s"]);
task.title = "Composer Packages ready";
}
}
// {
// title: "Verifying App Key",
Expand Down
14 changes: 14 additions & 0 deletions src/providers/execAsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as shelljs from "shelljs";

/**
* Async version of shelljs.exec to resolve callback function output
* @param command Command String
* @param options Shelljs Execution Option
*/
export const execAsync = (command: string, options: shelljs.ExecOptions = {}) =>
new Promise<{ stdout: string; stderr: string }>((resolve, reject) => {
shelljs.exec(command, options, (code, stdout, stderr) => {
if (code != 0) return reject(new Error(stderr));
return resolve({ stdout, stderr });
});
});

0 comments on commit 74498ca

Please sign in to comment.