All Projects β†’ cats-oss β†’ Scaffdog

cats-oss / Scaffdog

Licence: mit
🐢 scaffdog is Markdown driven scaffolding tool.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Scaffdog

Template
A super-simple way to create new projects based on templates.
Stars: ✭ 120 (-49.37%)
Mutual labels:  cli, scaffold, template
Mrm
Codemods for your project config files
Stars: ✭ 900 (+279.75%)
Mutual labels:  cli, scaffold, template
Cgx
πŸ’»πŸ”₯CLI to generate the recommended documentation/files to improve contribution (Github, Gitlab, CodeCommit and Bitbucket)
Stars: ✭ 190 (-19.83%)
Mutual labels:  cli, markdown, template
Remarker
▢️ Remark cli
Stars: ✭ 132 (-44.3%)
Mutual labels:  cli, markdown
Angular Chrome Extension
angular chrome extension scaffold
Stars: ✭ 113 (-52.32%)
Mutual labels:  scaffold, template
Cli Spring Boot Scaffold
command line for generate crud and configs for spring boot projects
Stars: ✭ 113 (-52.32%)
Mutual labels:  cli, scaffold
Angular Librarian
An Angular 2+ scaffolding setup for creating libraries
Stars: ✭ 92 (-61.18%)
Mutual labels:  cli, scaffold
Webpack Cli
webpack CLI provides the interface of options webpack uses in its configuration file. The CLI options override options passed in the configuration file.
Stars: ✭ 2,270 (+857.81%)
Mutual labels:  cli, scaffold
Formd
A Markdown formatting tool
Stars: ✭ 141 (-40.51%)
Mutual labels:  cli, markdown
Vuepress Homepage
πŸ“„ Elegant & friendly homepage (bio, tech portfolio, resume, doc...) template with Markdown and VuePress
Stars: ✭ 186 (-21.52%)
Mutual labels:  markdown, template
Markdown Pdf
πŸ“„ Markdown to PDF converter
Stars: ✭ 2,365 (+897.89%)
Mutual labels:  markdown, template
Think Builder
A command line toolit to build applications' CRUD/mvc scaffold for thinkphp v6. η”¨δΊŽη”Ÿζˆ thinkphp v6 咞ζŸ₯ζ”Ήεˆ θ„šζ‰‹ζžΆδ»£η ηš„ε‘½δ»€θ‘Œε·₯具。
Stars: ✭ 105 (-55.7%)
Mutual labels:  cli, scaffold
Awesome React Generator
No more clicking around to create files in your react project! Awesome React Generator is Command Line Tool that let's you scaffold your components without leaving your terminal.
Stars: ✭ 98 (-58.65%)
Mutual labels:  cli, scaffold
Pandoc Markdown Book Template
A template for creating epub books from markdown using pandoc.
Stars: ✭ 191 (-19.41%)
Mutual labels:  markdown, template
Tslide
Terminal SlideDeck, supporting markdown.
Stars: ✭ 198 (-16.46%)
Mutual labels:  cli, markdown
Cli
A tiny CLI for HedgeDoc
Stars: ✭ 94 (-60.34%)
Mutual labels:  cli, markdown
Mandown
man-page inspired Markdown viewer
Stars: ✭ 173 (-27%)
Mutual labels:  cli, markdown
Gomplate
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.
Stars: ✭ 1,270 (+435.86%)
Mutual labels:  cli, template
Catesta
Catesta is a PowerShell module project generator. It uses templates to rapidly scaffold test and build integration for a variety of CI/CD platforms.
Stars: ✭ 88 (-62.87%)
Mutual labels:  scaffold, template
Pandoc Book Template
A simple Pandoc template to build documents and ebooks.
Stars: ✭ 214 (-9.7%)
Mutual labels:  markdown, template

scaffdog

scaffdog is Markdown driven scaffolding tool.

GitHub Workflow Status npm MIT LICENSE

scaffdog

DEMO

Multiple files can be output in a document, and flexible scaffolding is possible with a simple but powerful template syntax πŸ•

Table of Contents

Features

  • πŸ“ Markdown driven
    • You can define a template with <h1> and code block.
    • It will be a Documetable template !
    • Define meta information with extended syntax using Front Matter.
  • βš’ Simple & Powerful template syntax
    • A simple syntax similar to mustache.js. ({{ inputs.value }})
    • Function execution similar to pipe syntax. ({{ inputs.value | fn }})
    • Provide minimum necessary functions in built-in.
  • πŸš€ Ready to use
    • You can quickly start using $ scaffdog init.

Requirements

  • Node.js v12.10 +

Getting Started

Installation

scaffdog can be installed globally, but we recommend installing it locally on the project.

$ npm install --save-dev scaffdog

Quick Start

In the following tutorial you can start using scaffdog immediately !

Setup

By default, it stores the document file and configuration file in the .scaffdog directory.

Creating directories, configuration file and initial documents can be done with the init subcommand.

$ npx scaffdog init

? Please enter a document name. hello

Setup of scaffdog 🐢 is complete!

  βœ” .scaffdog/config.js
  βœ” .scaffdog/hello.md

Now you can do scaffold by running `$ scaffdog generate`.

Please refer to the following documents and customize it.
https://github.com/cats-oss/scaffdog/#templates

After running the command, the .scaffdog/hello.md file should have been generated.

Let's scaffold using the hello document!

$ npx scaffdog generate hello

? Please select the output destination directory. .
? Please enter any text. pretty-dog

🐢 Generated 1 file!

     βœ” pretty-dog.md

Congratulations πŸŽ‰

The first file was generated.

$ cat pretty-dog.md

Let's make a document! See more detail scaffdog repository.
https://github.com/cats-oss/scaffdog/#templates

Please refer to this document and customize the document file πŸ‘

Migration

There are important changes in the major update.

See Migration Guide.

Configuration

scaffdog uses the object exported in .scaffdog/config.js as the configuration.

Simple Configuration

In the files field, specify the path pattern of the document used by scaffdog. The files field is required.

module.exports = {
  files: ['./*'],
};

Global Variables

You can define the global variables available in the template in the variables field.

module.exports = {
  files: ['./*'],
  variables: {
    key: 'value',
  },
};

Custom Helpers

You can define the custom helpers available in the template in the helpers field.

module.exports = {
  files: ['./*'],
  helpers: [
    // Using Key-Value
    {
      trim: (context, value) => value.trim(),
    },

    // Using Helper Registry
    (registry) => {
      registry.set('padstart', (context, value, size, str) =>
        value.padStart(size, str || ' '),
      );
      registry.set('padend', (context, value, size, str) =>
        value.padEnd(size, str || ' '),
      );
    },
  ],
};

The context passed to the first argument of the helper function has the following structure.

type Variable =
  | string
  | {
      [key in string | number]: Variable;
    }
  | Variable[];

type VariableMap = Map<string, Variable>;

type Helper = (context: Context, ...args: any[]) => string;

type HelperMap = Map<string, Helper>;

type Context = {
  cwd: string;
  variables: VariableMap;
  helpers: HelperMap;
};

Commands

scaffdog init

Prepare to use scaffdog. Create a .scaffdog directory by default, and create a first document file.

Options:
  -p, --project  Directory to load the scaffdog project.        [string] [default: ".scaffdog"]
  -v, --verbose  Enable logging.                                                      [boolean]
      --help     Show help                                                            [boolean]
      --version  Output the version number                                            [boolean]

scaffdog generate

Build a scaffold using the specified template. If you do not specify the template name and execute it, interactively select the template.

Positionals:
  name                                                                                 [string]

Options:
  -p, --project  Directory to load the scaffdog project.        [string] [default: ".scaffdog"]
  -v, --verbose  Enable logging.                                                      [boolean]
      --help     Show help                                                            [boolean]
      --version  Output the version number                                            [boolean]
  -n, --dry-run  Output the result to stdout.                                         [boolean]

scaffdog create

Create a document file with the specified name.

Positionals:
  name  Specify a document file name.                                                  [string]

Options:
  -p, --project  Directory to load the scaffdog project.        [string] [default: ".scaffdog"]
  -v, --verbose  Enable logging.                                                      [boolean]
      --help     Show help                                                            [boolean]
      --version  Output the version number                                            [boolean]
  -y, --yes      Use default options.                                                 [boolean]

scaffdog list

Print a list of available documents.

Options:
  -p, --project  Directory to load the scaffdog project.        [string] [default: ".scaffdog"]
  -v, --verbose  Enable logging.                                                      [boolean]
      --help     Show help                                                            [boolean]
      --version  Output the version number                                            [boolean]

Templates

Structure

Template documents are defined with <h1> and code blocks. <h1> is interpreted as the file name and code blocks as the template body.

Meta information is defined using Front Matter.

---
name: 'utility'
root: 'src/utils'
output: '**/*'
ignore: []
questions:
  name: 'Please enter a filename.'
---

# `{{ inputs.name }}.js`

```javascript
export const {{ inputs.name | camel }} = () => true;
```

# `__tests__/{{ inputs.name }}.test.js`

```javascript
import { {{ inputs.name | camel }} } from '../{{ inputs.name }}';

describe('{{ inputs.name | camel }}', () => {
  test('__TODO__', () => {
    expect({{ inputs.name | camel }}()).toBe(true);
  });
});
```

Syntax

Between {{ and }} is interpreted as a tag. Whitespace in tag contents is ignored.

Output of variable

The given variable name is output. See the Variables section for the variables that can be used.

{{ <identifier> }}

Example:

{{ inputs.value }}

Whitespaces

Trim the expression to be expanded and the space and line feed around it.
Use {{- to trim before the tag, and -}} to trim after the tag.

{{- <expression> -}}

Example:

before {{- "text" }} after
before {{ "text" -}} after
before {{- "text" -}} after

Output:

beforetext after
before textafter
beforetextafter

Comment out

You can use comment out to keep the template readable. Of course, it is not deployed as a template.

{{ /* a comment */ }}

Call helper function

Execute the helper function with the specified name. Arguments are separated by whitespace. See the Helpers section for the helpers that can be used.

{{ <helper> <argument> ... }}

Example:

{{ relative "../" }}

Pipe chain

You can chain output values or helper results with pipes. This is a helper similar to shell.

{{ <identifier> | <helper> }}
{{ <identifier> | <helper> <argument> ... }}

Example:

{{ inputs.value | upper }}
{{ inputs.value | replace "$.ts" ".js" | pascal }}
{{ basename | replace extname ".js" | pascal }}

Attributes

List of attributes that can be specified with Front Matter.

key required type description
name true string Name of template.
root true string The directory as the starting point of the output destination.
output true string Directory starting from root and being a destination candidate. You can use glob syntax. (see globby document)
ignore false string[] Directory to exclude from candidate output destination. You can use glob syntax. (see globby document)
questions false object Message to display when accepting input.

questions defines the question to be used in prompt with key-value. The values you answer can be used in a variable called inputs. (e.g. inputs.key1, inputs.value)

---
questions:
  # Shortest syntax, using `input` prompt.
  key1: 'Message'

  # Using `input` prompt.
  key2:
    message: 'Message'

  # Using `input` prompt, with default value.
  key3:
    message: 'Message'
    initial: 'Initial Value'

  # Using `list` prompt.
  key4:
    message: 'Message'
    choices: ['A', 'B', 'C']
---

Variables

List of variables available in the template. You need to be aware that the file name and the variables available in the template body are different.

File name

key description example
inputs The object value received at the prompt.

Template body

key description example
inputs The object value received at the prompt.
output.name The name of the output destination file excluding the extension. scaffdog
output.base The name of the output destination file including the extension. scaffdog.js
output.ext The destination file name extension. .js
output.dir The destination directory name. src
output.path The path of the destination file. src/scaffdog.js
output.abs The absolute path of the destination file. /path/to/src/scaffdog.js
document.name The document name. hello
document.path The path of the document file. /path/to/.scaffdog/hello.md

Helpers

When invoked on a pipe, the previous processing result is passed to the first argument.

name arguments description
camel [value: string] Conversion to a camel case.
snake [value: string] Conversion to a snake case.
pascal [value: string] Conversion to a pascal case.
kebab [value: string] Conversion to a kebab case.
constant [value: string] Conversion to a constant case.
upper [value: string] Conversion to a upper case.
lower [value: string] Conversion to a lower case.
replace [value: string, pattern: string, replacement: string] Replace pattern withreplacement. pattern is specified as a string, but it is treated as a regular expression.
trim [value: string] Alias for String.prototype.trim.
ltrim [value: string] Alias for String.prototype.trimStart.
rtrim [value: string] Alias for String.prototype.trimEnd.
eval [code: string] Executes the specified code and returns the result.
date [format?: string] See the dayjs documentation for format details.
noop [] Returns an empty string.
define [value: string, key: string] Defines a local variable in the template scope.
relative [path: string] Convert the path from the template file to the path from the destination file.
read [path: string] Read the specified file. The contents of the loaded file are also expanded as a template.

FAQ

Is it possible to define variables in the template?

scaffdog does not support variable definitions syntactically.

However, it is possible to define variables in combination with helper functions πŸŽ‰

See the following example.

{{- output.path | replace "^src/" "" | define "out" -}}
{{ output.path }}
{{ out }}
{{ out | replace "/" "-" }}

The output is as follows:

src/utils/input.js
utils/input.js
utils-input.js

Defined a variable called out which is a processed version of output.path. This is made up of some magic.

  1. Save the calculation result to out with define helper function.
  2. The variable definition tag trims whitespaces. (use {{- and -}})

Contributing

We are always welcoming your contribution πŸ‘

  1. Fork (https://github.com/cats-oss/scaffdog) πŸŽ‰
  2. Create a feature branch β˜•οΈ
  3. Run test suite with the $ yarn test command and confirm that it passes ⚑️
  4. Commit your changes πŸ“
  5. Rebase your local changes against the canary branch πŸ’‘
  6. Create new Pull Request πŸ’Œ

Bugs, feature requests and comments are more than welcome in the issues.

Development scripts

yarn test

Run Unit test with ava.

$ yarn test

yarn lint

Run lint with ESLint.

$ yarn lint

yarn format

Run formatting with ESLint (--fix) and Prettier.

$ yarn format

License

MIT Β© Cyberagent, Inc

thank you for reading!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].