child_process#ExecException TypeScript Examples

The following examples show how to use child_process#ExecException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: get-definitely-typed.ts    From DefinitelyTyped-tools with MIT License 6 votes vote down vote up
export async function getDefinitelyTyped(options: ParseDefinitionsOptions, log: LoggerWithErrors): Promise<FS> {
  if (options.definitelyTypedPath === undefined) {
    log.info("Downloading Definitely Typed ...");
    await ensureDir(dataDirPath);
    log.info(dataDirPath + " exists.");
    return downloadAndExtractFile(definitelyTypedZipUrl, log);
  }
  const { error, stderr, stdout } = await exec("git diff --name-only", options.definitelyTypedPath);
  if (error) {
    throw new Error(error.message + ": " + (error as ExecException).cmd);
  }
  if (stderr) {
    throw new Error(stderr);
  }
  if (stdout) {
    throw new Error(`'git diff' should be empty. Following files changed:\n${stdout}`);
  }
  log.info(`Using local DefinitelyTyped at ${options.definitelyTypedPath}`);
  return new DiskFS(`${options.definitelyTypedPath}/`);
}
Example #2
Source File: exec.ts    From cli with MIT License 6 votes vote down vote up
exec = (options: {
  cmd: string;
  baseDir?: string;
  slience?: boolean;
  log?: (...msg: any[]) => void;
}): Promise<string | ExecException> => {
  const { cmd, baseDir, slience, log } = options;
  return new Promise((resolved, rejected) => {
    const execProcess = cpExec(
      cmd,
      {
        cwd: baseDir,
      },
      (err, result) => {
        if (err) {
          return rejected(err);
        }
        resolved(result);
      }
    );
    execProcess.stdout.on('data', data => {
      if (!slience) {
        (log || console.log)(data);
      }
    });
  });
}
Example #3
Source File: terraform-fmt.ts    From airnode with MIT License 5 votes vote down vote up
function failOnError(message: string, err: ExecException | null, stderr: string) {
  if (err) {
    logger.error(message);
    logger.error(err.message);
    logger.error(stderr);
    exit(EC_TERRAFORM);
  }
}
Example #4
Source File: findNonIgnoredFiles.ts    From vscode-markdown-notes with GNU General Public License v3.0 5 votes vote down vote up
// TODO: https://github.com/Microsoft/vscode/blob/release/1.27/extensions/git/src/api/git.d.ts instead of git shell if possible
async function filterGitIgnored(uris: Uri[]): Promise<Uri[]> {
  const workspaceRelativePaths = uris.map((uri) => workspace.asRelativePath(uri, false));
  for (const workspaceDirectory of workspace.workspaceFolders!) {
    const workspaceDirectoryPath = workspaceDirectory.uri.fsPath;
    try {
      const { stdout, stderr } = await new Promise<{ stdout: string; stderr: string }>(
        (resolve, reject) => {
          exec(
            `git check-ignore ${workspaceRelativePaths.join(' ')}`,
            { cwd: workspaceDirectoryPath },
            // https://git-scm.com/docs/git-check-ignore#_exit_status
            (error: ExecException | null, stdout, stderr) => {
              if (error && error.code !== 0 && error.code !== 1) {
                reject(error);
                return;
              }

              resolve({ stdout, stderr });
            }
          );
        }
      );

      if (stderr) {
        throw new Error(stderr);
      }

      for (const relativePath of stdout.split('\n')) {
        const uri = Uri.file(
          join(workspaceDirectoryPath, relativePath.slice(1, -1) /* Remove quotes */)
        );
        const index = uris.findIndex((u) => u.fsPath === uri.fsPath);
        if (index > -1) {
          uris.splice(index, 1);
        }
      }
    } catch (error) {
      console.error('findNonIgnoredFiles-git-exec-error', error);
      //   applicationInsights.sendTelemetryEvent('findNonIgnoredFiles-git-exec-error');
    }
  }
  return uris;
}