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

grunt-js-copy

v0.1.2

Published

Copy and compress files and directories using Grunt

Downloads

3

Readme

grunt-js-copy v0.1.1 Build Status NPM Version

Create directories with Grunt (based on grunt-mkdir)

Getting Started

This plugin requires Grunt ^0.4.0 or higher.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-js-mkdir --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-js-copy');

The "copy" task

Overview

In your project's Gruntfile, add a section named copy to the data object passed into grunt.initConfig().

grunt.initConfig({
  copy: {
    options: {
      // Task-specific options go here.
    },
    files: {
      // Target-specific directories lists.
    }
  },
});

Options

compress

Type: String Default value: false

A boolean which indicates a compress. If defined as true, source files will ne compressed. Available format for compression:

format | extension | description -------|-----------|-------------- JS | .js | JavaScript XML | .xml | XML JSON | .json | JSON CSS | .css | CSS (style) SQL | .sql | SQL query formats

Usage Examples

Copy all

In this example, the whole content on directory tmp it is copies to the subdirectory tmp/copy_all without any restriction.

The parameter src represents which files needs to be copied, and in this case * means everything under directory tmp.

grunt.initConfig({
  copy: {
    all: {
      files: [
        { cwd: 'tmp', src: '*', dest: 'tmp/copy_all' }
      ]
    }
  }
});

Copy files according with its extension

In this example, only a specific file extension needs to be copied. The content from directory tmp it is copies to the following subdirectory tmp/copy_all according to the constraint specified.

The parameter src represents which files needs to be copied. For each array entry, it is specified a different file type on the src parameter, consequently it also a different destination.

grunt.initConfig({
  copy: {
    extension: {
      files: [
        { expand: true, cwd: 'tmp', src: ['*.html'], dest:  'tmp/copy_ext/html' },
        { expand: true, cwd: 'tmp', src: ['**/*.js'], dest: 'tmp/copy_ext/js' },
        { expand: true, cwd: 'tmp', src: ['**/*.xml'], dest: 'tmp/copy_ext/xml' }
      ]}
  }
});

Copy and rename

In this example, there's a need not only for a copy, but renaming the copied files also. The content from directory tmp it is copied to the following subdirectory tmp/copy_rename, and files ending with .js will be replaced with -dbg.js using a replace function.

The parameter rename is the one responsible for renaming the copied files. Both parameters dest and src from the anonymous function Rename refers to the same parameters from the files entry.

grunt.initConfig({
  copy: {
    rename: {
      files: [{ 
          expand: true, 
          cwd: 'tmp', 
          src: ['**/*.js'], 
          dest: 'tmp/copy_rename',
          // The 'dest' and 'src' values are passed into the function
          rename: function(dest, src) {
            // The 'src' is being renamed; the 'dest' remains the same
            return dest + "/" + src.replace(".js", "-dbg.js");
          }
      }]
    }
  }
});

Copy and rename using regular expression

In this example, there's a need not only for a copy, but renaming the copied files also. The content from directory tmp it is copied to the following subdirectory tmp/copy_rename_regex, and files ending with .js, .xml, .css, .html will have the suffix -dbg added before the file extension using a regular expression on the replace function.

grunt.initConfig({
  copy: {
    renameWithRegex: {
      files: [{ 
          expand: true, 
          cwd: 'tmp', 
          src: ['**/*.js', '**/*.xml', '*.css', '*.html'], 
          dest: 'tmp/copy_rename_regex',
          // The 'dest' and 'src' values are passed into the function
          rename: function(dest, src) {
            // The 'src' is being renamed; the 'dest' remains the same
            return dest + '/' + src.replace(/(\.js|\.xml|\.css|\.html)/, "-dbg$1");
          }
      }]
    }
}
});

Copy files and compress (minify)

In this example, it is necessary to minify every file copied under extension .js from tmp to subdirectory tmp/copy_compress. The module used for file compression is UglifyJS, and it is available for compression file extensions .js, .xml, .json, .css, .sql.

grunt.initConfig({
  copy: {
    compress: {
      options: {
        compression: true,
      },
      files: [
        { expand: true, cwd: 'tmp', src: ['**/*.js'], dest: 'tmp/copy_compress' }
      ]}
  }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2018-06-03 v0.1.1 First official release for Grunt 0.4.0.