Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Let .tree() accept callbacks #53

Open
rauschma opened this issue May 17, 2024 · 0 comments
Open

Suggestion: Let .tree() accept callbacks #53

rauschma opened this issue May 17, 2024 · 0 comments

Comments

@rauschma
Copy link

rauschma commented May 17, 2024

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant