How to use the cross-spawn.sync function in cross-spawn

To help you get started, we’ve selected a few cross-spawn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codejamninja / reactant / packages / context / src / state.ts View on Github external
// eslint-disable-next-line import/no-dynamic-require,global-require
        require.resolve('find-process', {
          paths: [
            path.resolve(pkgDir.sync(__dirname) || __dirname, 'node_modules'),
            path.resolve(rootPath, 'node_modules')
          ]
        })
      ) || path.resolve(rootPath, 'node_modules');
    const bin = path.resolve(
      pkgPath,
      // eslint-disable-next-line import/no-dynamic-require,global-require
      require(path.resolve(pkgPath, 'package.json')).bin['find-process']
    );
    return !/No process found/.test(
      (
        crossSpawn.sync('node', [bin, pid.toString()], {
          stdio: 'pipe'
          // eslint-disable-next-line no-undef
        })?.stdout || ''
      ).toString()
    );
  }
github tricinel / frontwerk / src / scripts / prettier.js View on Github external
const path = require('path');
const spawn = require('cross-spawn');

const { warning, info } = require('../utils/logger');

const [executor, script, ...args] = process.argv; // eslint-disable-line no-unused-vars
const scriptPath = require.resolve(path.join(__dirname, 'format'));

// Show deprecation warning
warning('This command will be deprecated in a future version of frontwerk!');
info(
  'Please use frontwerk format instead.',
  'You can pass the same options and it will work in the same way.'
);

const result = spawn.sync(executor, [scriptPath, ...args], {
  stdio: 'inherit'
});

process.exit(result.status);
github DimiMikadze / create-social-network / lib / createSocialNetwork.js View on Github external
console.log();
  console.log('Installing dependencies');
  console.log();
  // Since npm doesn't support workspaces, we need to separately install dependencies
  if (packageManager === 'npm') {
    spawn.sync('npm', ['install'], { cwd: `${projectName}`, stdio: 'inherit' });
    spawn.sync('npm', ['install'], {
      cwd: `${projectName}/api`,
      stdio: 'inherit',
    });
    spawn.sync('npm', ['install'], {
      cwd: `${projectName}/frontend`,
      stdio: 'inherit',
    });
  } else {
    spawn.sync('yarn', { cwd: `${projectName}`, stdio: 'inherit' });
  }

  // Rename .env.examples to .env
  fs.renameSync(`${projectName}/api/.env.example`, `${projectName}/api/.env`);
  fs.renameSync(
    `${projectName}/frontend/.env.example`,
    `${projectName}/frontend/.env`
  );

  // Remove .git and lib
  rimraf.sync(`${projectName}/.git`);
  rimraf.sync(`${projectName}/lib`);

  // Remove LICENSE.md, CONTRIBUTING.md and similar files
  rimraf.sync(`${projectName}/LICENSE.md`);
  rimraf.sync(`${projectName}/CONTRIBUTING.md`);
github iamturns / create-exposed-app / src / common / spawn.ts View on Github external
command: string,
  {
    commandOptions = { stdio: "inherit" },
    exitOnComplete = false,
    exitOnError = true,
  }: SpawnOptions = {},
): SpawnSyncReturns {
  logDebug("Spawning command: %s", command)
  logDebug("Command options: %j", commandOptions)
  logDebug("Exit on complete: %j", exitOnComplete)
  logDebug("Exit on error: %j", exitOnError)

  const commandParts = getCommandParts(command)
  logDebug("Command parts: %j", commandParts)

  const response = crossSpawn.sync(
    commandParts.command,
    commandParts.args,
    commandOptions,
  )
  logDebug("Response status: %j", response.status)

  if (shouldExit(exitOnComplete, exitOnError, response)) {
    logDebug("shouldExit = true")
    process.exit(response.status) // eslint-disable-line unicorn/no-process-exit
  }

  return response
}
github react-community / create-react-native-app / react-native-scripts / src / scripts / eject.js View on Github external
log('Removing node_modules...');
      rimraf.sync(path.resolve('node_modules'));
      if (useYarn) {
        log('Installing packages with yarn...');
        const args = newDevDependencies.length > 0 ? ['add', '--dev', ...newDevDependencies] : [];
        spawn.sync('yarnpkg', args, { stdio: 'inherit' });
      } else {
        // npm prints the whole package tree to stdout unless we ignore it.
        const stdio = [process.stdin, 'ignore', process.stderr];

        log('Installing existing packages with npm...');
        spawn.sync('npm', ['install'], { stdio });

        if (newDevDependencies.length > 0) {
          log('Installing new packages with npm...');
          spawn.sync('npm', ['install', '--save-dev', ...newDevDependencies], {
            stdio,
          });
        }
      }
    } else if (ejectMethod === 'expoKit') {
      await detach();
    } else {
      // we don't want to print the survey for cancellations
      log('OK! If you change your mind you can run this command again.');
      return;
    }

    log(
      `${chalk.green('Ejected successfully!')}
Please consider letting us know why you ejected in this survey:
  ${chalk.cyan('https://goo.gl/forms/iD6pl218r7fn9N0d2')}`
github lydell / LinkHints / scripts / build-post.js View on Github external
function getGitCommit(): string {
  const result = spawn.sync("git", ["rev-parse", "HEAD"], {
    encoding: "utf-8",
  });

  if (result.error != null) {
    throw result.error;
  }

  if (result.stderr !== "") {
    if (result.stderr.includes("not a git repository")) {
      return "(outside git repository)";
    }
    throw new Error(result.stderr);
  }

  return result.stdout.toString().trim();
}
github quasarframework / quasar-cli / lib / helpers / spawn.js View on Github external
module.exports.sync = function (cmd, params, cwd, onFail) {
  log(`[sync] Running "${cmd} ${params.join(' ')}"`)
  log()

  const runner = spawn.sync(
    cmd,
    params,
    { stdio: 'inherit', stdout: 'inherit', stderr: 'inherit', cwd }
  )

  if (runner.status || runner.error) {
    warn()
    warn(`⚠️  Command "${cmd}" failed with exit code: ${runner.status}`)
    if (runner.status === null) {
      warn(`⚠️  Please globally install "${cmd}"`)
    }
    onFail && onFail()
    process.exit(1)
  }
}
github tricinel / frontwerk / src / scripts / format.js View on Github external
const useBuiltinIgnore =
  !args.includes('--ignore-path') && !fileExists('.prettierignore');

const ignore = useBuiltinIgnore
  ? ['--ignore-path', getConfig('prettierignore')]
  : [];

const write = args.includes('--no-write') ? [] : ['--write'];

const filesToApply = parsedArgs._.length
  ? parsedArgs._
  : ['**/*.+(js|jsx|json|css|ts|md)'];

start(whichConfig('prettier'));

const result = spawn.sync(
  resolveBin('prettier'),
  [...config, ...ignore, ...write, ...filesToApply],
  { stdio: 'inherit' }
);

process.exit(result.status);
github lydell / LinkHints / scripts / png-icons.js View on Github external
function svgToPng(svgPath, pngPath) {
  spawn.sync("inkscape", ["-z", "-e", pngPath, svgPath], {
    stdio: "inherit",
  });

  spawn.sync("optipng", ["-strip", "all", "-o7", pngPath], {
    stdio: "inherit",
  });
}
github searchkit / searchkit / scripts / deploy.js View on Github external
const spawnWithErrorHandling = (...args) => {
  const results = spawn.sync(...args);
  if (results.error) {
    throw results.error;
  }
};