core/template.js
function generate(targetPath, args) {
  if (
    !args.template &&
    (!args.templateFile || (args.templateFile && !vio.fileExists(args.templateFile)))
  ) {
    const err = new Error(`No template file found: ${args.templateFile}`);
    err.code = 'TEMPLATE_FILE_NOT_FOUND';
    throw err;
  }
  const tpl = args.template || vio.getContent(args.templateFile);
  const compiled = _.template(tpl, args.templateOptions || {});
  const result = compiled(args.context || {});

  vio.save(targetPath, result);
}
function generate(targetPath, args) {
  if (
    !args.template &&
    (!args.templateFile || (args.templateFile && !vio.fileExists(args.templateFile)))
  ) {
    const err = new Error(`No template file found: ${args.templateFile}`);
    err.code = 'TEMPLATE_FILE_NOT_FOUND';
    throw err;
  }
  const tpl = args.template || vio.getContent(args.templateFile);
  const compiled = _.template(tpl, args.templateOptions || {});
  const result = compiled(args.context || {});

  vio.save(targetPath, result);
}
function generate ( targetPath , args ) { if ( ! args . template && ( ! args . templateFile || ( args . templateFile && ! vio . fileExists ( args . templateFile ) ) ) ) { const err = new Error ( ` ${ args . templateFile } ` ) ; err . code = 'TEMPLATE_FILE_NOT_FOUND' ; throw err ; } const tpl = args . template || vio . getContent ( args . templateFile ) ; const compiled = _ . template ( tpl , args . templateOptions || { } ) ; const result = compiled ( args . context || { } ) ; vio . save ( targetPath , result ) ; }
Process the template file and save the result to virtual IO.
If the target file has existed, throw fatal error and exit.

@param {string} targetPath - The path to save the result.
@param {Object} args - The path to save the result.
@param {string} args.template - The template string to process.
@param {string} args.templateFile - If no 'template' defined, read the template file to process. One of template and templateFile should be provided.
@param {Object} args.context - The context to process the template.
@alias module:template.generate

@example
const template = require('rekit-core').template;

const tpl = 'hello ${user}!';
template.generate('path/to/result.txt', { template: tpl, context: { user: 'Nate' } });

// Result => create a file 'path/to/result.txt' which contains text: 'hello Nate!'
// NOTE the result is only in vio, you need to call vio.flush() to write to disk.
Process the template file and save the result to virtual IO . If the target file has existed throw fatal error and exit .