/grunt-code-extract

grunt code extract into file

Primary LanguageJavaScriptMIT LicenseMIT

grunt-code-extract

The best Grunt plugin ever.

Getting Started

This plugin requires Grunt ~0.4.5

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-code-extract --save-dev

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

grunt.loadNpmTasks('grunt-code-extract');

The "codeExtract" task

Overview

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

grunt.initConfig({
  codeExtract: {
    jsExample1: {
      options: {
        blocks: [
          {start: '/* code-extract-start */', end: '/* code-extract-end */', replace: '"a"'},
          {
            start  : '/* start */', end: '/* end */',
            replace: function (srcFilepath, replacedSrcPath, origniSrc, 
              currentDealedPartialSrc, currentDealedRemainedSrcArray, extractedSrcArray) {
              return '//sdf';
            }
          }
        ]
      },
      files  : [{
        expand : true, flatten: true,
        src    : ['test/source*.js'], dest: 'tmp/',
        replace       : function (block, srcFilepath) {
          return block.replace === '"a"' ? '"A"' : '//' + srcFilepath;
        }, extractDest: 'tmp/extract.json'
      }]
    }
  },
});

Options

options.blocks

Type: Array Default value:

blocks: [{
  start: '/* code-extract-start */',
  end  : '/* code-extract-end */',
  replace: ''
}]

Defines the start and end identifier of the replacement block.

options.blocks[.replace]

Type: String Or Function Default value: ''

Define a replacement string or a custom replacement function.

Release History

(Nothing yet)