Skip to content

Suggestion: Let .tree() accept callbacks #53

@rauschma

Description

@rauschma

I love .tree() because it can represent nested dependencies:

omelette('hello').tree({
  cruel: ['world', 'moon'],
  beautiful: ['mars', 'pluto']
}).init();

However, it’d be great if it were possible to also dynamically create the top level via a callback:

omelette('hello').tree(
  async () => {
    const json = await /* ... */;
    return json;
  }
).init();

In my own code, I use the following workaround (TypeScript code):

const oml = omelette(BIN_NAME) as omelette.Instance & { compgen: number };
if (oml.compgen >= 0) {
  const tree: omelette.TreeValue = {};
  const projectDir = process.cwd();
  if (BookConfig.isProjectDir(projectDir)) {
    const bookConfig = BookConfig.fromDir(projectDir);
    for (const key of bookConfig.getOutputConfigKeys()) {
      tree[key] = ['--dry-run', '--replace'];
    }
  }
  oml.tree(tree).init();
  return; // not really needed
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions