Files
meteor/tools/cli
Ben Newman 8550412bb0 Reimplement meteor debug using the Node 8 inspector.
This is the feature that excites me most about Meteor 1.6, hands down.

Benefits include:

* Works with `meteor test[-packages] --debug-port 9229` (for tests), as
  well as just `meteor debug` (for apps).

* The application process waits patiently for the debugger to attach, so
  you don't have to race to open the debugger.

* The application process pauses at a location just after all server code
  has been evaluated, but before any code starts executing, giving you a
  chance to set reliable breakpoints anywhere in server code. This is much
  better than using the `node --inspect-brk` flag, since that stops too
  soon to set any useful breakpoints.

* The application server runs at full speed, so you don't have to wait
  forever to hit that all-important breakpoint, and you don't lose nearly
  as much time if you accidentally continue past the line of code where
  the trouble is occurring.

* Even if your application is stuck in an infinite loop, you can still
  attach the debugger, pause execution, and debug the loop.

* No more `node-inspector`! Instead, you can now debug your server code in
  native Chrome DevTools, or several other high-quality inspector clients,
  such as VS Code or WebStorm (seriously, check out the documentation:
  https://nodejs.org/en/docs/inspector/#inspector-tools-clients). The list
  of debuggable processes can be found at the URL chrome://inspect.

* Realistic performance and memory profiling is now possible via the
  familiar DevTools interface.

* I highly recommend this Chrome extension that automatically (re)connects
  to any open inspector sockets, so you don't have to keep manually
  (re)attaching the debugger: http://june07.com/nim

* The implementation of `meteor debug` no longer has to proxy multiple
  private/public debugger ports. Look at all that deleted code!

This new inspector is so much better than the old `node-inspector` that
I've been using the release-1.6 branch to debug problems in Meteor 1.5,
despite the risks of using Node 8, because those risks are so far
outweighed by the quality of the new debugging experience.

That said, the experience isn't perfect (yet). I welcome your feedback on
the Meteor 1.6 PR: https://github.com/meteor/meteor/pull/8728
2017-06-14 19:08:40 -04:00
..
2015-08-10 11:24:23 -07:00

CLI

Files in this folder define the common framework for defining and parsing CLI commands, options and properties such as inApp or inPackage.

It is encouraged to split out theme sharing commands into separate files.

An example of a command:

main.registerCommand({
  name: 'some-command',
  requiresRelease: false,
  requiresApp: true,
  // requiresPackage: true,
  // requiresAppOrPackage: true,
  pretty: true, // optional
  minArgs: 1, // optional
  maxArgs: 10, // optional
  options: {
    'long-option': { type: Boolean, short: 's', default: true, required: true },
    'with-string': { type: String, short: 'w' }
  }
}, function (options) {
  var {appDir, packageDir, args} = options;
  var longOption = options['long-option'];
  var withString = options['with-string'];
  ...
});

This command will handle the following examples:

meteor some-command --long-option
meteor some-command -s
meteor some-command -s --with-string "some value"
meteor some-command -s -w "some value"

Note: don't pick a short key for an option unless it is very common to use it. The commands parser makes sure the same short key for an option is used consistently for the same kind of option across all commands. So two commands A and B can share a short option "c" only if it stands for the same long option in both cases.

Catalog refresh policy

You might notice that some commands are marked to never refresh the catalog. This is useful to make the command fast, if the command doesn't involve any network communication to the package server, it might be a good idea to forbid the preemtive refresh:

main.registerCommand({
  ...
  catalogRefresh: new catalog.Refresh.Never()
});

Command return code

For some reason there are two ways to terminate the command with a non-standard exit code (non-zero, unix process exit code).

First way is just the return value of the command function, which should be a number.

The second way is to throw a special kind of exception:

main.registerCommand({...}, function (options) {
  throw new main.ExitWithCode(2);
})

In case of additional options check, you can throw another special exception to show the help text for the command:

main.registerCommand({...}, function (options) {
  if (options.bla === 'bad-value')
    throw new main.ShowUsage;
})

There is also main.WaitForExit used for terminating after the subprocesses are done. (XXX more info)

help.txt

The help.txt file contains all the information printed to the user when the meteor help command is run. It has its own syntax where every command is separated by a marker >>> with the name of the command.

Commands are parsed so the help text for an individual command could be separated from the rest.

Sadly, these commands need to be redocumented in the docs app as well. The docs text is not shared between these two places, yet.

Admin commands

Given that self-test is the only reliable way to test code in Meteor Tool, you might need to create special "admin" commands. Since "admin" commands don't show up in the help text, this namespace is abused to store all sorts of one-of commands to run in automated and manual tests.