jondot/hygen

Can I use `hygen` to get the string output only?

yedeyu opened this issue · 0 comments

I want to get the string output only for each template within my program.

I tried the following code, and see that the log statements I added didn't run.

const { runner } = require('hygen')
const Logger = require('hygen/dist/logger').default
const path = require('path')
const defaultTemplates = path.join(__dirname, 'templates')

runner(process.argv.slice(2), {
  templates: defaultTemplates,
  cwd: process.cwd(),
  logger: new Logger(console.log.bind(console)),
  createPrompter: () => require('enquirer'),
  exec: (action, body) => {
    console.log(action);
    console.log(body);
    
    const opts = body && body.length > 0 ? { input: body } : {}


    //return require('execa').shell(action, opts)
  },
  debug: !!process.env.DEBUG
})

I tried the following code, and see the result is not the string content that I expected.

const { runner } = require('hygen')
const Logger = require('hygen/dist/logger').default
const path = require('path')
const defaultTemplates = path.join(__dirname, 'templates')

let p = runner(process.argv.slice(2), {
  templates: defaultTemplates,
  cwd: process.cwd(),
  logger: new Logger(console.log.bind(console)),
  createPrompter: () => require('enquirer'),
  debug: !!process.env.DEBUG
})

p.then(console.log);

So my question is, can I use hygen to get the string output only (for each template)?