Exemplo n.º 1
0
function run(mod, t) {
  t.plan(1)

  var ps = spawn('node', [
    '-e',
    'require("./")();require("' + mod + '")'
  ], {
    stdio: [ 'ignore', 'ignore', 'pipe' ]
  });

  ps.on('error', t.fail.bind(t));
  ps.on('close', function(code){
    t.is(code, 0, 'exit code is 0')
  })

  ps.stderr.on('data', function(chunk) {
    chunk.toString().split(/[\r\n]/).forEach(function(line){
      t.comment(line)
    })
  })
}
Exemplo n.º 2
0
    it('should render all watched files', function(done) {
      var src = fixture('simple/bar.scss');

      fs.writeFileSync(src, '');

      var bin = spawn(cli, [
        '--output-style', 'compressed',
        '--watch', src
      ]);

      bin.stdout.setEncoding('utf8');
      bin.stdout.once('data', function(data) {
        assert(data.trim() === 'body{background:white}');
        fs.unlinkSync(src);
        done();
      });

      setTimeout(function() {
        fs.appendFileSync(src, 'body{background:white}');
      }, 500);
    });
Exemplo n.º 3
0
    it('should watch the full sass dep tree for a single file', function(done) {
      var src = fixture('watching/index.scss');
      var foo = fixture('watching/foo.scss');

      fs.writeFileSync(foo, '');

      var bin = spawn(cli, [
        '--output-style', 'compressed',
        '--watch', src
      ]);

      bin.stdout.setEncoding('utf8');
      bin.stdout.once('data', function(data) {
        assert(data.trim() === 'body{background:white}');
        done();
      });

      setTimeout(function() {
        fs.appendFileSync(foo, 'body{background:white}\n');
      }, 500);
    });
Exemplo n.º 4
0
function testCmd (cmd, args, cb) {
  var oldDir = process.cwd()
  process.chdir(path.join(__dirname, '/fixtures'))

  var cmds = cmd.split(' ')

  var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)))
  process.chdir(oldDir)

  var stdout = ''
  bin.stdout.setEncoding('utf8')
  bin.stdout.on('data', function (str) { stdout += str })

  var stderr = ''
  bin.stderr.setEncoding('utf8')
  bin.stderr.on('data', function (str) { stderr += str })

  bin.on('close', function (code) {
    cb(code, stdout, stderr)
  })
}
Exemplo n.º 5
0
function executeCommand(cmd, args, cwd, cb) {
  console.log(chalk.yellow('Executing: ') + cmd + ' ' + args.join(' '));

  var child = spawn(cmd, args, {
    cwd: cwd
  });
  var result = '';

  child.stdout.on('data', function(buffer) {
    console.log(chalk.grey(buffer.toString()));
    result += buffer.toString();
  });

  child.stderr.on('data', function(buffer) {
    console.log(chalk.red(buffer.toString()));
  });

  child.stdout.on('end', function() {
    cb(result);
  });
}
Exemplo n.º 6
0
app.listen(port, function() {
	console.log('' + new Date(), 'server', 'runs on port', port)
	var spawn = require('cross-spawn')
	var runner = spawn(
		'./node_modules/.bin/nightwatch',
		[
			'--config', 'test/e2e/nightwatch.conf.js',
			'--env', 'chrome'
		],
		{
			stdio: 'inherit'
		}
	)

	runner.on('exit', function (code) {
		process.exit(code)
	})

	runner.on('error', function (err) {
		throw err
	})
})
Exemplo n.º 7
0
Arquivo: install.js Projeto: mklabs/yo
function installGenerator(app, pkgName) {
  app.insight.track('yoyo', 'install', pkgName);

  return spawn('npm', ['install', '--global', pkgName], {stdio: 'inherit'})
    .on('error', err => {
      app.insight.track('yoyo:err', 'install', pkgName);
      throw err;
    })
    .on('close', () => {
      app.insight.track('yoyo', 'installed', pkgName);

      console.log(
        '\nI just installed a generator by running:\n' +
        chalk.blue.bold('\n    npm install -g ' + pkgName + '\n')
      );

      app.env.lookup(() => {
        app.updateAvailableGenerators();
        app.navigate('home');
      });
    });
}
Exemplo n.º 8
0
function getnginxpath () {
	if (nginxpath === undefined) {
		let log = spawn('nginx', ['-t']);
		log = log.stdout.toString() || log.stderr.toString();
		nginxpath = path.resolve(log.toString().match(/.* file (.*)nginx\.conf test/)[1]);
	}
	let conf = fs.readFileSync(path.join(nginxpath, 'nginx.conf'), 'utf-8');
	if (conf.indexOf('include enabled_sites/*') === -1) {
		conf = conf.replace(/http ?\{/igm, 'http {\n\tinclude enabled_sites/*.conf;');
		fs.writeFileSync(path.join(nginxpath, 'nginx.conf'), conf);
		fs.mkdirsSync(path.join(nginxpath, 'enabled_sites'));
	}
	let confFile = 'testingapp.conf';
	fs.copySync(ProyPath(confFile), path.join(nginxpath, 'enabled_sites', confFile));
	let res = spawn('nginx', ['-s', 'reopen']).stderr.toString();

	while (res.indexOf('error') > -1) {
		spawnAsync('nginx', []);
		res = spawn('nginx', ['-s', 'reopen']).stderr.toString();
	}
	return nginxpath;
}
Exemplo n.º 9
0
gulp.task('website', [ 'build', 'watch' ], function (done) {

  // English config and Staging URL are the defaults
  var setConfig = process.env.npm_package_config_votegov_hugo_en;
  var setURL = 'http://localhost/';

  if ('spanish' === process.env.NODE_LANG) {
    setConfig = process.env.npm_package_config_votegov_hugo_es;
    setURL = 'http://localhost/es/';
  }

  gutil.log(
    gutil.colors.cyan('website'),
    'Using environment-specified --config path: ' + setConfig
  );

  gutil.log(
    gutil.colors.cyan('website'),
    'Using environment-specified BaseUrl: ' + setURL
  );

  var hugo_args = [
    'server',
    '--watch',
    '--buildDrafts',
    '--config=' + setConfig,
    '--baseURL=' + setURL,
  ];

  var hugo = spawn('hugo', hugo_args);

  hugo.stdout.on('data', function (data) {
    gutil.log(gutil.colors.blue('website'), '\n' + data);
  });

  hugo.on('error', done);
  hugo.on('close', done);

});
Exemplo n.º 10
0
    it.skip('should watch the full sass dep tree for a single file (sass)', function(done) {
      var src = fixture('watching/index.sass');
      var foo = fixture('watching/bar.sass');

      fs.writeFileSync(foo, '');

      var bin = spawn(cli, [
        '--output-style', 'compressed',
        '--watch', src
      ]);

      bin.stdout.setEncoding('utf8');
      bin.stdout.once('data', function(data) {
        assert.strictEqual(data.trim(), 'body{background:red}');
        bin.kill();
        done();
      });

      setTimeout(function() {
        fs.appendFileSync(foo, 'body\n\tbackground: red\n');
      }, 500);
    });
Exemplo n.º 11
0
    it('should emit nothing on file change when using --watch and --quiet options', function(done) {
      var src = fixture('simple/tmp.scss');
      var didEmit = false;
      fs.writeFileSync(src, '');

      var bin = spawn(cli, ['--watch', '--quiet', src]);

      bin.stderr.setEncoding('utf8');
      bin.stderr.once('data', function() {
        didEmit = true;
      });

      setTimeout(function() {
        fs.appendFileSync(src, 'body {}');
        setTimeout(function() {
          assert.equal(didEmit, false);
          bin.kill();
          done();
          fs.unlinkSync(src);
        }, 200);
      }, 500);
    });
Exemplo n.º 12
0
export default server => {
  const runner = spawn(
    './node_modules/.bin/nightwatch',
    [
      '--config', 'test/e2e/_nightwatch.conf.js',
      '--env', 'chrome'
    ],
    {
      stdio: 'inherit'
    }
  )

  runner.on('exit', function (code) {
    server.close()
    process.exit(code)
  })

  runner.on('error', function (err) {
    server.close()
    throw err
  })
}
Exemplo n.º 13
0
    return new Promise((resolve, rejct) => {
        command = 'git'
        args = [
            'clone'
        ].concat([
            templateRepository,
            root
        ])

        const child = spawn(command, args, { stdio: 'inherit' })
        child.on('close', code => {
            if (code !== 0) {
                reject({
                    command: `${command} ${args.join(' ')}`,
                })
                spinner.fail('clone template failed')
                return
            }
            removeRedundant(root)
            spinner.succeed('clone template succeed')
            resolve()
        })
    })
Exemplo n.º 14
0
 return new Promise(function (resolve, reject) {
     var args = cmd.split(/\s/g);
     var child = cross_spawn_1.default(args[0], args.slice(1), {
         cwd: _this.config.cwd,
     });
     child.stdout.on('data', function (data) {
         _this.out.log(data.toString());
     });
     child.stderr.on('data', function (data) {
         _this.out.log(data.toString());
     });
     child.on('error', function (err) {
         _this.out.error(err);
     });
     child.on('close', function (code) {
         if (code !== 0) {
             reject(code);
         }
         else {
             resolve();
         }
     });
 });
Exemplo n.º 15
0
    it('should compile with the --follow option', function(done) {
      var src = fixture('follow/input-dir');
      var dest = fixture('follow/output-dir');

      fs.mkdirSync(src);
      fs.symlinkSync(path.join(path.dirname(src), 'foo'), path.join(src, 'foo'), 'dir');

      var bin = spawn(cli, [src, '--follow', '--output', dest]);

      bin.once('close', function() {
        var expected = path.join(dest, 'foo/bar/index.css');
        fs.unlinkSync(path.join(src, 'foo'));
        fs.rmdirSync(src);
        assert(fs.existsSync(expected));
        fs.unlinkSync(expected);
        expected = path.dirname(expected);
        fs.rmdirSync(expected);
        expected = path.dirname(expected);
        fs.rmdirSync(expected);
        fs.rmdirSync(dest);
        done();
      });
    });
Exemplo n.º 16
0
    it.skip('should compile all changed files in watched directory', function(done) {
      var destDir = fixture('watching-css-out-02/');
      var srcDir = fixture('watching-dir-02/');
      var srcFile = path.join(srcDir, 'foo.scss');

      fs.writeFileSync(srcFile, '');

      var bin = spawn(cli, [
        '--output-style', 'compressed',
        '--output', destDir,
        '--watch', srcDir
      ]);

      setTimeout(function () {
        fs.appendFileSync(srcFile, 'body{background:white}\n');
        setTimeout(function () {
          bin.kill();
          var files = fs.readdirSync(destDir);
          assert.deepEqual(files, ['foo.css', 'index.css']);
          rimraf(destDir, done);
        }, 200);
      }, 500);
    });
Exemplo n.º 17
0
    it.skip('should watch whole directory', function(done) {
      var destDir = fixture('watching-css-out-01/');
      var srcDir = fixture('watching-dir-01/');
      var srcFile = path.join(srcDir, 'index.scss');

      fs.writeFileSync(srcFile, '');

      var bin = spawn(cli, [
        '--output-style', 'compressed',
        '--output', destDir,
        '--watch', srcDir
      ]);

      setTimeout(function() {
        fs.appendFileSync(srcFile, 'a {color:green;}\n');
        setTimeout(function() {
          bin.kill();
          var files = fs.readdirSync(destDir);
          assert.deepEqual(files, ['index.css']);
          rimraf(destDir, done);
        }, 200);
      }, 500);
    });
Exemplo n.º 18
0
 function spawn(exe, useCrossSpawn){
   args = self.template(args, id)
   log.info('spawning: ' + exe + ' - ' + JSON.stringify(args))
   if (useCrossSpawn) {
     self.process = crossSpawn(exe, args, options)
   }
   else {
     self.process = childProcess.spawn(exe, args, options)
   }
   self.process.once('close', self.onClose.bind(self))
   self.stdout = ''
   self.stderr = ''
   self.process.stdout.on('data', function(chunk){
     self.stdout += chunk
   })
   self.process.stderr.on('data', function(chunk){
     self.stderr += chunk
   })
   self.emit('processStarted', self.process)
   if (cb) {
     cb(self.process)
   }
 }
Exemplo n.º 19
0
module.exports = function (js, params) {
  var deferred = q.defer();
  console.log('\x1b[33m%s\x1b[0m', 'Starting fake server!');

  serverProcess = spawn('node', [js].concat(params));
  serverProcess.stdout.on('data', function () {
    deferred.resolve();
  });
  serverProcess.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
  });
  serverProcess.on('close', function () {
    console.log('\x1b[31m%s\x1b[0m', 'Fake server aborted!! This might mean port is already in use.');
    process.exit();
  });

  return {
    promise: deferred.promise,
    kill: function () {
      console.log('\x1b[33m%s\x1b[0m', 'Killing fake server!');
      serverProcess.kill();
    }
  };
};
Exemplo n.º 20
0
  return new Promise((resolve, reject) => {
    const outputs = []
    let failed = false

    const cp = spawn('node', [tmpFileName])
    cp.stdout.setEncoding('utf8')
    cp.stdout.on('data', data => {
      try {
        data.split(hookConsoleLog.messageSplitter)
          .filter(outputJSON => !!outputJSON)
          .map(outputJSON => JSON.parse(outputJSON))
          .forEach(outputInfo => outputs.push(outputInfo))
      } catch (err) {
        failed = true
        reject(err)
      }
    })
    let errData = ''

    cp.stderr.setEncoding('utf8')
    cp.stderr.on('data', data => { errData += data })

    cp.on('close', () => {
      fs.unlinkSync(tmpFileName)

      if (failed) {
        return
      }

      if (errData) {
        return reject(new Error(errData))
      }

      return resolve(outputs)
    })
  })
Exemplo n.º 21
0
 argue[m.type](m, uri, opts, function (err, args) {
     if (err) return cb(err);
     if (opts.noProxy && env.no_proxy === undefined) {
         env.no_proxy = opts.noProxy;
     }
     if (opts.proxy && env.http_proxy === undefined) {
         env.http_proxy = opts.proxy;
     }
     if (opts.proxy && env.HTTP_PROXY === undefined) {
         env.HTTP_PROXY = opts.proxy;
     }
     switch (process.platform) {
         case 'win32':
             m.command = m.command.replace(/"/g, ''); //Ensure all the quotes are removed
             cwd = require('path').dirname(m.command); //Change directory to the app's base (Chrome)
             break;
         case 'darwin':
             if (m.name !== 'firefox' && m.name !== 'phantom') { //Use the bin path under the hood
                 /*
                 This creates a command line structure like this:
                 open --wait-apps --new --fresh -a /Path/To/Executable <url> --args <rest of app args>
                 */
                 args.unshift('--args');
                 args.unshift(args.pop());
                 args.unshift(m.command);
                 args.unshift('-a');
                 args.unshift('--fresh');
                 args.unshift('--new');
                 args.unshift('--wait-apps');
                 m.command = 'open';
             }
             break;
     }
     cb(null, spawn(m.command, args, { env : env, cwd: cwd }));
     
 });
Exemplo n.º 22
0
  _startElectron (opts, cb) {
    var env = {}
    var exitStderr = ''
    if (this.xDisplay) env.DISPLAY = this.xDisplay
    var electronOpts = { env }
    if (opts.nodeIPC) electronOpts.stdio = [ 'ipc' ]
    this.child = spawn(opts.electron || electron, [ opts.daemonMain ], electronOpts)
    this.child.on('close', (code) => {
      if (this.closing) return
      var err = `electron-eval error: Electron process exited with code ${code}`
      if (exitStderr) err += `.\nStderr:\n${exitStderr}`
      this.error(new Error(err))
    })
    this.child.on('error', (err) => this.error(err))
    this.child.stderr.on('data', (data) => {
      exitStderr += `${data.toString()}${exitStderr ? '\n' : ''}`
    })

    process.on('exit', () => this.child.kill())

    if (!opts.nodeIPC) this._startIPC()

    this.child.once('message', (data) => {
      this.keepaliveInterval = setInterval(this.keepalive.bind(this), opts.timeout / 2)
      this.keepaliveInterval.unref()
      this.child.send(opts)
      this.child.once('message', (data) => {
        this.child.on('message', (message) => this.emit(message[0], message[1]))
        this.ready = true
        this.queue.forEach((item) => this.eval(...item))
        this.queue = null
        this.emit('ready')
        this.keepalive()
      })
    })
  }
Exemplo n.º 23
0
function updateGenerators(app, pkgs) {
  spawn('npm', ['install', '-g'].concat(pkgs), { stdio: 'inherit' })
    .on('close', updateSuccess.bind(null, app));
}
Exemplo n.º 24
0
  console.log('Starting server on http://127.0.0.1:3000')
})

// 2. run the nightwatch test suite against it
// to run in additional browsers:
//    1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
//    2. add it to the --env flag below
// or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
// For more information on Nightwatch's config file, see
// http://nightwatchjs.org/guide#settings-file
var opts = process.argv.slice(2)
if (opts.indexOf('--config') === -1) {
  opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js'])
}
if (opts.indexOf('--env') === -1) {
  opts = opts.concat(['--env', 'chrome'])
}

var spawn = require('cross-spawn')
var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })

runner.on('exit', function (code) {
  server.close()
  process.exit(code)
})

runner.on('error', function (err) {
  server.close()
  throw err
})
Exemplo n.º 25
0
function runCommand() {
  return spawn(BIN_COMMAND, [
    '--no-depcoprc', '-f', 'json'
  ], { cwd: ROOT_DIR });
}
Exemplo n.º 26
0
module.exports = function(appPath, appName, verbose, originalDirectory) {
  var ownPath = path.join(appPath, 'node_modules', 'react-scripts');

  var appPackage = require(path.join(appPath, 'package.json'));

  // Copy over some of the devDependencies
  appPackage.dependencies = appPackage.dependencies || {};
  appPackage.devDependencies = appPackage.devDependencies || {};

  // Setup the script rules
  appPackage.scripts = {
    'start': 'react-scripts start',
    'build': 'react-scripts build',
    'test': 'react-scripts test --env=jsdom',
    'eject': 'react-scripts eject'
  };

  // explicitly specify ESLint config path for editor plugins
  appPackage.eslintConfig = {
    extends: './node_modules/react-scripts/config/eslint.js',
  };

  fs.writeFileSync(
    path.join(appPath, 'package.json'),
    JSON.stringify(appPackage, null, 2)
  );

  var readmeExists = pathExists.sync(path.join(appPath, 'README.md'));
  if (readmeExists) {
    fs.renameSync(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md'));
  }

  // Copy the files for the user
  fs.copySync(path.join(ownPath, 'template'), appPath);

  // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
  // See: https://github.com/npm/npm/issues/1862
  fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), [], function (err) {
    if (err) {
      // Append if there's already a `.gitignore` file there
      if (err.code === 'EEXIST') {
        var data = fs.readFileSync(path.join(appPath, 'gitignore'));
        fs.appendFileSync(path.join(appPath, '.gitignore'), data);
        fs.unlinkSync(path.join(appPath, 'gitignore'));
      } else {
        throw err;
      }
    }
  });

  // Run another npm install for react and react-dom
  console.log('Installing react and react-dom from npm...');
  console.log();
  // TODO: having to do two npm installs is bad, can we avoid it?
  var args = [
    'install',
    'react',
    'react-dom',
    '--save',
    verbose && '--verbose'
  ].filter(function(e) { return e; });
  var proc = spawn('npm', args, {stdio: 'inherit'});
  proc.on('close', function (code) {
    if (code !== 0) {
      console.error('`npm ' + args.join(' ') + '` failed');
      return;
    }

    // Display the most elegant way to cd.
    // This needs to handle an undefined originalDirectory for
    // backward compatibility with old global-cli's.
    var cdpath;
    if (originalDirectory &&
        path.join(originalDirectory, appName) === appPath) {
      cdpath = appName;
    } else {
      cdpath = appPath;
    }

    console.log();
    console.log('Success! Created ' + appName + ' at ' + appPath + '.');
    console.log('Inside that directory, you can run several commands:');
    console.log();
    console.log('  * npm start: Starts the development server.');
    console.log('  * npm test: Starts the test runner.');
    console.log('  * npm run build: Bundles the app into static files for production.');
    console.log('  * npm run eject: Removes this tool. If you do this, you can’t go back!');
    console.log();
    console.log('We suggest that you begin by typing:');
    console.log();
    console.log('  cd', cdpath);
    console.log('  npm start');
    if (readmeExists) {
      console.log();
      console.log(chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`'));
    }
    console.log();
    console.log('Happy hacking!');
  });
};
Exemplo n.º 27
0
 * 	2. add it to the --env flag below or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
 * For more information on Nightwatch"s config file, see http://nightwatchjs.org/guide#settings-file
 */

let opts = process.argv.slice(2);
if (opts.indexOf("--config") === -1) {
	opts = opts.concat([
		"--config",
		"test/e2e/nightwatch.conf.js"
	]);
}
if (opts.indexOf("--env") === -1) {
	opts = opts.concat([
		"--env",
		"chrome"
	]);
}

const spawn = require("cross-spawn");
const runner = spawn("./node_modules/.bin/nightwatch", opts, {stdio: "inherit"});

runner.on("exit", function (code) {
	server.close();
	process.exit(code);
});

runner.on("error", function (err) {
	server.close();
	throw err;
});
Exemplo n.º 28
0
// 1. start the dev server using production config
process.env.NODE_ENV = 'testing';
var server = require('../../build/dev-server.js');

// 2. run the nightwatch test suite against it
// to run in additional browsers:
//    1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
//    2. add it to the --env flag below
// For more information on Nightwatch's config file, see
// http://nightwatchjs.org/guide#settings-file
var spawn = require('cross-spawn');
var runner = spawn(
  './node_modules/.bin/nightwatch',
  [
    '--config', 'test/e2e/nightwatch.conf.js',
    '--env', 'chrome,firefox'
  ],
  {
    stdio: 'inherit'
  }
);

runner.on('exit', function (code) {
  server.close();
  process.exit(code)
});

runner.on('error', function (err) {
  server.close();
  throw err
});
Exemplo n.º 29
0
gulp.task('jekyll-build', function(done) {
  browserSync.notify(config.notification);
  // Spawn jekyll commands
  return spawn('bundle', ['exec', 'jekyll', 'build'], {stdio: 'inherit'})
    .on('close', done);
});
module.exports = function spawnCommand(command, args, opt) {
  opt = opt || {};
  return spawn(command, args, _.defaults(opt, { stdio: 'inherit' }));
};