npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

filemanager-plugin

v2.8.2

Published

Filemanager-plugin allows you to delete, zip/unzip(.zip/.tar/.tar.gz), move, rename, copy files or directories before and after webpack/rollup builds. Also, you can customize the lifecycle of webpack or rollup during building.

Downloads

2,806

Readme

File manager plugin

Build Status Coverage Status Node Version Total Download License

Overview

This file manager plugin allows you to delete, zip/unzip(.zip/.tar/.tar.gz), move, rename, copy files or directories before and after webpack/rollup/vite builds. Also, you can customize the lifecycle of webpack, rollup or vite during building.

Installation

npm install filemanager-plugin --save-dev

Usage

events

Control the running order during building.

  • start {Object}: Register actions to beforeCompile hook to compiler. Executes a plugin after compilation parameters are created.
  • end {Object}: Register actions to done hook to compiler, actions will be executed when the compilation has completed.

In the example below, the start event with del command will run first, and then the end event with zip after.

// webpack
const FileManagerPlugin = require('filemanager-plugin').WebpackFilemanager;
module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        start: {
          del: {
            items: ['./dist']
          }
        },
        end: {
          zip: {
            items: [
              {source: './src/demo0.zip', destination: './dest/demo0', type: 'zip'}
            ]   
          }
        }
      }
    })
  ]
};

// rollup
const rollupFilemanager = require('filemanager-plugin').RollupFilemanager;
module.exports = {
  plugins: [
    rollupFilemanager({
      events: {} // It's the same as webpack configuration
    })
  ]
}

customHooks

Supports for the custom lifecycle for webpack, vite or rollup to control the running order. In addition, when customHooks is set, events will be ignored.

  • hookName {String}: Register hook of webpack, vite or rollup. Commands will run when each hook is called. (webpack hooks, rollup hooks, vite hooks).
  • commands {Array}: Setting actions. Commands will run, when each hook which you registered is triggered.
  • hookType {String}: Depending on the hook type, It only supports webpack.
// webpack
const FileManagerPlugin = require('filemanager-plugin').WebpackFilemanager;
module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        start: {
          zip: {
            items: [
              {source: './src/demo0.zip', destination: './dest/demo0', type: 'zip'}
            ]   
          }
        }
      }, // events will be ignore.
      customHooks: [
        {
          hookName: 'compile',
          hookType: 'tap',
          commands: {
            del: {
              items: ['./dist']
              // All file under './dist' will be deleted, when compile hook is called
            }
          }
        }
      ]
    })
  ]
};

// rollup
const RollupFilemanager = require('filemanager-plugin').RollupFilemanager;
module.exports = {
  plugins: [
    new RollupFilemanager({
      customHooks: [
        {
          hookName: 'generateBundle',
          commands: {
            del: {
              items: ['./dist']
              // All file under './dist' will be deleted, when generateBundle hook is called
            }
          }
        }
      ]
    })
  ]
};

// vite
const ViteFilemanager = require('filemanager-plugin').ViteFilemanager;
module.exports = {
  plugins: [
    ViteFilemanager({
      customHooks: [
        {
          hookName: 'generateBundle',
          commands: {
            del: {
              items: ['./dist']
              // All file under './dist' will be deleted, when generateBundle hook is called
            }
          }
        }
      ]
    })
  ]
};

Commands

| Name | Type | Description | | :--- | :--- | --- | | zip | {Array} | Zip files or directories by using tar, tgz, gzip or zip. However, gzip only supports compress single file. You need to use tgz to zip a directory. | | unzip | {Array} | Unzip files or directories. The usage is Same as zip. | | del | {Array} | Delete multiple files or directories. | | copy | {Array} | Copy multiple files or directories. | | move | {Array} | Move multiple files or directories. | | rename | {Array} | Rename multiple files or directories. |

These commands would be called when each hook which has been registered is called. Also, each action will be executed in order base on Array order. In this example below, in the end event, the del command will run first, and zip after:

// webpack
const FileManagerPlugin = require('filemanager-plugin').WebpackFilemanager;
module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        start: {
          del: {
            items: ['./dist']
          },
          zip: {
            items: [
              {source: './src/demo0.zip', destination: './dest/demo0', type: 'zip'}
            ]   
          }
        }
      }
    })
  ]
};

// rollup
const rollupFilemanager = require('filemanager-plugin').RollupFilemanager;
module.exports = {
  plugins: [
    rollupFilemanager({
      events: {} // It's the same as webpack configuration
    })
  ]
}

zip example

module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        end: {
          zip: {
            items: [
               { source: './src/demo1', destination: './dest/demo1.zip', type: 'zip'},
               { source: './src/demo2', destination: './dest/demo2.tar', type: 'tar'},
               { source: './src/demo3', destination: './dest/demo3.tgz', type: 'tgz'},
               { source: './src/demo4.html', destination: './dest/demo4.html.gz', type: 'gzip'},
               { source: './src/*.js', destination: './dest/demo5.js.zip'} 
               // All js files under './src' will be compressed to 'demo5.js.zip' under './dest'
            ]
          }
        }
      }
    })
  ]
}
  • source {String}: Compressed source path which can be a file or directory. It supports glob pattern.
  • destination {String}: Compressed destination path.
  • type {String}: Compressed type. Default is zip.

unzip example

module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        end: {
          unzip: {
            items: [
              { source: './src/demo1.zip', destination: './dest/demo1'},
              { source: './src/demo2.tar', destination: './dest/demo2', type: 'tar'},
              { source: './src/demo3.tgz', destination: './dest/demo3', type: 'tgz'},
              { source: './src/demo4.html.gz', destination: './dest/demo4', type: 'gzip'},
              { source: './src/*.zip', destination: './dest/demo5'}
              // All zip files under './src' will be uncompressed to 'demo5' under './dest'
            ]
          }
        }      
      }
    })
  ]
}
  • source {String}: Uncompressed source path. It supports glob pattern.
  • destination {String}: Uncompressed destination path.
  • type {String}: Uncompressed type. Default is zip.

del example

module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        end: {
          del: {
            items: [
              './dist',
              './temp/*.html' // All html files under './temp' will be deleted.
            ]  
          }
        }
      }
    })
  ]
}
  • source {String}: Deleted path which can be a file or directory. It supports glob pattern.

copy example

module.exports = {
  plugins: [
    new FileManagerPlugin({
      end: {
        copy: {
          items: [
            // All .js files under './src/demo' will be copied to './dest/demo' and keep directory hierarchy.
            { source: './src/demo1/**/*.js', destination: './dest/demo', isFlat: false},
            // All .html files under './src/demo' will be copied to './dest/demo'
            { source: ['./src/demo/*.html'], destination: './dest/demo', globOptions: {silent: false}},
            // index.html under './src/demo' will be copied as 'newIndex.html' under './dest/demo'
            { source: ['./src/demo/index.html'], destination: './dest/demo', name : 'newIndex.html'}
          ]
        }
      }
    })
  ]
}
  • source {String | Array}: Copied source path. It supports glob pattern.
  • destination {String}: Copied destination path.
  • globOptions {Object}: Allows to configure the glob pattern matching library used by the plugin. See the list of supported options.
  • isFlat {Boolean}: Whether Removing directory structure/folder hierarchy when copying with recursive. Default is true.
  • name {String}: When you need to rename a file. Notice: It would be effective when source is a or a list of files. Default is empty string which means it would be ignored.

move example

module.exports = {
  plugins: [
    new FileManagerPlugin({
      end: {
        move: {
          items: [
            { source: './src/demo1.zip', destination: './dest/demo1'},
            { source: './src/*.css', destination: './dest/demo'}
            // All css files under './src' will be moved to './dest/demo'
          ] 
        }       
      }
    })
  ]
}
  • source {String}: Moved source path. It supports glob pattern.
  • destination {String}: Moved destination path.

rename example

module.exports = {
  plugins: [
    new FileManagerPlugin({
      end: {
        rename: {
          items : [
            { path: './rename', oldName: 'a.html', newName: 'b.html' }
          ]
        }
      }
    })
  ]
}
  • source {String}: Renamed source path.
  • destination {String}: Renamed destination path.

options

The global configuration for file manager operation

  • parallel {Number}: Use multi-process parallel running to improve the task speed. Max number of concurrent runs: os.cpus().length - 1. Default is closing.
  • log {String}: Show which information you need during building. Default is all.
const FileManagerPlugin = require('filemanager-plugin').WebpackFilemanager;

module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        start: {
          del: {
            items: ['./dist']
          }
        }
      },
      options: {
        parallel: 3,
        log: 'all'
      }
    })
  ]
};
// start with three process to run task.
// success: delete './dist'
  • cache {Boolean}: If you set true, it would only once during building. It's highly efficient for development mode. Also, you can override the value by each action. Default is true.
const FileManagerPlugin = require('filemanager-plugin').WebpackFilemanager;

module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        start: {
          del: {
            items: ['./dist']
          },
          copy: {
            items: [
              { source: './src/demo', destination: './dest/demo'}
            ],
            options: {
              cache: false // it would override cache of global options, so that it would run when webpack hot reload
            } 
          },
        }
      },
      options: {
        parallel: 3,
        log: 'all',
        cache: true
      }
    })
  ]
};

Upgrade

const FileManagerPlugin = require('filemanager-plugin').WebpackFilemanager;

// filemanager-plugin 1.X.X
module.exports = {
  plugins: [
    new FileManagerPlugin({
      start: {
        del: [
          { source: './dist' }
        ]
      },
      end: {
        zip: [
          { source: './src/demo', destination: './dest/demo.zip', type: 'zip'}
        ],
        rename: [
          { source: './rename/b', destination: './rename/a' }
        ],   
        copy: [
          { source: './src/demo', destination: './dest/demo'}
        ],
        unzip: [
        ],
        move: [
          { source: './src/demo.zip', destination: './dest/demo.zip'}
        ]
      }
    })
  ]
};

// filemanager-plugin 2.X.X
module.exports = {
  plugins: [
    new FileManagerPlugin({
      events: {
        start: {
          del: {
            items: ['./dist']
          }
        },
        end: {
          zip: {
            items: [
              { source: './src/demo', destination: './dest/demo.zip', type: 'zip'}
            ]
          },
          rename: {
            items: [
              { path: './rename', oldName: 'b', newName: 'a' }
            ]
          },
          copy: {
            items: [
              { source: './src/demo', destination: './dest/demo'}
            ]
          },
          unzip: {
            items: [
              { source: './src/demo.zip', destination: './dest/demo', type: 'zip'}
            ]
          },
          move: {
            items: [
              { source: './src/demo.zip', destination: './dest/demo.zip'}
            ]
          }
        }
      },
    })]
}