Giter Club home page Giter Club logo

project-init's Introduction

project init (pi)

Build Status Windows build status

pi is a command-line utility to initialize projects. It is written in rust.

It is intended to provide something like cookiecutter, but faster.

Reasons to use pi:

  • You want to automate the process of starting a new project, for all your projects.
  • You want project initialization that's quick

Reasons to use pi over cookiecutter:

  • Templates are smaller. Define files you need in a .toml.
  • Fast. pi is 30x faster than cookiecutter when rendering the sample vim plugin template.
  • pi uses mustache, a logic-less language, for templates.
  • pi can initialize a darcs, pijul, mercurial, or git repository inside your projects
  • pi provides opinionated templates for many languages
  • pi is extensible in Rust

Reasons to not use pi over cookiecutter:

  • cookiecutter uses jinja templates, which are far more sophisticated.
  • pi is newer and presumably more buggy
  • cookiecutter is extensible in Python

Benchmarks (with Haskell's bench):

Tool Language Time (vim example plugin) Time (rust library)
pi init rust 10.10 ms 8.809 ms
pi new rust 6.672 ms 8.653 ms
cookiecutter python 317.1 ms 316.9 ms

Installation

Script

Enter the following in a command prompt:

curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git vmchale/project-init

Binary releases

The easiest way for most users is simply to download the prebuilt binaries. You can find binaries for various platforms on the release page.

Cargo

First, install cargo. Then:

 $ cargo install project_init

You will need to use the nightly release for this to work; if in doubt run

rustup run nightly cargo install project_init

Use

pi reads from $HOME/.pi_templates/ and your current directory. So, if you place a template in the $HOME/.pi_templates/idris/, you can initialize a project anywhere with

 $ pi init idris treesod

There is a repo containing pi templates here.

You can also use pi with built-in templates, viz.

 $ pi new haskell really-good-project
Finished initializing project in really-good-project/

Or to fetch a template from github:

 $ pi git vmchale/haskell-ats ambitious-insane-project

Examples

Configuration

Global configuration is via the $HOME/.pi.toml file. The following is an example:

license = "BSD3"         # set default license to BSD3 
version_control = "git"  # initialize new repositories with git
version = "0.1.0"        # start new projects at version 0.1.0

[author]
name = "Vanessa McHale"
email = "[email protected]"
github_username = "vmchale"

# put any custom keys you want under a [[user]] table
[[user]]
website = "https://vmchale.com"

Project-specific config lives in $PROJECT_NAME/template.toml. The following is an example for a vim plugin:

license = "BSD3"        # overrides global value if set
with_readme = true      # add README.md

[files]
files = ["syntax/{{ project }}.vim","plugin/{{ project }}.vim","doc/{{ project }}.txt"] # blank files
directories = ["doc","syntax","plugin"]
templates = ["vimball.txt"] # files to be processed

[config]
version = "0.1.0"
version_control = "darcs"

# put any custom keys you want below [[user]]
[[user]]
vim_org_username = "vmchale"

This will generate the following directory structure:

vim-plugin
├── LICENSE
├── README.md
├── doc
│  └── vim-plugin.txt
├── plugin
│  └── vim-plugin.vim
├── syntax
│  └── vim-plugin.vim
└── vimball.txt

For a more in-depth example, see here. This is a template based off the recursion schemes generator.

Templates

pi uses mustache for templating, via the rustache crate.

You can find examples and help on the mustache page, or you can my look at the example repo.

project-init's People

Contributors

musoke avatar vmchale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

project-init's Issues

Failed to install from cargo, "cannot find macro 'eprintln!'"

Just tried to install project-init from cargo using cargo install project_init. That gave me the following error once it wen't to compile project_init v2.0.6

error: cannot find macro `eprintln!` in this scope
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.0.6/src/repo.rs:17:9
   |
17 |         eprintln!("{}, git failed to initialize. Is git on your path?","Error".red());
   |         ^^^^^^^^
   |
   = help: did you mean `println!`?

error: cannot find macro `eprintln!` in this scope
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.0.6/src/repo.rs:34:9
   |
34 |         eprintln!("{}, Mercurial failed to initialize. Is hg on your path?","Error".red());
   |         ^^^^^^^^
   |
   = help: did you mean `println!`?

error: cannot find macro `eprintln!` in this scope
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.0.6/src/render.rs:161:25
    |
161 |                         eprintln!("Failed to open file: {:?}", p);
    |                         ^^^^^^^^
    |
    = help: did you mean `println!`?

error: cannot find macro `eprintln!` in this scope
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.0.6/src/render.rs:199:21
    |
199 |                     eprintln!("Failed to create file: {:?}. Check that the directory is included in your template.toml", path);
    |                     ^^^^^^^^
    |
    = help: did you mean `println!`?

error: cannot find macro `eprintln!` in this scope
   --> .cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.0.6/src/render.rs:257:9
    |
257 |         eprintln!("Failed to create file: {:?}. Check that the directory is included in your template.toml", p);
    |         ^^^^^^^^
    |
    = help: did you mean `println!`?

error: cannot find macro `eprintln!` in this scope
  --> .cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.0.6/src/lib.rs:81:9
   |
81 |         eprintln!("{}: No ~/.pi.toml found. Using defaults.", "Warning".yellow());
   |         ^^^^^^^^
   |
   = help: did you mean `println!`?

error: aborting due to 6 previous errors

error: failed to compile `project_init v2.0.6`, intermediate artifacts can be found at `/tmp/cargo-install.5YdRpzeR0TA5`

Caused by:
  Could not compile `project_init`.

To learn more, run the command again with --verbose.

Preserve file permissions

Again, not sure if this is a bug or feature request.

I have a template that contains a shell script with execute permission, which doesn't seem to be preserved when I run pi init. Is this intended?

How may I copy a file with its contents without processing the contents using Mustache?

I have a LaTeX file, {{ project }}.md/scriv-pmarkdown.latex.

It contains content with {{ and }} as part of the normal LaTeX.
If I add the file to the templates block in template.toml then the LaTeX is altered and broken on init of a new project from the template.

If I add the file to the files block then the file is added empty on init of a new project from the template.

If I alter the delimiters used by Mustache (see Set Delimiter) in the scriv-pmarkdown.latex file as follows and then put the file in the templates block:

Add to the top of the file.

%{{=<% %>=}}

Add to the bottom of the file.

%<%={{ }}=%>

The change in delimiters is ignored and so the file is broken.

Is there are way to copy the contents of the file without parsing with Mustache?

panic on empty .pi.toml

At least I'm guessing this is related to the fact that my .pi.toml is empty.

Against v 2.9.7

RUST_BACKTRACE=1 pi l                                                                                                        

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(69)`,
 right: `Some(10)`', /home/tsampson/.cargo/registry/src/github.com-1ecc6299db9ec823/project_init-2.9.7/src/main.rs:70:26
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:71
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:381
   2: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:397
             at /checkout/src/libstd/panicking.rs:577
   3: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   4: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   5: pi::main
   6: main
   7: __libc_start_main
   8: _start

First run experience might be improved

e.g.

pi l                                                                                                                            
File "/home/tsampson/.pi.toml" could not be opened. Check that it exists.

I'm not sure what might be better here. Create one on first run? Through a wizard (if you want to go that far). Some of the values can probably be inferred from other places (.gitconfig if it exists for example, possible env vars). But maybe there's a simple way to improve this a bit too.

Feature Request: Specifying custom keys on command line

Hi,

thanks for this project!

Would it be possible to specify custom keys as additional arguments to the init subcommand?

For example:

pi init my_library_template awesome_library  group=com.example.libs

This would overwrite the custom key in the template.toml:

[[user]]
group="com.another"

Fix name

This is a small bug, and maybe you'll just want to close it, but the name is all wrong. It's clear to me this project should have been named "Magnum P.I."

image

Then again, maybe I can think of some project that would use that name... >.>

Benchmark unit

Hi,
I think you meant µs and not ms in the table of the readme file :)

make it a library?

I want to use it from another crate I am working on (which will setup a project and offer some project specific command line utilities). Currently I have dependency on python just for cookie-cutter support, would be good to use this as a library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.