1.21.1 • Published 4 years ago

cortojs v1.21.1

Weekly downloads
87
License
-
Repository
github
Last release
4 years ago

corto

Boilerplate app snippets

Quick start

# Inits a new corto
corto init --directory ./my-template

# Add a corto file
cat <<README > ./my-template/README.md
{{ def.name }}
===

{{ def.about }}
README

# Installs new corto
corto install \
  --from ./my-template \
  --target ./foo \
  --def.name project \
  --def.about 'a cool project'

# Verifies interpolation worked
cat ./foo/README.md
project
===

a cool project

You can configure stuff like default values and hooks:

  • via cli arguments
  • via a config file (default is a corto.json file inside the template's folder)

If both are used, cli arguments gets precedence but not exclusivity, meaning configurations will be merged.

Install

# Install from local directory
corto install /path/to/templates
# Install git from http
corto install http://github.com/corto/parceljs
# Install git from ssh
corto install git@github.com:corto/parceljs

Options

We use clipop for declaring options

corto install <corto>              
  # Permits copying inside already existing directories
  --allow-exists      boolean 
  # Permits copying over non-empty directories
  --allow-non-empty   boolean  
  # Path to a json file with corto config
  --config            string   
  # Dictionnary of substitutions
  --def               object<string>
  # Dictionnary of extra
  --extra             object<string>
  # Do not apply configuration from corto.json
  --ignore-config     boolean  
  # Hooks (view below)
  --hooks             object  
  # Dictionnary of options
  --opt               object<string>
  # Regular expression to use for interpolation
  --pattern           string
  # Strategy used for stumbling upon existing locations
  --strategy          string
  # Fine grain strategies
  --strategies        object<string>[]
  # Output verbosity
  --verbose           boolean

corto.json

All these properties (except config) can saved inside a corto.json. Just camel case option names:

{
  "corto": {
    "name": "mycorto",
    "version": "1.0.0"
  },
  "allowExists": false,
  "pattern": "<(.+)>",
  "required": {
    "field": true
  },
  "def": {
    "name": "some default name"
  },
  "hooks": {
    "pre": [
      "git init"
    ],
    "post": [
      "git add .",
      "git commit -am First",
      "npm install"
    ]
  }
}

Hooks

Hooks can be applied before everything (pre) or after everything (post)

Hook literal commands

Hooks are commands that are run inside the target directory, for example:

npm install

Hook template commands

You can also use templating:

{
  "opt": {
    "packageManager": "npm" // default package manager
  },
  "schema": {
    "packageManager": {
      "oneOf": ["npm", "yarn"] // setting accepted package managers
    }
  },
  "hooks": {
    "post": [
      // install node dependencies
      "{{ opt.packageManager }} install"
    ]
  }
}
corto install ./my-corto --opt.packageManager yarn # will use yarn instead of npm

Command interface

There is a limitation to string literals: they don't encapsulate between-quotes content, so the following command:

do-something --command 'do something cool'

will be run such as:

"do-something" "--command" "do" "something" "cool"

To work around that problem, you can use the command interface (templating allowed):

{
  "opt": {
    "score": 0
  },
  "hooks": {
    "post": [
      {
        "command": "do-something",
        "args": [
          "--command",
          "do something cool"
        ],
        "condition": "opt.score > 100" // optional
      }
    ]
  }
}

Loop support

{
  "opt": {
    "path": "a/bc/d/d/e/f"
  },
  "hooks": {
    "pre": [
      {
        "for": "opt.path.split('/')",
        "each": "mkdir {{ item }}"
      }
    ]
  }
}

Basic fs support

1.21.0

4 years ago

1.21.1

4 years ago

1.20.5

4 years ago

1.20.4

4 years ago

1.20.2

4 years ago

1.20.3

4 years ago

1.20.1

4 years ago

1.15.0

4 years ago

1.19.0

4 years ago

1.18.0

4 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.20.0

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.9.0

4 years ago

1.10.0

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago