0.3.2 • Published 1 year ago

interface-cli v0.3.2

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

interface-cli (WIP)

itf: the alias for interface-cli.

Install

npm i -g interface-cli

Setup

interface-cli uses Handlebars for templating.

INSTANCENAME: special keyword for filename. You can also use it inside the template.

CLI will ask the required parameters inside the template.

Config

// interface.config.js
import path from "path"
import { createConfig } from "interface-cli"

// HBS templates path
const templatesDir = path.resolve("./templates")

export default createConfig({
   // Handlebars helpers
   helpers: [["toLowerCase", (str) => str.toLowerCase()]],
   templates: {
      "Template Name": (instanceName) => [
         // Inputted in CLI
         {
            // File 1 in template
            // Output file path
            path: path.join(".temp", instanceName, `${instanceName}.jsx`),
            // HBS file path
            templatePath: path.join(templatesDir, "ReactComponent.jsx.hbs"),
         },
         {
            // File 2 in template
            path: path.join(".temp", instanceName, "index.jsx"),
            // HBS string
            content: `export { default } from "./{{ INSTANCENAME }}"`,
         },
      ],
      "React Component with CSS Module": (instanceName) => [
         {
            path: path.join(".temp", instanceName, `${instanceName}.jsx`),
            templatePath: path.join(
               templatesDir,
               "ReactComponentwCssModule.jsx.hbs"
            ),
         },
         {
            path: path.join(".temp", instanceName, `${instanceName}.module.css`),
            templatePath: path.join(templatesDir, "ReactComponent.module.css"),
         },
         {
            path: path.join(".temp", instanceName, "index.jsx"),
            content: `export { default } from "./{{ INSTANCENAME }}"`,
         },
      ],
   },
})