/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
build-system/common/process.js
67 строк
2 KB
Kristofer Baxter
♻️ Remove Notice from JS and Markdown (#35717)
19 авг 2021, 21:21
Не верифицирован
19 авг 2021, 21:21
f564b7e
Код
Авторство
О чём код?
'use strict'; /** * @fileoverview Provides functions for executing tasks in a child process. * Separated from `exec` to allow import before `npm` installs dependencies. */ const childProcess = require('child_process'); const shellCmd = process.platform == 'win32' ? 'cmd' : '/bin/bash'; /** * Spawns the given command in a child process with the given options. * Special-cases the AMP task runner so that it is correctly spawned on all * platforms (node shebangs do not work on Windows). * * @param {string} cmd * @param {?Object} options * @return {!Object} */ function spawnProcess(cmd, options) { const cmdToSpawn = cmd.startsWith('amp ') ? `node ${cmd}` : cmd; return childProcess.spawnSync(cmdToSpawn, {shell: shellCmd, ...options}); } /** * Executes the provided command, returning the process object. * @param {string} cmd * @param {?Object=} options * @return {!Object} */ function getOutput(cmd, options = {}) { const p = spawnProcess(cmd, { 'cwd': options.cwd || process.cwd(), 'env': options.env || process.env, 'stdio': options.stdio || 'pipe', 'encoding': options.encoding || 'utf-8', }); return p; } /** * Executes the provided command, returning its stdout. * @param {string} cmd * @param {?Object=} options * @return {string} */ function getStdout(cmd, options) { return getOutput(cmd, options).stdout; } /** * Executes the provided command, returning its stderr. * @param {string} cmd * @param {?Object=} options * @return {string} */ function getStderr(cmd, options) { return getOutput(cmd, options).stderr; } module.exports = { getOutput, getStderr, getStdout, spawnProcess, };