Bud ✎
The foundation of the whole framework is this, it provides the DSL used by all extensions, expose common utils, etc.
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();
fixture`./exts/Test/truth/index.js
module.exports = function () {
return 42;
};
`;
// load additional definitions
const Module = Grown.load(__dirname + '/exts');
// locate the dependency
assert(Module.get('Test').truth() === 42);
// don't do this... yet!
// new Grown();
If you uncomment
// new Grown()
and re-run the code it'll throw an error sinceServer
is not available! 💣
Public props static
argv
— Parsed argv from command-line.cwd
— Current working directory.pkg
— Current package.json contents.env
— Currentprocess.env.NODE_ENV
value.
Public methods static
do(body)
— Wraps code into promises withrescue
abilities.use(module)
— Register custom extensions from external modules.new([options])
— Shortcut fornew Grown(...)
constructor.def(name, cwd[, opts])
— Load and register definitions from the givencwd
.defn(name, value)
— Set static values into theGrown
container, once.bind(prefix, cwd)
— Configure custom module resolution through prefixes.load(cwd[, hooks])
— Build module definitions from this directory. Ifhooks
are given, found modules will be passed to them, so they can be extended or completely replaced.