1.0.4 • Published 3 years ago

motem v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

MOTEM

Simple modular templates generator

Usage

  1. npm i motem -D or yarn add motem -D.
  2. Create a directory for your templates in the root directory e.g.: root/templates.
  3. Create at least one json template, use the following code as a starter:
{
  "name": "Component",
  "description": "Generate a component",
  "add": [
    {
      "dirPath": "src/components/[ModuleName]",
      "files": [
        {
          "fileName": "[ModuleName].tsx",
          "template": [
            "import React from 'react';",
            "import type { [ModuleName]Props } from './[ModuleName].props';",
            "",
            "const [ModuleName] = ({ label }: [ModuleName]Props) => {",
            "  const className = '[module-name]';",
            "  return <div className={className}>{label}</div>",
            "}",
            "",
            "export default [ModuleName];",
            ""
          ]
        },
        {
          "fileName": "[ModuleName].props.ts",
          "template": [
            "export interface [ModuleName]Props {",
            "  label: string;",
            "}",
            ""
          ]
        },
        {
          "fileName": "index.ts",
          "template": [
            "export { default } from './[ModuleName]';",
            ""
          ]
        }
      ]
    }
  ],
  "modify": [
    {
      "filePath": "src/module.ts",
      "lines": [
        {
          "hook": "// IMPORT_MODULE",
          "appendLines": [
            "import [ModuleName] from './components/[ModuleName]';"
          ]
        },
        {
          "hook": "/* ADD_UNION_TYPE */",
          "appendLine": "| '[module-name]'"
        }
      ]
    }
  ]
}
  1. run motem templates.

!Important

  • The magic keyword is [ModuleName], [moduleName], [module-name], [module_name], [MODULE_NAME]. The case will transform the module name that you will pass to it.

Parameters

ParameterTypeRequiredDescription
nameStringYesThe name will be displayed in the cli
descriptionStringNoThe description will be displayed next to name in the cli
addArrayNoArray of files and templates and the directory in which that you want to create
add0.dirPathStringYesRelative path(from where motem command will be launched) to directory where the files will be added
add0.checkAdditionalDirsArrayNoWill check if such module exists in other directories than dirPath
add0.filesArrayYesArray of files and templates that you want to create
add0.files.fileNameStringYesEnter the file name that will be added use ModuleName syntax that will be replaced with user input.
add0.files.templateArrayYesWrite your template for the file here, each new line, should be a new array item. ModuleName syntax also works here.
modifyArrayNoList of files you want to modify
modify0.filePathStringYesRelative path(from where motem command will be launched) to the file you want to modify
modify0.linesArrayYesArray of a specific object, where you describe the lines you want to add.
modify0.lines0.hookStringYesA string (usually a comment), that will be used to add new lines. NOTE, the hook will be automatically added at the end of your added lines.
modify0.lines0.appendLinesArrayNoAppend multiple (or a single) lines. Hook will be added as a new line after your lines.
modify0.lines0.appendLineStringNoAppend an inline string. Hook will be added after a space of your string.
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.3

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago