question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No console log when using fly programatically?

See original GitHub issue

Background I’m building a tool similar to next or create-react-app but for simple websites without react etc. We are currently using gulp but I’d like to replace that with fly. The current code can be found here.

The problem I don’t seem to be able to get fly to log the expected output when using it programatically. The console is blank but if I run console.log('whatever') inside a task that’ll show. Am I missing some option? Or is this a intended behaviour?

Sample code

// lib/utils/taskRunner.js
function startTaskRunner() {
  const cwd = path.join(__dirname, '..');
  const file = path.join(cwd, 'flyfile.js');

  const fly = new Fly({
    file,
    cwd,
    plugins: [
      require('fly-clear'),
    ],
  });

  fly.start();
}

startTaskRunner();
// lib/flyfile.js
exports.clean = function* (fly) {
  yield fly.clear('dist');
};

exports.default = function* (fly) {
  yield fly.start('clean');
};

Thankful for any pointers

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
alexandernanbergcommented, Jun 27, 2017

@lukeed Oh that looks great! I will definitely give Taskr another try, wouldn’t be surprised if it replaces gulp now 😉

Thanks guys 😄

2reactions
lukeedcommented, Jun 27, 2017

Hi @alexandernanberg!

Unfortunately, it seems as though you’ve left us for Gulp 😿 … but that’s okay 😜

Just wanted to let you know that you could have done this:

const join = require('path').join;
const Taskr = require('taskr');
const Reporter = require('taskr/lib/reporter');

function startTaskRunner() {
  // establish instance
  const taskr = new Taskr({
    cwd: join(__dirname, '..'),
    file: join(cwd, 'taskfile.js'),
    plugins: [
      require('@taskr/clear')
    ],
  });

  // attach Reporter (logger)
  Reporter.call(taskr);

  taskr.start();
}

Note: I updated the references from Fly to Taskr since we’ve changed our name 😃

The reason this wasn’t done by default (with every instance) is that it’s generally not wanted in programmatic use. This is because most of the time, it’s used as a silent runner & the main/parent tool is handling is own logging or stdout prints.

This follows the same pattern as our main cli.js boot script – here.

Aside from that, as @jbucaran mentioned, the only other option for logging is thru each task’s first parameter:

exports.default = function * (task) {
  try {
    yield task.source('foo/**').failure({ demo:true });
  } catch (err) {
    task.$.error(`Uh oh! The default task threw: ${err.message}`);
  }
};

The full list of inner-task utilities is available here!

Please let me know if that helps and/or you’re willing to give Taskr another try 😉

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to quickly and conveniently disable all console.log ...
Redefine the console.log function in your script. console.log = function() {}. That's it, no more messages to console. EDIT: Expanding on Cide's idea....
Read more >
Debugging Flutter apps programmatically
Note: You can view logs in DevTools' Logging view or in your system console. This sections shows how to set up your logging...
Read more >
How to remove console log from your JavaScript files ...
Learn how to remove JavaScript console methods such as console log programmatically from your JavaScript files.
Read more >
Debugger | Node.js v19.3.0 Documentation
Node.js includes a command-line debugging utility. The Node.js debugger client is not a full-featured debugger, but simple stepping and inspection are ...
Read more >
Place Autocomplete | Maps JavaScript API - Google Developers
console.log("Returned place contains no geometry"); return; ... To retrieve predictions programmatically, use the AutocompleteService class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found