Giter Site home page Giter Site logo

embedded-hygen-example's Introduction

embedded-hygen-example

A quick example of how to embed hygen into your own CLI tool to have templates embedded within it, for example. It's not perfect, but it gets the job done.

Setup

  1. Run yarn install
  2. Run yarn build
  3. Run yarn generate project new

For the sake of simplicity as a proof of concept, I set the cwd option in the src/bin.ts file to be path.join(process.cwd(), '.tmp'). This way, for the sake of testing, I can just call the bin file with node from the root folder of this package, without it trying to dump the generated files in this very same root folder, and instead generating them all into a separate .tmp folder.

After the files have been generated, you can see the generated structure in the .tmp folder. This "project generator" outputs more template files to scaffold components within this new project. You can call them as follows.

  1. Make sure you're in the .tmp folder, the new project that just generated
  2. Run yarn install (Could perhaps look at a way to automate this after successful generation?)
  3. Run yarn generate component new

You'll see that on top of scaffolding the base structure of the project, it scaffolded some generators to continue expanding the project with a defined structure. It's entirely optional, of course, but since I highlighted the possibility in my original comment, I figured I'd include it.

How to convert this PoC into a working product

  1. Remove the .tmp folder from the cwd parameter in the bin file.
  2. Publish the package on a package feed
  3. Install it as a global package or use npx to install + run it on demand.

Caveats

As mentioned in the intro its not perfect. For example when you trigger an error by calling a generator that doesn't exist, hygen will still reference the init self generators, which don't exist anymore because we overrode the defaultTemplates from hygen.

To get around this you could potentially embed these into your own project as well for full feature parity with the only addition being more default templates alongside the init self ones provided by hygen (perhaps a build step that copies them from node_modules/hygen/src/templates to your own default templates directory?). You're essentially just extending hygen with more built in templates this way.

embedded-hygen-example's People

Contributors

mjansen-dc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.