How to use hook-std - 7 common examples

To help you get started, we’ve selected a few hook-std 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 webiny / webiny-js / packages-utils / webiny-semantic-release / src / index.js View on Github external
export default async config => {
    const { params, plugins } = await buildParams(config);

    // Connect to the stdout and process each line of the output using `stdOut` function
    const unhook = hookStd({ silent: false }, stdOut);
    try {
        await compose([verifyEnvironment(), ...plugins])(params);
        unhook();
        return params;
    } catch (err) {
        unhook();
        throw err;
    }
};
github gulp-sourcemaps / gulp-sourcemaps / test / init.js View on Github external
test('init: should output an error message if debug option is set and sourceContent is missing', function(t) {

    var file = makeFile();
    file.contents = new Buffer(sourceContent + '\n//# sourceMappingURL=helloworld4.js.map');

    var history = [];
    console.log('HOOKING');
    var unhook = hookStd.stderr(function(s) {
      history.push(s);
    });
    var pipeline = sourcemaps.init({loadMaps: true});

    pipeline.on('data', function() {
      unhook();
      var hasRegex =  function(regex){
        return function(s){
          return regex.test(s);
        };
      };
      console.log(history);
      t.ok(
        history.some(
          hasRegex(/No source content for "missingfile". Loading from file./g)), 'should log missing source content');
      t.ok(history.some(hasRegex(/source file not found: /g)), 'should warn about missing file');
github gulp-sourcemaps / gulp-sourcemaps / test / write.js View on Github external
test('write: should output an error message if debug option is set and sourceContent is missing', function(t) {
    var file = makeFile();
    file.sourceMap.sources[0] += '.invalid';
    delete file.sourceMap.sourcesContent;

    var history = [];
    var unhook = hookStd.stderr(function(s) {
      history.push(s);
    });
    var pipeline = sourcemaps.write();

    var hasRegex =  function(regex){
      return function(s){
        return regex.test(s);
      };
    };
    pipeline.on('data', function() {
      unhook();
      console.log(JSON.stringify(history));
      t.ok(history.some(hasRegex(/No source content for "helloworld.js.invalid". Loading from file./g)), 'should log missing source content');
      t.ok(history.some(hasRegex(/source file not found: /g)), 'should warn about missing file');
      t.end();
    }).write(file);
github twitch-js / twitch-js / test / logger.js View on Github external
it('should log to the console', () => {
    let out = '';

    const unhook = hookStd.stdout({ silent: true }, output => {
      out += output;
    });

    log.setLevel('info');
    log.info('foobar');

    unhook();

    const expected = out.trim();
    expected.should.containEql('info: foobar');
  });
});
github tmijs / tmi.js / test / logger.js View on Github external
it("logs to the console", function() {
		var out = '';

		var unhook = hookStd.stdout({silent: true}, function(output) {
			out += output;
		});

		log.setLevel('info');
		log.info('foobar');

		unhook();

		var expected = out.trim();
		expected.should.containEql('info: foobar');
	});
});
github heroku / heroku-cli-util / test / spinner.js View on Github external
function readOutput (spinner, callback) {
    let out = ''

    const unhook = hookStd.stderr({silent: true}, output => {
      out += output
    })

    spinner.start()
    spinner.stop()
    unhook()

    callback(out)
  }
github sindresorhus / alfy / index.js View on Github external
alfy.debug = getEnv('debug') === '1';

alfy.icon = {
	get: getIcon,
	info: getIcon('ToolbarInfo'),
	warning: getIcon('AlertCautionIcon'),
	error: getIcon('AlertStopIcon'),
	alert: getIcon('Actions'),
	like: getIcon('ToolbarFavoritesIcon'),
	delete: getIcon('ToolbarDeleteIcon')
};

loudRejection(alfy.error);
process.on('uncaughtException', alfy.error);
hookStd.stderr(alfy.error);

hook-std

Hook and modify stdout and stderr

MIT
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis

Popular hook-std functions