saojs / sao

⚔ Futuristic scaffolding tool
https://sao.vercel.app
MIT License
1.05k stars 61 forks source link

[v1] Document `this.sao.opts` for passing variables to sao context #124

Open shaunwarman opened 5 years ago

shaunwarman commented 5 years ago

I probably missed it. But it doesn't seem obvious how to pass in variables to sao context.

My CLI tool uses cac for something like

cli create <applicationName>

And need to feed this value into sao context

await sao({ applicationName, generator, ...etc })

It seems it's available on this.sao.opts is this documented? If not, I'll send a PR.

lirantal commented 5 years ago

Is this an example of what you were looking for: https://github.com/lirantal/create-node-lib/blob/master/bin/cli.js ?

shaunwarman commented 5 years ago

Ah more so something that shows you can pass variables to soa generator and get access to those variables in the soa context.

Example

await sao({
      applicationName,
      generator,
      outDir: targetPath,
      npmClient: 'npm'
    }).run();

saofile.js

const questions = require('./src/utils/prompts');

module.exports = {
  prompts() {
    const { applicationName } = this.sao.opts; // <- this isn't documented
    return questions.configure(applicationName);
  },
  actions: [
   ...
  ],
  async completed() {
    this.gitInit();
    await this.npmInstall();
    this.showProjectTips();
  }
};

So if I'm looking at v1 documentation on sao generator instance it's not immediately obvious that you can pass variables in and have access to those on this.sao.opts.