Bud

The foundation of the whole framework is this, it provides the DSL used by all extensions, expose common utils, etc.

/* @runkit */
const Grown = require('@grown/bud')();
const Util = require('@grown/bud/util');

// extends the Grown-container
Grown.use(($, util) => {
  assert($ === Grown);
  assert(util === Util);
});

// build a promise-guard for callbacks
const cb = Grown.do(rescue => {
  rescue(e => {
    // you can use this block to
    // catch-up things on a failure
    assert(e instanceof Error);
  });

  // any errors thrown here will reject
  // the created promise, also they'll be
  // logged through `Util.getLogger().error`
  throw new Error('E_FAILURE');
});

cb();

// ./exts/Test/handler/index.js
// module.exports = function () {
//   return 42;
// };

// load additional definitions
const Exts = Grown.load(`${__dirname}/exts`);

// locate the dependency
assert(Exts.get('Test').handler() === 42);

// don't do this!
// new Grown();

If you uncomment // new Grown() and re-run the code it'll throw an error since Server is not available! 💣


Public props static

  • argv — Parsed argv from command-line.
  • cwd — Current working directory.
  • env — Current process.env.NODE_ENV value.

Public methods static

  • do(body) — Wraps code into promises with rescue abilities.
  • use(module) — Register custom extensions from external modules.
  • new([options]) — Shortcut for new Grown(...) constructor.
  • defn(name, value) — Set static values into the Grown container, once.
  • load(cwd[, hooks]) — Build module definitions from this directory. If hooks are given, found modules will be passed to them, so they can be extended or completely replaced.

➯ Next: Extensions ⟩ CLI