Code Monkey home page Code Monkey logo

Comments (3)

trev-dev avatar trev-dev commented on May 31, 2024 4

I just came up against this myself and learned that flatten=false is the wrong way to go. You want to flatten the destination, but then use the rename option to manipulate the destination! Take my config as an example.

I'm working on a shopify theme using shopify's theme kit and I want to track my custom liquid file changes separately from the rest of the theme, because dozens of other devs might mutate the theme without warning.

I need to move my liquid files from ./src/liquid/**/* to shopify-theme/**/* but I want the subdirectories of ./src/liquid/** to be preserved.

To do this, I need to write a rename function:

    import path from 'path'
    // in plugins:
    copy({
      targets: [
        {
          src: "src/liquid/**/*",
          dest: "shopify-theme",
          rename: (_name, _extension, fullpath) => {
            const keptParts = fullpath.split(path.sep).filter(dir => {
              return dir !== "src" && dir !== "liquid"
            })
            return path.join(...keptParts)
          }
        }
      ],
      verbose: true
    })

In @macaw-germany's case I think the config might look more like this:

    import path from 'path'
    // in plugins:
    copy({
      targets: [
        {
          src: "folder2",
          dest: "destfolder",
          rename: (_name, _extension, fullpath) => {
            const keptParts = fullpath.split(path.sep).filter(dir => {
              return dir !== "folder2"
            })
            return path.join(...keptParts)
          }
        }
      ],
      verbose: true
    })

from rollup-plugin-copy.

trev-dev avatar trev-dev commented on May 31, 2024 2

Assuming your structure is always consistent, you can also simply use a fullpath.split(path.sep).slice(1) instead of explicitly removing directories by name. Filtering by name will get rid of further nested directories, not just the first occurrences.

from rollup-plugin-copy.

weihaopeng avatar weihaopeng commented on May 31, 2024

same question!

from rollup-plugin-copy.

Related Issues (20)

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.