Synchronizing code of fragments
You can match a code of fragment into other file from a file, and make fragments are consistent between two files.
This plugin requires Grunt ~0.4.1
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-fragment --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-fragment');
In your project's Gruntfile, add a section named fragment
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
fragment: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Type: String
Default value: grunt.file.defaultEncoding
A string value that is encoding method.
Type: RegExp
Default value: '/[\S\s]+/gm'
A RegExp that to match a code of fragment and replace others in target file.
In this example, the default options are used to do something with whatever. So if the from.js
file has the function syncFunc
return 'new version' and the to.js
file had the function syncFunc
return old version
, the generated result would be to.js
file had the function syncFunc
return new version
.
grunt.initConfig({
fragment: {
options: {
match: /(function syncFunc \(\) \{)[\S\s]+(\}\/\/ syncFunc end)/gm,
encode: 'utf-8'
},
files: {
'test/expected/js/to.js': 'test/expected/js/from.js',
},
},
})
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.
(Nothing yet)