tiagob / create-full-stack

Set up a TypeScript full stack with one command.
https://create-full-stack.com
MIT License
97 stars 9 forks source link

Heroku/Pulumi cloud option #156

Open tiagob opened 3 years ago

tiagob commented 3 years ago

RDS & Fargate replacement

Cloud Front replacement

austinrivas commented 3 years ago

it might just be easiest to call the hasura pro cli directly from ts using shelljs?

//#region Global Imports
import * as shell from 'shelljs';
//#endregion Global Imports

//#region Local Imports
import {
  ShellExecResponse,
  ShellExecSuccess,
  ShellExecError,
  ShellExecTimeoutError,
  ShellExecNotFoundError,
} from './Responses';
import { ShellExecOptions } from '@Modules/shell-utils/Interfaces';
//#endregion Local Imports

export const SHELL_DEFAULT_SETTINGS: ShellExecOptions = {
  silent: true,
  simple: true,
};

/*eslint complexity: ["error", 9]*/
export const handleShellResponse = (
  code: number | null,
  stdout: string | null,
  stderr: string | null,
  command: string,
  settings: ShellExecOptions,
  resolve: (value?: ShellExecSuccess) => void,
  reject: (value?: ShellExecError) => void,
): void => {
  switch (code) {
    case 0: // success
      return resolve(
        new ShellExecSuccess(code, stdout, stderr, command, settings),
      );
    // If there is an error then reject
    case null: // timeout
      return reject(
        new ShellExecTimeoutError(code, stdout, stderr, command, settings),
      );
    case 127: // not-found
      return reject(
        new ShellExecNotFoundError(code, stdout, stderr, command, settings),
      );
    case 1: // Catch-all
    case 2: // Misuse of shell builtins (according to Bash documentation)
    case 126: // Command invoked cannot execute
    case 128: // Invalid argument to exit
    case 130: // Script terminated by Control-C
    default:
      return reject(
        new ShellExecError(code, stdout, stderr, command, settings),
      );
  }
};

export const shellExec = async (
  command: string,
  settings: ShellExecOptions = SHELL_DEFAULT_SETTINGS,
): Promise<ShellExecResponse> => {
  return new Promise((resolve, reject) => {
    shell.exec(
      command,
      settings,
      (code: number | null, stdout: string | null, stderr: string | null) => {
        handleShellResponse(
          code,
          stdout,
          stderr,
          command,
          settings,
          resolve,
          reject,
        );
      },
    );
  });
};