incuna / grunt-maketextfiles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

grunt-maketextfiles

Builds the textfiles.js manifest needed to import data and template textfiles into requireJS for eDetails Based on original makeTextFiles npm module: https://github.com/incuna/maketextfiles

Getting Started

This plugin requires Grunt ~0.4.2

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-maketextfiles --save-dev

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

grunt.loadNpmTasks('grunt-maketextfiles');

The "maketextfiles" task

Overview

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

grunt.initConfig({
    //if you are using grunt watch, add
    watch: {
        options: {
            atBegin: true,
            interrupt: true
        },
        textFilesProject: {
            files: [
                'project/data/**/*.{json, yaml}',
                'project/templates/**/*.html',
            ],
            tasks: ['maketextfiles'],
            options: {
                event: ['added', 'deleted'],
            }
        },
        textFilesJam: {
            files: [
                'project/jam/require.config.js'
            ],
            tasks: ['maketextfiles'],
        }
    }
});

Options

options.projectPackage

Type: Object Default value: grunt.file.readJSON('package.json')

The contents of package.json where textDirs are set.

options.projectBasePath

Type: String Default value: project/

The name of the project folder to search in.

options.destinationFileName

Type: String Default value: project/textFiles.js

The name of the output file relative to the Gruntfile.

Usage Examples

Default Options

These would be the default options as used in a Gruntfile.

grunt.initConfig({
  makeTextFiles: {
    options: {
      projectPackage: grunt.file.readJSON('package.json'),
      projectBasePath: 'project/',
      destinationFileName: 'project/textFiles.js',
    },
  },
});

package.json files

This task reads text directories from package.json file for the main project and jam packages.

Text file definitions must be declared inside the textDirs property in a package file. This is an array of objects to parse, each containing these properties:

textDirs.path

Type: String

Relative path of the directory to parse

textDirs.fileTypes

Type: array

Array of file extensions to match inside the textDirs.path

example package.json property

"textDirs": [
    {
        "path": "data"
        "fileTypes": [
            "json",
            "yaml"
        ] 
    },
    {
        "path": "templates"
        "fileTypes": [
            "html"
        ] 
    }
]

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.
  • To release:
    • Update package.json with version number (use semver)
    • Update CHANGELOG.md
    • Tag release with version number

About

License:MIT License


Languages

Language:JavaScript 100.0%