jondot / hygen

The simple, fast, and scalable code generator that lives in your project.

Home Page:http://www.hygen.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use node code in hygen

Raiper34 opened this issue · comments

Hi, is possible to use node code in hygen? I am new to hygen and have not found answers. I use my helper script for generating asset map, but I want to replace it with hygen. My script first get structure of given folder and based that folder i generate asset map. Can I run node code in hygen to get folder structure like this?

const assets = fs.readdirSync(BASE_ASSETS_FOLDER).filter(folder => !folder.includes('.'));

Thanks!

For future, you can use prompt.js with params like

const fs = require('fs');
const BASE_ASSETS_FOLDER = './raw';
module.exports =
  {
    params: ({args}) => {
      // use fs (or similar) to read data
      // process data
      // add to args

      // anything you add to args available in templates
      args.assets = fs.readdirSync(BASE_ASSETS_FOLDER).filter(folder => !folder.includes('.'))
      return args
    }
  }

and then you can use assets variable in template :)