13

CLI Tool to create universal code boilerplates - any feedback appreciated

 4 years ago
source link: https://github.com/eykrehbein/cook
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

:man:‍:egg: Cook

A minimal CLI Tool to create and use your own boilerplates

QNRJ3aq.gif

Key Features

  • Create boilerplates containing files and folders with one command
  • Use unlimited variables / placeholders which will be filled on creation
  • Runs on Windows, MacOS and Linux

Installation

With yarn:

yarn global add @eyk/cook

With npm:

npm install -g @eyk/cook

Usage

Creating a Boilerplate

All boilerplates are stored in a newly created directory at HOMEDIR/.cook . You can create a new boilerplate by either creating a folder in this directory or using the following command.

cook create <name>

This command will create a new (empty) directory with the given name. You can modify the content by navigating into it.

Furthermore, you got the option to copy an existing directory into the newly created boilerplate folder automatically. This can be done by using the --copy flag.

Example:

# Copying the current working directory
cook create test --copy

# Copying a specific folder
cook create test --copy preparedFolder/

Variables

Cook's boilerplates aren't static. You can use variables inside of folder names, file names and the files' content.

Syntax:

{{ variableName }}
c{{ variableName }}

The c letter in front of the curly-braces has no special meaning, but it ensures there won't be any conflicts with other curly-braces like in Vue.js files.

Example of creating a boilerplate for a React.js component:

# Current working directory
my-boilerplate
└─── {{name}}
    │   {{name}}.js
    │   {{name}}.css
// {{name}}.js file
import React from 'react';
import 'c{{name}}.css';

export default props => {
  return <div className="c{{name}}"></div>;
};

Command:

cook create rc --copy my-boilerplate

Applying Boilerplates

To apply a boilerplate, use the following command.

cook <name> [targetDir]

This will copy the named boilerplate into the target dir (or, if not specified, into the current working directory)

If you have used any variables, you can specify their value by using flags.

Example:

Specified variables: name , counter

Command:

cook <name> [targetDir] --name HelloWorld --counter 0

This will replace all occurrences of name and counter inside of pathnames and content.

Listing existing Boilerplates

If you want to get a list of all existing boilerplates, you can use the following command.

cook list

Removing Boilerplates

To remove a boilerplate, use the following command.

cook remove <name>

License

MIT


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK