npm

Need private packages and team management tools?Check out npm Orgs. »

grunt-depend-concat

0.1.4 • Public • Published

grunt-depend-concat

A Grunt task that concatenates files in order via path references.

This task was initially developed to be used in conjunction with grunt-ts for concatenating separately compiled JavaScript files. However, the task's functionality has been expanded to be useful in a variety of ways.

Written in TypeScript.

Getting Started

This plugin requires Grunt ~0.4.0

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-depend-concat --save-dev

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

grunt.loadNpmTasks('grunt-depend-concat');

Configuration

method

The method option determines what the task searches for to find dependencies.

JavaDoc-like Tags - doctag

Setting the method.type option to "doctag" will have the task recognize documentation tags matching the method.tag string.

For example, the following method options ...

{
    method: {
        type: 'doctag',
        tag: 'use'
    }
}

... will recognize the following tags as dependencies:

/**
 * @use ../path/to/file.js
 */

XML Tags - xmltag

Setting the method.type option to "xmltag" will have the task recognize documentation tags matching the method.tag string.

For example, the following method options ...

{
    method: {
        type: 'xmltag',
        tag: 'use'
    }
}

... will recognize the following tags as dependencies:

// <use path="../path/to/file.ts" />

/// <use path="../path/to/file.ts" />

The xmltag type has additional options.

The method.attribute and method.prefix options will alter the regular expression used for finding dependencies.

For example, the following method options ...

{
    method: {
        type: 'xmltag',
        tag: 'require',
        attribute: 'src',
        prefix: '<\\!-- *'
    }
}

... will recognize the following tags as dependencies:

<!-- <require src="../path/to/file.ts" />

Presets

TypeScript References

Set the method option to "reference" for TypeScript references to be recognized. The following is an example reference.

/// <reference path="../path/to/file.ts" />

Custom

You can also use a custom method by providing the method option to a literal object with the regex and index properties set.

{
    /**
     * A regular expression used to find the dependencies
     */
    regex: /somefancyregex/gi,

    /**
     * An array index where each dependency's file path
     * can be found from the result of RegExp.exec()
     */
    index: 1
}

separator

File contents separator. Default: "\n"

ignore_ext

When looking for matching dependency files, the file extensions are ignored. Allows TypeScript references (.ts) to discover their compiled (.js) counterparts. Default: true

Example

grunt.initConfig({
    'depend-concat': {
        /* 
            @depends /path/to/dependency.js
        */
        depends_doctag: {
            options: {
                method: {
                    type: 'doctag',
                    tag: 'depends'
                }
            }
            src: ['compiled/files/*.js'],
            dest: 'dist/concat.js'
        },
        /* 
            /// <reference path="../path/to/file.ts" />
        */
        typescript_reference: {
            options: {
                method: 'reference'
            },
            src: ['compiled/files/*.js'],
            dest: 'dist/concat.js'
        },
        /* 
            <!-- <require filepath="../path/to/file.xml" /> -->
        */
        require_xmltag: {
            options: {
                method: : {
                    type: 'doctag',
                    tag: 'require',
                    attribute: 'filepath',
                    prefix: '<\\!-- *'
                },
                ignore_ext: false,
            },
            src: ['compiled/files/*.xml'],
            dest: 'dist/concat.xml'
        },
    }
});

License

Released under the MIT license


(^_^)

install

npm i grunt-depend-concat

Downloadsweekly downloads

5

version

0.1.4

license

MIT

repository

Gitbitbucket

last publish

collaborators

  • avatar
Report a vulnerability