基于项目模板创建项目的命令行工具:Cookiecutter

jopen 10年前

一个命令行实用程序,从cookiecutters(项目模板)创建的项目,比如:创建从一个Python包项目模板的Python包项目。

基于项目模板创建项目的命令行工具:Cookiecutter

特性

Did someone say features?

  • Cross-platform: Windows, Mac, and Linux are officially supported.

  • Works with Python 2.6, 2.7, 3.3, and PyPy. (But you don't have to know/write Python code to use Cookiecutter.)

  • Project templates can be in any programming language or markup format: Python, JavaScript, Ruby, CoffeeScript, RST, Markdown, CSS, HTML, you name it. You can use multiple languages in the same project template.

  • Simple command line usage:

    # Create project from the cookiecutter-pypackage.git repo template  # You'll be prompted to enter values.  # Then it'll create your Python package in the current working directory,  # based on those values.  $ cookiecutter gh:audreyr/cookiecutter-pypackage
  • Can also use it at the command line with a local template:

    # Create project in the current working directory, from the local  # cookiecutter-pypackage/ template  $ cookiecutter cookiecutter-pypackage/
  • Or use it from Python:

    from cookiecutter.main import cookiecutter    # Create project from the cookiecutter-pypackage/ template  cookiecutter('cookiecutter-pypackage/')    # Create project from the cookiecutter-pypackage.git repo template  cookiecutter('https://github.com/audreyr/cookiecutter-pypackage.git')
  • Directory names and filenames can be templated. For example:

    {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}.py
  • Supports unlimited levels of directory nesting.

  • 100% of templating is done with Jinja2. This includes file and directory names.

  • Simply define your template variables in a cookiecutter.json file. For example:

    {      "full_name": "Audrey Roy",      "email": "audreyr@gmail.com",      "project_name": "Complexity",      "repo_name": "complexity",      "project_short_description": "Refreshingly simple static site generator.",      "release_date": "2013-07-10",      "year": "2013",      "version": "0.1.1"  }
  • Unless you suppress it with --no-input, you are prompted for input:

    • Prompts are the keys in cookiecutter.json.
    • Default responses are the values in cookiecutter.json.
    • Prompts are shown in order.
    </li>
  • Cross-platform support for ~/.cookiecutterrc files:

    default_context:      full_name: "Audrey Roy"      email: "audreyr@gmail.com"      github_username: "audreyr"  cookiecutters_dir: "~/.cookiecutters/"
  • Cookiecutters (cloned Cookiecutter project templates) are put into ~/.cookiecutters/ by default, or cookiecutters_dir if specified.

  • You can use local cookiecutters, or remote cookiecutters directly from Git repos or from Mercurial repos on Bitbucket.

  • Default context: specify key/value pairs that you want used as defaults whenever you generate a project

  • Pre- and post-generate hooks: Python or shell scripts to run before or after generating a project.

  • Paths to local projects can be specified as absolute or relative.

  • Projects are always generated to your current directory.

  • </ul>

    可用的Cookiecutters

    Here is a list of cookiecutters (aka Cookiecutter project templates) for you to use or fork.

    Make your own, then submit a pull request adding yours to this list!

    Python

    C

    C++

    • BoilerplatePP: A simple cmake template with unit testing for projects written in C++.

    Common Lisp

    JS

    LaTeX/XeTeX

    • pandoc-talk: A cookiecutter template for giving talks with pandoc and XeTeX.

    Berkshelf-Vagrant

    • slim-berkshelf-vagrant: A simple cookiecutter template with sane cookbook defaults for common vagrant/berkshelf cookbooks.

    HTML

    Similar projects

    • Paste has a create option that creates a skeleton project.
    • Diecutter: an API service that will give you back a configuration file from a template and variables.
    • Django's startproject and startapp commands can take in a --template option.
    • python-packager: Creates Python packages from its own template, with configurable options.
    • Yeoman has a Rails-inspired generator system that provides scaffolding for apps.
    • Pyramid's pcreate command for creating Pyramid projects from scaffold templates.
    • mr.bob is a filesystem template renderer, meant to deprecate tools such as paster and templer.
    • grunt-init used to be built into Grunt and is now a standalone scaffolding tool to automate project creation.
    • scaffolt consumes JSON generators with Handlebars support.
    • init-skeleton clones or copies a repository, executes npm install and bower install and removes the .git directory.
    • Cog python-based code generation toolkit developed by Ned Batchelder

    项目主页:http://www.open-open.com/lib/view/home/1415004759544