Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Run commands after scaffold completion #188

Open
iilyak opened this issue Jan 10, 2020 · 6 comments
Open

[Feature] Run commands after scaffold completion #188

iilyak opened this issue Jan 10, 2020 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@iilyak
Copy link

iilyak commented Jan 10, 2020

Usually when new project is started there is a need to run some initialization commands, such as for example:

  • git init
  • git remote add upstream ....
  • git worktree add --track -b gh-pages site origin/gh-pages
  • direnv allow

It would be nice to be able to run the commands automatically or be able to print them (and suppress all other output) to pipe into sh.
I.e. the scaffold command would look like ffizer apply --source <source_dir> --destination <dest_dir> | sh.

@davidB davidB added enhancement New feature or request help wanted Extra attention is needed labels Jan 10, 2020
@davidB
Copy link
Member

davidB commented Jan 10, 2020

It's a feature on my TODO list since the start. I never work on it due to priority and some issues & questions (your point of view is welcome):

  • for security (not run arbitrary command on the user's host): for each command, the user is asked "do you want to run .... [Y/n] ?"
  • in case of composed template (with imports), what is the right order to apply command (depth-first or breadth-first or ???)
  • common question for scripting commands (see Commands, Scripts and Sub Tasks from cargo-make doc):
    • how to manage multi-OS support (linux, macos x, windows)
    • how to handle error
    • what is the syntax (a string, an array, ...)

The first/next step that I plan is to allow template to include a notice messages to display at the end of the generation. This message could include command and ask user to copy/paste them.

WDYT ?

@iilyak
Copy link
Author

iilyak commented Jan 10, 2020

for security (not run arbitrary command on the user's host): for each command, the user is asked "do you want to run .... [Y/n] ?"

👍

in case of composed template (with imports), what is the right order to apply command (depth-first or breadth-first or ???)

maybe do a topological sorting of the nodes? However there might be the cases when user might want to override the order.

common question for scripting commands (see Commands, Scripts and Sub Tasks from cargo-make doc):

variables:
     - name: github_org
       ask: Github organization or user name
     - name: repo_name
        ask: Repository name 

imports:
  - uri: "git@github.com:ffizer/templates_default.git"
    id: base
    rev: "master"
    subfolder: "gitignore_io"
  - uri: "git@github.com:myown/docs-template.git"
    id: docs
    rev: "master"
    subfolder: "docs"

commands:
    - id: postscaffold
       command: |
           git init
           git remote add upstream git@github.com:{{github_org}}/{{repo_name}}.git
           git worktree add --track -b gh-pages site origin/gh-pages
       order:
          - base # we want `postscaffold` commands from ffizer/templates_default.git to run before ours
          - self # this is how we refer to `postscaffold` command in the current `.ffizer.yaml`
          - docs

To somewhat abstract OS differences one could write something like

commands:
    - id: postscaffold
       windows: 
           command: |
               ...
       posix:
          command: |
               ...
       darwin:
          command: |
               ...

OR (easier to implement but might be not a good choice long term)

commands:
   id: postscaffold
   command: |
       {{#if (eq  platform "darwin") ~}}
        ....
       {{~/if}}
       {{#if (eq  platform "windows") ~}}
        ....
       {{~/if}}

@davidB
Copy link
Member

davidB commented Jun 4, 2020

Hi,

The ffizer 2.x (beta currently) include a basic support for commands: like

scripts:
  - cmd: |
      {{#if (eq (env_var "OS") "windows") }}
      echo Hello {{ who }}> file2.txt
      del file_to_delete.txt
      {{else}}
      echo "Hello {{ who }}" > file2.txt
      rm file_to_delete.txt
      {{/if}}

extracted from https://github.com/ffizer/ffizer/blob/master/tests/data/test_3/template/.ffizer.yaml

@iilyak
Copy link
Author

iilyak commented Jun 5, 2020

Thank you. It compiles. I'll test it after I figure out how to make a release locally. I am new to Rust and currently learning it. I wanted to figure out how your build setup is working. It is very awesome. Looks like somehow you use github actions locally. Do you have a ffizer templates for rust projects?

@davidB
Copy link
Member

davidB commented Jun 5, 2020

Welcome to Rust Land

FYI the pre-built binaries are available under github/release or you can update you local ffizer with ffizer upgrade.

If you compile from source, you can use the regular cargo command:

  • cargo run to run from project folder
  • cargo install --path . to install it into under $HOME/.cargo/bin (should be in your PATH).

My usage of cargo make is for "advanced" tasks.

I have a rust template (but it's obsoleted no ci,... , I'll update it then add it to ffizer organization): https://github.com/davidB/templates.

@davidB
Copy link
Member

davidB commented Jun 5, 2020

I have an other rust template but more specialized at https://gitlab.com/davidB31/cg-starter-multi-rust I have duplication between them, after release of the version 2 I plan to remove duplication and to re-create them as composition of templates (one the unique features of ffizer I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants