jwvdiermen/grunt-include-source

Please support TypeScript template

Closed this issue · 1 comments

Currently, there's a constant need to create a file with references to all typescript files, so that it could be globally included to determine types. This plugin works great for this, but needs a small enhancement to work properly.

This is the expected syntax and generated output. I've re-used html, as it seemed the closest and updated it with Typescript-specific things. Such comment is ignored by typescript compiler and allows for safe compilation.

/// <!-- include: "type": "ts", "files": "**/*.ts", "ordering": "top-down" -->
/// <reference path="../client/application/application.ts" />
/// <!-- /include -->

Basically to support TS, please update parsers and templates to this (note the "ts" at the end of each)

    var parsers = {
        'html': parseSource('HTML', /<!---?\s*include:\s+(.*)\s*-?--\s*>/gi),
        'haml': parseSource('HAML', /-#\s+include:\s+(.*)/gi),
        'jade': parseSource('JADE', /\/\/-?\s+include:\s+(.*)/gi),
        'scss': parseSource('SASS', /\/\/\s+include:\s+(.*)/gi),
        'ts': parseSource('TS', /\/\/\/\s<!---?\s*include:\s+(.*)\s*-?--\s*>/gi)
    };

    var endMarkerParsers = {
        'html': findEndMarker('HTML', /<!---?\s*\/include\s+-?--\>/i),
        'haml': findEndMarker('HAML', /-#\s+\/include/i),
        'jade': findEndMarker('JADE', /\/\/-?\s+\/include/i),
        'scss': findEndMarker('SASS', /\/\/\s+\/include/i),
        'ts': findEndMarker('TS', /\/\/\/\s<!---?\s*\/include\s+-?--\>/i)
    };

    var templates = {
        'html':
        {
            'js': '<script src="{filePath}"></script>',
            'css': '<link href="{filePath}" rel="stylesheet" type="text/css">'
        },
        'haml':
        {
            'js': '%script{src: "{filePath}"}',
            'css': '%link{href: "{filePath}", rel: "stylesheet", type: "text/css"}/'
        },
        'jade':
        {
            'js': 'script(src="{filePath}")',
            'css': 'link(href="{filePath}", rel="stylesheet", type="text/css")'
        },
        'scss':
        {
            'scss': '@import "{filePath}";',
            'css': '@import "{filePath}";'
        },
        'ts':
        {
            'ts': '/// <reference path="{filePath}" />'
        }
    };

Added in next release, please let me know if you have any issues.