grunt-concat-properties

0.0.14 • Public • Published

grunt-concat-properties

Grunt plugin for concating JavaScript models methods or attributes from many files

 View/init.js
 View/firstMethod.js     -->    View.js
 View/secondMethod.js
 ...

Usage Example

grunt.initConfig({
    concatProperties: {
        myApp: {
            src: [
                'View/{**/,}*.js'
            ],
            dest: 'build/View.js'
        }
    }
};

src

Type: Array Default value: []

Array of files masks for concatination. Files will be concated at specified sequence.

dest

Type: String Default value: ''

The destination file path


How to start

Sample project structure

Instalation
npm install grunt-concat-properties --save-dev
1 For each model, view or other object you need to create a folder with init.js file.

Example for constructor:

// View/init.js
MyApp.View = function () {};
MyApp.View.prototype = {
    // @include prototypeProperties
};
2 Add files with properties or groups to your object folder.
// View/firstMethod.js
MyApp.Model.prototype.firstMethod = function () {};
// View/secondMethod.js
MyApp.Model.prototype.secondMethod = function () {};
3 Run task
grunt concatProperties
Result:
// build/View.js
MyApp.View = function () {};
MyApp.View.prototype = {
    firstMethod:  function () {},
    secondMethod: function () {}
};

Also you can concat inline properties using other place definition

// @include properties

Advantage configuring

grunt.initConfig({
    concatProperties: {
        myApp: {
            options: {
                base: 'test/App/',
                sourceProcessor: null,
                initFiles: [
                    '**/init.js',
                    '!init.js'
                ]
            },

            src: [
                'models/{**/,}*.{json,yaml,yml,js}',
                'View/{**/,}*.js'
            ],
            dest: 'build/properties.js'
        }
    }
};

src

Type: Array Default value: []

Source files. Task can parse JS, JSON or YAML files

options.base

Type: String Default value: ''

Path to your application from Gruntfile.js You need to specify this property only if Gruntfile.js isn`t placed at your app folder,

options.sourceProcessor

Type: Function Default value: null

The function will being called for process each property source data.

For example:

/**
 * @param source {String}
 * @param propertyData {Object}
 * @param propertyData.name     {String}
 * @param propertyData.source   {String}
 * @param propertyData.comment  {String}
 * @param propertyData.type     {String}  'function' || 'object'
 * @param propertyData.isPublic {Boolean}
 * @param propertyData.isFromPrototype {Boolean}
 * @param propertyData.filePath {String}
 */
function sourceProcessor (source, propertyData) {
    return source;
}

options.initFiles

Type: Array Default value: ['**/init.js', '!init.js']

Masks of initialization files

Multiple destination files configuration

grunt.initConfig({
    concatProperties: {
        myApp: {
            files: {
                'build/models.js': [
                    'models/{**/,}*.js'
                ],
                'build/View.js': [
                    'View/{**/,}*.js'
                ]
            }
        }
    }
};

Recommendations

Use some like grunt-jsbeautifier to keep indentation at concated files

Readme

Keywords

Package Sidebar

Install

npm i grunt-concat-properties

Weekly Downloads

1

Version

0.0.14

License

none

Last publish

Collaborators

  • el-fuego