Giter VIP home page Giter VIP logo

metalsmith-move-up's Introduction

metalsmith-move-up

travis git npm standard

Metalsmith MoveUp is a MetalSmith plugin for moving the full contents of a directory up one or more levels. By default this plugin will move everything in your destination directory up one. Metalsmith MoveUp supports multiple transforms, which are processed in the order they are provided, allowing for more complex transforms to be done with a single call.

For globbing support we use minimatch. To make matching easier we set dot matching to true meaning a global match can be done using a single globstar **. MiniMatch options can be provided as a global or on a per transform basis.

Installation

To install Metalsmith MoveUp, simply use npm:

npm install metalsmith-move-up --save

Usage

The example below can be found and ran from the eg folder; it demonstrates how to use Metalsmith MoveUp in a couple of different ways in a node.js app.

Javascript

'use strict'

var metalsmith = require('metalsmith'),
    moveUp = require('metalsmith-move-up')

// move everything in the build folder up one. The
// build folder always represents the root for operations.
metalsmith.use(moveUp())

// defaults are added as needed so input is easier. Input
// is simplified where possible. both lines will have a
// default .by of 1 and will use dot:true for mini-match.
metalsmith.use(moveUp('pages/*'))
metalsmith.use(moveUp({pattern: 'pages/*'}))

// multiple simple transforms are also supported.
metalsmith.use(moveUp([
  'lib/**',
  'test/*'
]))

// multiple, order specific, transforms can be done with one
// call. Each job only begins after the previous one finishes.
metalsmith.use(moveUp([
  '!*.css',
  'index.css'
]))

// the .by field moves everything N or as many times as
// possible. This means if a given match only has one path
// part, it will only be moved up one directory.
metalsmith.use(moveUp({
  pattern: 'pages/*',
  by: 2
}))

// globbing is supported via minimatch. default options for
// minimatch can be supplied at a global level using the .opts
// field. Transforms are added to the .transforms array, any
// transform that does not have a .opts field will get the
// global .opts value. This is a replace, not a merge.
metalsmith.use(moveUp({
  opts: {
    dot: false
  },
  transforms: [
    {pattern: 'pages/*', by: 2},
    {pattern: 'css/*', by: 2, opts: {dot: true}}
  ]
}))

Metalsmith JSON

{
  "source": "./src",
  "destination": "./dest",
  "plugins": {
    "metalsmith-move-up": {
      "opts": {"dot": "true"},
      "transforms": [
        {"pattern": "**", "by": "2"},
        {"pattern": "posts/*", "by": "2", "opts": {"dot": "false"}}
      ]
    }
  }
}

Transform

The transform object has three fields, if no transforms are passed a default pattern will be ran that pulls all applicable files and folders in the build directory up by one.

pattern

The glob pattern to use when locating files and directories for moving. See both minimatch for example patterns.

by

The maximum number of path parts to remove. Matches with less path segments than the count will have all of their segments removed, as such, they will end up in the root (destination) folder.

opts

The options to use with minimatch, order is field > global > default each overriding the last. Note that these options do not merge, they overwrite.

Contributing

Metalsmith MoveUp is an open project and encourages participation. If you feel you can help in any way, be it with examples, extra testing, or new features please be our guest.

See our Contribution Guide for information on obtaining the source and an overview of the tooling used.

License

Copyright Dean McDonnell 2015, Licensed under MIT

metalsmith-move-up's People

Contributors

mcdonnelldean avatar rbardini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zml2008

metalsmith-move-up's Issues

Support more input options for params

Options for metalsmith-move-up are currently supported as such:

moveUp(patternOne, patternTwo, patternN)

Add the ability to support array input:

moveUp([patternOne, patternTwo], patternN, [patternX, patternY])

Input order should be maintained.

Add common patterns / recipies to documentation

The Globbing syntax is not the easiest in the world, it would be nice to add some documentation and / or code samples to show how to do various common tasks with moveup, for instance:

  • Flatten the whole destination folder
  • Match only a single folder
  • Match all files of a single type
  • Match all files with the same partial name
  • Negate matches
  • Match by conditional or filtered pattern

Check if plugin works with metalsmith cli

This has not been checked and may require #2 to be completed first.

  • Check if it works as is
  • Document changes needed
  • Update code to work with metalsmith CLI
  • Update tests and docs as applicable

Improve options / field naming

The naming is confusing in it's current format, the new suggested format is:

  • moveUp supports one or more Transforms
  • moveUp, by itself does not have any options.
  • Transforms can be provided as an collection or an individual Transform
  • Transforms have two fields, pattern & upBy
    • pattern: a glob or glob array
    • upBy: the count of directories to move up

These changes need to be reflected in the code, tests and documentation.

Moving just the contents up from directory

I was wondering if there is a way that I can move just the contents one (or more) levels up from a directory.
For example:
| main folder
| – – 1.jpg
| – – subfolder
| – – | – – 2.jpg

In this instance I would like to move 2.jpg into the main folder so it would become:
| main folder
| – – 1.jpg
| – – 2.jpg
| – – subfolder

Is this possible? Thanks

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.