loreanvictor / tmplr

Automate Code Scaffolding
MIT License
26 stars 0 forks source link

Issues with glob copying #14

Closed tommy-mitchell closed 1 year ago

tommy-mitchell commented 1 year ago

I recently tried updating a template to support copying/deleting via glob patterns (https://github.com/tommy-mitchell/cli-template), but some files are seemingly being ignored. I'm using these commands:

# setup project

- copy: ./template/**/*.*
  to: ./

# finish

- remove: ./template/**/*.*
- remove: .tmplr.yml

However, these files are not being copied or removed:

\__ template/
    \__ .github/
        \__ workflows/
            \__ main.yml
    \__ test/
        \__ fixtures/
            \__ .gitkeep
    \__ .gitignore
    \__ .xo-config.json

It looks like files/folders starting with a period are being ignored.

loreanvictor commented 1 year ago

That is by design (as per minimatch), to avoid accidentally copying files and folders that should not be copied (or updated, or removed, etc.). If you need to copy / update / remove those files / folders, you need to specify the dot explicitly (sandbox):

steps:
  - copy: ./template/**/*
    to: ./dest

  - copy: ./template/**/.**/**/*
    to: ./dest

  - copy: ./template/**/.*
    to: ./dest

  - copy: ./template/**/.**/**/.*
    to: ./dest

A hidden argument could be added to copy / update / remove commands to also include hidden files and folders, though this would be a bit of an unsafe option.

tommy-mitchell commented 1 year ago

Ah, I didn’t realize. I’ll try out those commands tomorrow. Thanks :)

Here’s how fast-glob and globby handle dot files, for reference.

tommy-mitchell commented 1 year ago

That worked perfectly for copying everything, but I'm having trouble removing the empty folders now. For example, with your sandbox:

steps:
  - copy: ./template/**/*
    to: ./dest

  - copy: ./template/**/.**/**/*
    to: ./dest

  - copy: ./template/**/.*
    to: ./dest

  - copy: ./template/**/.**/**/.*
    to: ./dest

  - remove: ./dest/**/*
  - remove: ./dest/**/.**/**/*
  - remove: ./dest/**/.*
  - remove: ./dest/**/.**/**/.*

This leaves:

\__ dest/
    \__ .hidden/
    \__ stuff/
Command output ``` ❯ npx tmplr ✔ Copied: template/doc.md -> dest/doc.md ✔ Copied: template/stuff/code.js -> dest/stuff/code.js ✔ Copied: template/.hidden/other-code.js -> dest/.hidden/other-code.js ✔ Copied: template/.stuff -> dest/.stuff ✔ Copied: template/.hidden/.other-file -> dest/.hidden/.other-file ✔ Removed: dest/doc.md ✔ Removed: dest/stuff/code.js ✔ Removed: dest/.hidden/other-code.js ✔ Removed: dest/.stuff ✔ Removed: dest/.hidden/.other-file ```
loreanvictor commented 1 year ago

Ah yes, I have inadvertently introduced an issue to remove command, where it can't remove directories any more (I need to add some e2e tests to the CLI itself 😅). Since this is a separate issue, I'll create a different issue for tracking and discussing it.

loreanvictor commented 1 year ago

@tommy-mitchell you should be able to directly remove folders by specifying their names (again), which should? cover most use cases.

tommy-mitchell commented 1 year ago

Great, that works for now :) Feel free to close this issue.

loreanvictor commented 1 year ago

I'm gonna leave it open as I feel the current solution is a bit clunky, and adding a hidden parameter to copy command would be a good solution for this.

loreanvictor commented 1 year ago

76baf4d adds a include hidden option to copy / update / remove, to also include hidden files when a glob pattern is provided. You can access this feature from 0.2.5 upwards.