ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

cp.js (850B)


      1 /**
      2  * React Starter Kit (https://www.reactstarterkit.com/)
      3  *
      4  * Copyright © 2014-present Kriasoft, LLC. All rights reserved.
      5  *
      6  * This source code is licensed under the MIT license found in the
      7  * LICENSE.txt file in the root directory of this source tree.
      8  */
      9 
     10 import cp from 'child_process';
     11 
     12 export const spawn = (command, args, options) => new Promise((resolve, reject) => {
     13   cp.spawn(command, args, options).on('close', (code) => {
     14     if (code === 0) {
     15       resolve();
     16     } else {
     17       reject(new Error(`${command} ${args.join(' ')} => ${code} (error)`));
     18     }
     19   });
     20 });
     21 
     22 export const exec = (command, options) => new Promise((resolve, reject) => {
     23   cp.exec(command, options, (err, stdout, stderr) => {
     24     if (err) {
     25       reject(err);
     26       return;
     27     }
     28 
     29     resolve({ stdout, stderr });
     30   });
     31 });
     32 
     33 export default { spawn, exec };