1.0.7 • Published 5 months ago

code-generator-by-template v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

code-generator-by-template

Automate your coding process through auto generated code by command lines.

Description

There are two different usages for this library. It's possible to generate a single file or a whole structure based off the templates.

Usage

Base command (generate single file)

generate-file pathToTemplateFile

\<pathToFileToCreate> (required)

Ex.: tasks/taskKinds/taskKinds.routes.ts Path for the file to be created. If one wants to create a new file on the project nested in a parent folder, this can be specified by adding the parent folder's name before the file name. For example, if one wants to create a CRUD for task kinds in a kanban project and they want to place it inside the tasks folder, they could use generate tasks/taskKinds/taskKinds.routes.ts. That would create the folders as:

- tasks
  - taskKinds
    taskKinds.routes.ts
pathToTemplateFile (optional)

Ex.: templates/template.test.ts If provided, should point to the path of the template to be used on the file creation. If not provided, by default, it looks for a folder named "templates" on the root folder and a file with the same name inputted file name.

variables (optional)

Ex.: camelCase=Test plural=tests Variables to be used on the template file. It should have the same key as specified on the template file for it to work.

Base command (generate multiple files)

generate-structure --parentFolders --pathToDesignPatternFile

--parentFolders (optional)

Ex.: tasks/taskKinds If one wants to create some parent folders before the folder names with placeholder, this can be specified by adding the parent folder's name before the file name. For example, if one wants to create a CRUD for task kinds in a kanban project and they want to place it inside the tasks folder, they could use generate tasks/taskKinds/taskKinds.routes.ts. That would create the folders as:

- tasks
  - taskKinds
--templateFolderPath (optional)

Ex.: templates/template.test.ts If provided, should point to the path of the template folder to be used on the file creation. If not provided, by default, it looks for a folder named "templates" on the root folder.

--pathToDesignPatternFile (optional)

Ex.: templates/code-generator-design-pattern.json If provided, should point to the path of the design pattern file. If not provided, by default, it looks for a folder named "templates" on the root folder and then a file named code-generator-design-pattern.json.

variables (optional)

Ex.: camelCase=Test plural=tests Variables to be used on the template file. It should have the same key as specified on the template file for it to work.

Template files

The template files should be text (.txt) files, with the parameters placeholders under square brackets ([]).

Process explanation

generate-file

The script will receive a path (ex.: tests/new-test.ts) and check if the folders on this path exist. If they don't, they will be created. If they exist, it will proceed to create the file, following a template. The template path can be specified on the command or use the default behaviour (which is to use the template file in a folder named "templates"). The template may have placeholders, which then may be provided in the template and the command line args.

generate-structure

The script may receive some parent folders to create before the folders with placeholders on their names on the design pattern file, the path to the template folder, the path to the design pattern file and/or the variables to replace on the placeholders. The script will check the design pattern file to create the necessary folders and files that are specified there. Then, for the files, it shall look for the template files with the same name that is specified on the design pattern file. For the placeholder in the files contents and in the design patterns, it looks for the placeholders parameters that come from the program args, inputted by the user.

Development

Requirements

  • NodeJS 20+

Steps to run

  • Install
  • Compile
  • Run

Installing

  • yarn install

Compiling

  • npx tsc

Running

  • node dist/index.js
1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago