<commit_before>"use strict";

var _ = require('underscore');

module.exports = function (grunt) {

    let additionalMetadata;
    let allCweDescriptions;

    function getAllRules() {
        const contribRules = grunt.file.expand('dist/build/*Rule.js');
        const baseRules = grunt.file.expand('node_modules/tslint/lib/rules/*Rule.js');
        return contribRules.concat(baseRules);
    }

    function hash(input) {
        // initialized with a prime number
        let hash = 31;
        let i = 0;
        for (i = 0; i < input.length; i++) {
            // multiply by prime so to get the better distribution of the values
            hash = 31 * hash + input.charCodeAt(i); // run the hash function on all chars
            hash = hash | 0; // convert to 32 bit signed integer
        }
        return Math.abs(hash).toString(32).toUpperCase();
    }

    function getMetadataFromFile(ruleFile) {
        const moduleName = './' + ruleFile.replace(/\.js$/, '');
        const module = require(moduleName);
        if (module.Rule.metadata == null) {
            grunt.fail.warn('No metadata found for ' + moduleName);
            return;
        }
        return module.Rule.metadata;
    }

    function createCweDescription(metadata) {
        allCweDescriptions = allCweDescriptions || grunt.file.readJSON('./cwe_descriptions.json', { encoding: 'UTF-8' });

        const cwe = getMetadataValue(metadata, 'commonWeaknessEnumeration', true, true);
        if (cwe === '') {
            return '';
        }

        let result = '';
        cwe.split(',').forEach(function (cweNumber) {
            cweNumber = cweNumber.trim();
            const description = allCweDescriptions[cweNumber];
            if (description == null) {
                grunt.fail.warn(`Cannot find description of ${cweNumber} for rule ${metadata['ruleName']} in cwe_descriptions.json`)
            }
            if (result !== '') {
                result = result + '\n';
            }
            result = result + `CWE ${cweNumber} - ${description}`
        });
        if (result !== '') {
            return '"' + result + '"';
        }
        return result;
    }

    function getMetadataValue(metadata, name, allowEmpty, doNotEscape) {
        additionalMetadata = additionalMetadata || grunt.file.readJSON('./additional_rule_metadata.json', { encoding: 'UTF-8' });

        let value = metadata[name];
        if (value == null) {
            if (additionalMetadata[metadata.ruleName] == null) {
                if (allowEmpty == false) {
                    grunt.fail.warn(`Could not read metadata for rule ${metadata.ruleName} from additional_rule_metadata.json`);
                } else {
                    return '';
                }
            }
            value = additionalMetadata[metadata.ruleName][name];
            if (value == null) {
                if (allowEmpty == false) {
                    grunt.fail.warn(`Could not read attribute ${name} of rule ${metadata.ruleName}`);
                }
                return '';
            }
        }
        if (doNotEscape == true) {
            return value;
        }
        value = value.replace(/^\n+/, ''); // strip leading newlines
        value = value.replace(/\n/, ' '); // convert newlines
        if (value.indexOf(',') > -1) {
            return '"' + value + '"';
        } else {
            return value;
        }
    }

    function camelize(input) {
        return _(input).reduce(function (memo, element) {
            if (element.toLowerCase() === element) {
                memo = memo + element;
            } else {
                memo = memo + '-' + element.toLowerCase();
            }
            return memo;
        }, '');
    }

    function getAllRuleNames(options) {
        options = options || { skipTsLintRules: false }

        var convertToRuleNames = function (filename) {
            filename = filename
                .replace(/Rule\..*/, '')  // file extension plus Rule name
                .replace(/.*\//, '');     // leading path
            return camelize(filename);
        };

        var contribRules = _(grunt.file.expand('src/*Rule.ts')).map(convertToRuleNames);
        var baseRules = [];
        if (!options.skipTsLintRules) {
            baseRules = _(grunt.file.expand('node_modules/tslint/lib/rules/*Rule.js')).map(convertToRuleNames);
        }
        var allRules = baseRules.concat(contribRules);
        allRules.sort();
        return allRules;
    }

    function getAllFormatterNames() {

        var convertToRuleNames = function (filename) {
            filename = filename
                .replace(/Formatter\..*/, '')  // file extension plus Rule name
                .replace(/.*\//, '');     // leading path
            return camelize(filename);
        };

        var formatters = _(grunt.file.expand('src/*Formatter.ts')).map(convertToRuleNames);
        formatters.sort();
        return formatters;
    }

    function camelCase(input) {
        return input.toLowerCase().replace(/-(.)/g, function (match, group1) {
            return group1.toUpperCase();
        });
    }

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        clean: {
            src: ['dist'],
            options: {
                force: true
            }
        },

        copy: {
            options: {
                encoding: 'UTF-8'
            },
            package: {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/src',
                        src: ['**/*.js', '!references.js'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: 'dist/src',
                        src: ['**/*.json'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: 'dist/tests',
                        src: ['TestHelper.js', 'TestHelper.d.ts'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: '.',
                        src: ['README.md'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: '.',
                        src: ['recommended_ruleset.js'],
                        dest: 'dist/build'
                    }
                ]
            },
            json: {
                expand: true,
                cwd: '.',
                src: ['src/**/*.json'],
                dest: 'dist'
            }
        },

        mochaTest: {
            test: {
                src: ['dist/tests/**/*.js']
            }
        },

        ts: {
            default: {
                src: [
                    './src/**/*.ts{,x}',
                    './tests/**/*.ts{,x}'
                ],
                outDir: 'dist',
                options: {
                    module: 'commonjs',
                    target: 'es5',
                    declaration: true,
                    failOnTypeErrors: true,
                    jsx: 'react'
                }
            },
            'test-data': {
                src: [
                    './test-data/**/*.ts{,x}'
                ],
                outDir: 'dist',
                options: {
                    module: 'commonjs',
                    target: 'es5',
                    declaration: false,
                    failOnTypeErrors: true,
                    jsx: 'react'
                }
            }
        },

        tslint: {
            options: {
                rulesDirectory: 'dist/src'
            },
            prod: {
                options: {
                    configuration: grunt.file.readJSON("tslint.json", { encoding: 'UTF-8' })
                },
                files: {
                    src: [
                        'src/**/*.ts'
                    ]
                }
            },
            tests: {
                options: {
                    configuration: (function () {
                        let tslintJson = grunt.file.readJSON("tslint.json", { encoding: 'UTF-8' });
                        tslintJson.rules['no-multiline-string'] = false;
                        tslintJson.rules['quotemark'] = false;
                        tslintJson.rules['max-func-body-length'] = false;
                        return tslintJson;
                    })(),
                },
                files: {
                    src: [
                        'tests/**/*.ts',
                        '!**/references.ts'
                    ]
                }
            }
        },

        watch: {
            scripts: {
                files: [
                    './src/**/*.ts',
                    './tests/**/*.ts'
                ],
                tasks: [
                    'ts',
                    'mochaTest',
                    'tslint'
                ]
            }
        }

    });

    require('load-grunt-tasks')(grunt); // loads all grunt-* npm tasks
    require('time-grunt')(grunt);

    grunt.registerTask('create-package-json-for-npm', 'A task that creates a package.json file for the npm module', function () {
        var basePackageJson = grunt.file.readJSON('package.json', { encoding: 'UTF-8' });
        delete basePackageJson.devDependencies;
        grunt.file.write('dist/build/package.json', JSON.stringify(basePackageJson, null, 2), { encoding: 'UTF-8' });
    });

    grunt.registerTask('validate-debug-mode', 'A task that makes sure ErrorTolerantWalker.DEBUG is false', function () {
        // DON'T MAKE A RELEASE IN DEBUG MODE
        var fileText = grunt.file.read('src/utils/ErrorTolerantWalker.ts', { encoding: 'UTF-8' });
        if (fileText.indexOf('DEBUG: boolean = false') === -1) {
            grunt.fail.warn('ErrorTolerantWalker.DEBUG is turned on. Turn off debugging to make a release');
        }
    });

    grunt.registerTask('validate-documentation', 'A task that validates that all rules defined in src are documented in README.md\n' +
        'and validates that the package.json version is the same version defined in README.md', function () {

            var readmeText = grunt.file.read('README.md', { encoding: 'UTF-8' });
            var packageJson = grunt.file.readJSON('package.json', { encoding: 'UTF-8' });
            getAllRuleNames({ skipTsLintRules: true }).forEach(function (ruleName) {
                if (readmeText.indexOf(ruleName) === -1) {
                    grunt.fail.warn('A rule was found that is not documented in README.md: ' + ruleName);
                }
            });
            getAllFormatterNames().forEach(function (formatterName) {
                if (readmeText.indexOf(formatterName) === -1) {
                    grunt.fail.warn('A formatter was found that is not documented in README.md: ' + formatterName);
                }
            });

            if (readmeText.indexOf('\nVersion ' + packageJson.version + ' ') === -1) {
                grunt.fail.warn('Version not documented in README.md correctly.\n' +
                    'package.json declares: ' + packageJson.version + '\n' +
                    'README.md declares something different.');
            }
        });

    grunt.registerTask('validate-config', 'A task that makes sure all the rules in the project are defined to run during the build.', function () {

        var tslintConfig = grunt.file.readJSON('tslint.json', { encoding: 'UTF-8' });
        var rulesToSkip = {
            'no-unexternalized-strings': true,
            'object-literal-key-quotes': true,
            'no-relative-imports': true,
            'no-empty-line-after-opening-brace': true
        };
        var errors = [];
        getAllRuleNames().forEach(function (ruleName) {
            if (rulesToSkip[ruleName]) {
                return;
            }
            if (tslintConfig.rules[ruleName] !== true && tslintConfig.rules[ruleName] !== false) {
                if (tslintConfig.rules[ruleName] == null || tslintConfig.rules[ruleName][0] !== true) {
                    errors.push('A rule was found that is not enabled on the project: ' + ruleName);
                }
            }
        });

        if (errors.length > 0) {
            grunt.fail.warn(errors.join('\n'));
        }
    });

    grunt.registerTask('generate-sdl-report', 'A task that generates an SDL report in csv format', function () {

        const rows = [];
        const resolution = 'See description on the tslint or tslint-microsoft-contrib website';
        const procedure = 'TSLint Procedure';
        const header = 'Title,Description,ErrorID,Tool,IssueClass,IssueType,SDL Bug Bar Severity,' +
            'SDL Level,Resolution,SDL Procedure,CWE,CWE Description';
        getAllRules().forEach(function (ruleFile) {
            const metadata = getMetadataFromFile(ruleFile);

            const issueClass = getMetadataValue(metadata, 'issueClass');
            if (issueClass === 'Ignored') {
                return;
            }
            const ruleName = getMetadataValue(metadata, 'ruleName');
            const errorId = 'TSLINT' + hash(ruleName);
            const issueType = getMetadataValue(metadata, 'issueType');
            const severity = getMetadataValue(metadata, 'severity');
            const level = getMetadataValue(metadata, 'level');
            const description = getMetadataValue(metadata, 'description');
            const cwe = getMetadataValue(metadata, 'commonWeaknessEnumeration', true, false);
            const cweDescription = createCweDescription(metadata);

            const row = `${ruleName},${description},${errorId},tslint,${issueClass},${issueType},${severity},${level},${resolution},${procedure},${cwe},${cweDescription}`;
            rows.push(row);
        });
        rows.sort();
        rows.unshift(header);
        grunt.file.write('tslint-warnings.csv', rows.join('\n'), { encoding: 'UTF-8' });

    });

    grunt.registerTask('generate-recommendations', 'A task that generates the recommended_ruleset.js file', function () {

        const groupedRows = {};

        getAllRules().forEach(function (ruleFile) {
            const metadata = getMetadataFromFile(ruleFile);

            const groupName = getMetadataValue(metadata, 'group');
            if (groupName === 'Ignored') {
                return;
            }
            if (groupedRows[groupName] == null) {
                groupedRows[groupName] = [];
            }

            let recommendation = getMetadataValue(metadata, 'recommendation', true, true);
            if (recommendation === '') {
                recommendation = 'true,';
            }
            const ruleName = getMetadataValue(metadata, 'ruleName');
            groupedRows[groupName].push(`        "${ruleName}": ${recommendation}`);
        });

        _.values(groupedRows).forEach(function (element) { element.sort(); });

        let data = grunt.file.read('./templates/recommended_ruleset.js.snippet', { encoding: 'UTF-8' });
        data = data.replace('%security_rules%', groupedRows['Security'].join('\n'));
        data = data.replace('%correctness_rules%', groupedRows['Correctness'].join('\n'));
        data = data.replace('%clarity_rules%', groupedRows['Clarity'].join('\n'));
        data = data.replace('%whitespace_rules%', groupedRows['Whitespace'].join('\n'));
        data = data.replace('%configurable_rules%', groupedRows['Configurable'].join('\n'));
        data = data.replace('%deprecated_rules%', groupedRows['Deprecated'].join('\n'));
        data = data.replace('%accessibilityy_rules%', groupedRows['Accessibility'].join('\n'));
        grunt.file.write('recommended_ruleset.js', data, { encoding: 'UTF-8' });
    });

    grunt.registerTask('generate-default-tslint-json', 'A task that converts recommended_ruleset.js to ./dist/build/tslint.json', function () {
        const data = require('./recommended_ruleset.js');
        grunt.file.write('./dist/build/tslint.json', JSON.stringify(data, null, 2), { encoding: 'UTF-8' });
    });

    grunt.registerTask('create-rule', 'A task that creates a new rule from the rule templates. --rule-name parameter required', function () {

        function applyTemplates(source) {
            return source.replace(/%RULE_NAME%/gm, ruleName)
                .replace(/%RULE_FILE_NAME%/gm, ruleFile)
                .replace(/%WALKER_NAME%/gm, walkerName);
        }

        var ruleName = grunt.option('rule-name');
        if (!ruleName) {
            grunt.fail.warn('--rule-name parameter is required');
        } else {

            var ruleFile = camelCase(ruleName) + 'Rule';
            var sourceFileName = './src/' + ruleFile + '.ts';
            var testFileName = './tests/' + ruleFile.charAt(0).toUpperCase() + ruleFile.substr(1) + 'Tests.ts';
            var walkerName = ruleFile.charAt(0).toUpperCase() + ruleFile.substr(1) + 'Walker';

            var ruleTemplateText = grunt.file.read('./templates/rule.snippet', { encoding: 'UTF-8' });
            var testTemplateText = grunt.file.read('./templates/rule-tests.snippet', { encoding: 'UTF-8' });

            grunt.file.write(sourceFileName, applyTemplates(ruleTemplateText), { encoding: 'UTF-8' });
            grunt.file.write(testFileName, applyTemplates(testTemplateText), { encoding: 'UTF-8' });

            var currentRuleset = grunt.file.readJSON('./tslint.json', { encoding: 'UTF-8' });
            currentRuleset.rules[ruleName] = true;
            grunt.file.write('./tslint.json', JSON.stringify(currentRuleset, null, 2), { encoding: 'UTF-8' });
        }
    });

    grunt.registerTask('all', 'Performs a cleanup and a full build with all tasks', [
        'clean',
        'copy:json',
        'ts:default',
        'mochaTest',
        'tslint',
        'validate-documentation',
        'validate-config',
        'validate-debug-mode',
        'copy:package',
        'generate-recommendations',
        'generate-default-tslint-json',
        'generate-sdl-report',
        'create-package-json-for-npm'
    ]);

    grunt.registerTask('default', ['all']);

};
<commit_msg>[Issue #211,#212,#213,#214,#215,#216] reverting gruntFile.js whitespace changes<commit_after>"use strict";

var _ = require('underscore');

module.exports = function(grunt) {

    let additionalMetadata;
    let allCweDescriptions;

    function getAllRules() {
        const contribRules = grunt.file.expand('dist/build/*Rule.js');
        const baseRules = grunt.file.expand('node_modules/tslint/lib/rules/*Rule.js');
        return contribRules.concat(baseRules);
    }

    function hash(input) {
        // initialized with a prime number
        let hash = 31;
        let i = 0;
        for (i = 0; i < input.length; i++) {
            // multiply by prime so to get the better distribution of the values
            hash = 31 * hash + input.charCodeAt(i); // run the hash function on all chars
            hash = hash | 0; // convert to 32 bit signed integer
        }
        return Math.abs(hash).toString(32).toUpperCase();
    }

    function getMetadataFromFile(ruleFile) {
        const moduleName = './' + ruleFile.replace(/\.js$/, '');
        const module = require(moduleName);
        if (module.Rule.metadata == null) {
            grunt.fail.warn('No metadata found for ' + moduleName);
            return;
        }
        return module.Rule.metadata;
    }

    function createCweDescription(metadata) {
        allCweDescriptions = allCweDescriptions || grunt.file.readJSON('./cwe_descriptions.json', {encoding: 'UTF-8'});

        const cwe = getMetadataValue(metadata, 'commonWeaknessEnumeration', true, true);
        if (cwe === '') {
            return '';
        }

        let result = '';
        cwe.split(',').forEach(function (cweNumber) {
            cweNumber = cweNumber.trim();
            const description = allCweDescriptions[cweNumber];
            if (description == null) {
                grunt.fail.warn(`Cannot find description of ${cweNumber} for rule ${metadata['ruleName']} in cwe_descriptions.json`)
            }
            if (result !== '') {
                result = result + '\n';
            }
            result = result + `CWE ${cweNumber} - ${description}`
        });
        if (result !== '') {
            return '"' + result + '"';
        }
        return result;
    }

    function getMetadataValue(metadata, name, allowEmpty, doNotEscape) {
        additionalMetadata = additionalMetadata || grunt.file.readJSON('./additional_rule_metadata.json', {encoding: 'UTF-8'});

        let value = metadata[name];
        if (value == null) {
            if (additionalMetadata[metadata.ruleName] == null) {
                if (allowEmpty == false) {
                    grunt.fail.warn(`Could not read metadata for rule ${metadata.ruleName} from additional_rule_metadata.json`);
                } else {
                    return '';
                }
            }
            value = additionalMetadata[metadata.ruleName][name];
            if (value == null) {
                if (allowEmpty == false) {
                    grunt.fail.warn(`Could not read attribute ${name} of rule ${metadata.ruleName}`);
                }
                return '';
            }
        }
        if (doNotEscape == true) {
            return value;
        }
        value = value.replace(/^\n+/, ''); // strip leading newlines
        value = value.replace(/\n/, ' '); // convert newlines
        if (value.indexOf(',') > -1) {
            return '"' + value + '"';
        } else {
            return value;
        }
    }

    function camelize(input) {
        return _(input).reduce(function(memo, element) {
            if (element.toLowerCase() === element) {
                memo = memo + element;
            } else {
                memo = memo + '-' + element.toLowerCase();
            }
            return memo;
        }, '');
    }

    function getAllRuleNames(options) {
        options = options || { skipTsLintRules: false }

        var convertToRuleNames = function(filename) {
            filename = filename
                .replace(/Rule\..*/, '')  // file extension plus Rule name
                .replace(/.*\//, '');     // leading path
            return camelize(filename);
        };

        var contribRules = _(grunt.file.expand('src/*Rule.ts')).map(convertToRuleNames);
        var baseRules = [];
        if (!options.skipTsLintRules) {
            baseRules = _(grunt.file.expand('node_modules/tslint/lib/rules/*Rule.js')).map(convertToRuleNames);
        }
        var allRules = baseRules.concat(contribRules);
        allRules.sort();
        return allRules;
    }

    function getAllFormatterNames() {

        var convertToRuleNames = function(filename) {
            filename = filename
                .replace(/Formatter\..*/, '')  // file extension plus Rule name
                .replace(/.*\//, '');     // leading path
            return camelize(filename);
        };

        var formatters = _(grunt.file.expand('src/*Formatter.ts')).map(convertToRuleNames);
        formatters.sort();
        return formatters;
    }

    function camelCase(input) {
        return input.toLowerCase().replace(/-(.)/g, function(match, group1) {
            return group1.toUpperCase();
        });
    }

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        clean: {
            src: ['dist'],
            options: {
                force: true
            }
        },

        copy: {
            options: {
                encoding: 'UTF-8'
            },
            package: {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/src',
                        src: ['**/*.js', '!references.js'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: 'dist/src',
                        src: ['**/*.json'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: 'dist/tests',
                        src: ['TestHelper.js', 'TestHelper.d.ts'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: '.',
                        src: ['README.md'],
                        dest: 'dist/build'
                    },
                    {
                        expand: true,
                        cwd: '.',
                        src: ['recommended_ruleset.js'],
                        dest: 'dist/build'
                    }
                ]
            },
            json: {
                expand: true,
                cwd: '.',
                src: ['src/**/*.json'],
                dest: 'dist'
            }
        },

        mochaTest: {
            test: {
                src: ['dist/tests/**/*.js']
            }
        },

        ts: {
            default: {
                src: [
                    './src/**/*.ts{,x}',
                    './tests/**/*.ts{,x}'
                ],
                outDir: 'dist',
                options: {
                    module: 'commonjs',
                    target: 'es5',
                    declaration: true,
                    failOnTypeErrors: true,
                    jsx: 'react'
                }
            },
            'test-data': {
                src: [
                    './test-data/**/*.ts{,x}'
                ],
                outDir: 'dist',
                options: {
                    module: 'commonjs',
                    target: 'es5',
                    declaration: false,
                    failOnTypeErrors: true,
                    jsx: 'react'
                }
            }
        },

        tslint: {
            options: {
                rulesDirectory: 'dist/src'
            },
            prod: {
                options: {
                    configuration: grunt.file.readJSON("tslint.json", { encoding: 'UTF-8' })
                },
                files: {
                    src: [
                        'src/**/*.ts'
                    ]
                }
            },
            tests: {
                options: {
                    configuration: (function() {
                        let tslintJson = grunt.file.readJSON("tslint.json", { encoding: 'UTF-8' });
                        tslintJson.rules['no-multiline-string'] = false;
                        tslintJson.rules['quotemark'] = false;
                        tslintJson.rules['max-func-body-length'] = false;
                        return tslintJson;
                    })(),
                },
                files: {
                    src: [
                        'tests/**/*.ts',
                        '!**/references.ts'
                    ]
                }
            }
        },

        watch: {
            scripts: {
                files: [
                    './src/**/*.ts',
                    './tests/**/*.ts'
                ],
                tasks: [
                    'ts',
                    'mochaTest',
                    'tslint'
                ]
            }
        }

    });

    require('load-grunt-tasks')(grunt); // loads all grunt-* npm tasks
    require('time-grunt')(grunt);

    grunt.registerTask('create-package-json-for-npm', 'A task that creates a package.json file for the npm module', function () {
        var basePackageJson = grunt.file.readJSON('package.json', { encoding: 'UTF-8' });
        delete basePackageJson.devDependencies;
        grunt.file.write('dist/build/package.json', JSON.stringify(basePackageJson, null, 2), { encoding: 'UTF-8' });
    });

    grunt.registerTask('validate-debug-mode', 'A task that makes sure ErrorTolerantWalker.DEBUG is false', function () {
        // DON'T MAKE A RELEASE IN DEBUG MODE
        var fileText = grunt.file.read('src/utils/ErrorTolerantWalker.ts', { encoding: 'UTF-8' });
        if (fileText.indexOf('DEBUG: boolean = false') === -1) {
            grunt.fail.warn('ErrorTolerantWalker.DEBUG is turned on. Turn off debugging to make a release');
        }
    });

    grunt.registerTask('validate-documentation', 'A task that validates that all rules defined in src are documented in README.md\n' +
        'and validates that the package.json version is the same version defined in README.md', function () {

        var readmeText = grunt.file.read('README.md', { encoding: 'UTF-8' });
        var packageJson = grunt.file.readJSON('package.json', { encoding: 'UTF-8' });
        getAllRuleNames({ skipTsLintRules: true }).forEach(function(ruleName) {
            if (readmeText.indexOf(ruleName) === -1) {
                grunt.fail.warn('A rule was found that is not documented in README.md: ' + ruleName);
            }
        });
        getAllFormatterNames().forEach(function(formatterName) {
            if (readmeText.indexOf(formatterName) === -1) {
                grunt.fail.warn('A formatter was found that is not documented in README.md: ' + formatterName);
            }
        });

        if (readmeText.indexOf('\nVersion ' + packageJson.version + ' ') === -1) {
            grunt.fail.warn('Version not documented in README.md correctly.\n' +
                'package.json declares: ' + packageJson.version + '\n' +
                'README.md declares something different.');
        }
    });

    grunt.registerTask('validate-config', 'A task that makes sure all the rules in the project are defined to run during the build.', function () {

        var tslintConfig = grunt.file.readJSON('tslint.json', { encoding: 'UTF-8' });
        var rulesToSkip = {
            'no-unexternalized-strings': true,
            'object-literal-key-quotes': true,
            'no-relative-imports': true,
            'no-empty-line-after-opening-brace': true
        };
        var errors = [];
        getAllRuleNames().forEach(function(ruleName) {
            if (rulesToSkip[ruleName]) {
                return;
            }
            if (tslintConfig.rules[ruleName] !== true && tslintConfig.rules[ruleName] !== false) {
                if (tslintConfig.rules[ruleName] == null || tslintConfig.rules[ruleName][0] !== true) {
                    errors.push('A rule was found that is not enabled on the project: ' + ruleName);
                }
            }
        });

        if (errors.length > 0) {
            grunt.fail.warn(errors.join('\n'));
        }
    });

    grunt.registerTask('generate-sdl-report', 'A task that generates an SDL report in csv format', function () {

        const rows = [];
        const resolution = 'See description on the tslint or tslint-microsoft-contrib website';
        const procedure = 'TSLint Procedure';
        const header = 'Title,Description,ErrorID,Tool,IssueClass,IssueType,SDL Bug Bar Severity,' +
            'SDL Level,Resolution,SDL Procedure,CWE,CWE Description';
        getAllRules().forEach(function(ruleFile) {
            const metadata = getMetadataFromFile(ruleFile);

            const issueClass = getMetadataValue(metadata, 'issueClass');
            if (issueClass === 'Ignored') {
                return;
            }
            const ruleName = getMetadataValue(metadata, 'ruleName');
            const errorId = 'TSLINT' + hash(ruleName);
            const issueType = getMetadataValue(metadata, 'issueType');
            const severity = getMetadataValue(metadata, 'severity');
            const level = getMetadataValue(metadata, 'level');
            const description = getMetadataValue(metadata, 'description');
            const cwe = getMetadataValue(metadata, 'commonWeaknessEnumeration', true, false);
            const cweDescription = createCweDescription(metadata);

            const row = `${ruleName},${description},${errorId},tslint,${issueClass},${issueType},${severity},${level},${resolution},${procedure},${cwe},${cweDescription}`;
            rows.push(row);
        });
        rows.sort();
        rows.unshift(header);
        grunt.file.write('tslint-warnings.csv', rows.join('\n'), {encoding: 'UTF-8'});

    });

    grunt.registerTask('generate-recommendations', 'A task that generates the recommended_ruleset.js file', function () {

        const groupedRows = {};

        getAllRules().forEach(function(ruleFile) {
            const metadata = getMetadataFromFile(ruleFile);

            const groupName = getMetadataValue(metadata, 'group');
            if (groupName === 'Ignored') {
                return;
            }
            if (groupedRows[groupName] == null) {
                groupedRows[groupName] = [];
            }

            let recommendation = getMetadataValue(metadata, 'recommendation', true, true);
            if (recommendation === '') {
                recommendation = 'true,';
            }
            const ruleName = getMetadataValue(metadata, 'ruleName');
            groupedRows[groupName].push(`        "${ruleName}": ${recommendation}`);
        });

        _.values(groupedRows).forEach(function (element) { element.sort(); });

        let data = grunt.file.read('./templates/recommended_ruleset.js.snippet', {encoding: 'UTF-8'});
        data = data.replace('%security_rules%',       groupedRows['Security'].join('\n'));
        data = data.replace('%correctness_rules%',    groupedRows['Correctness'].join('\n'));
        data = data.replace('%clarity_rules%',        groupedRows['Clarity'].join('\n'));
        data = data.replace('%whitespace_rules%',     groupedRows['Whitespace'].join('\n'));
        data = data.replace('%configurable_rules%',   groupedRows['Configurable'].join('\n'));
        data = data.replace('%deprecated_rules%',     groupedRows['Deprecated'].join('\n'));
        data = data.replace('%accessibilityy_rules%', groupedRows['Accessibility'].join('\n'));
        grunt.file.write('recommended_ruleset.js', data, {encoding: 'UTF-8'});
    });

    grunt.registerTask('generate-default-tslint-json', 'A task that converts recommended_ruleset.js to ./dist/build/tslint.json', function () {
        const data = require('./recommended_ruleset.js');
        grunt.file.write('./dist/build/tslint.json', JSON.stringify(data, null, 2), {encoding: 'UTF-8'});
    });

    grunt.registerTask('create-rule', 'A task that creates a new rule from the rule templates. --rule-name parameter required', function () {

        function applyTemplates(source) {
            return source.replace(/%RULE_NAME%/gm, ruleName)
                .replace(/%RULE_FILE_NAME%/gm, ruleFile)
                .replace(/%WALKER_NAME%/gm, walkerName);
        }

        var ruleName = grunt.option('rule-name');
        if (!ruleName) {
            grunt.fail.warn('--rule-name parameter is required');
        } else {

            var ruleFile = camelCase(ruleName) + 'Rule';
            var sourceFileName = './src/' + ruleFile + '.ts';
            var testFileName = './tests/' + ruleFile.charAt(0).toUpperCase() + ruleFile.substr(1) + 'Tests.ts';
            var walkerName = ruleFile.charAt(0).toUpperCase() + ruleFile.substr(1) + 'Walker';

            var ruleTemplateText = grunt.file.read('./templates/rule.snippet', {encoding: 'UTF-8'});
            var testTemplateText = grunt.file.read('./templates/rule-tests.snippet', {encoding: 'UTF-8'});

            grunt.file.write(sourceFileName, applyTemplates(ruleTemplateText), {encoding: 'UTF-8'});
            grunt.file.write(testFileName, applyTemplates(testTemplateText), {encoding: 'UTF-8'});

            var currentRuleset = grunt.file.readJSON('./tslint.json', {encoding: 'UTF-8'});
            currentRuleset.rules[ruleName] = true;
            grunt.file.write('./tslint.json', JSON.stringify(currentRuleset, null, 2), {encoding: 'UTF-8'});
        }
    });

    grunt.registerTask('all', 'Performs a cleanup and a full build with all tasks', [
        'clean',
        'copy:json',
        'ts:default',
        'mochaTest',
        'tslint',
        'validate-documentation',
        'validate-config',
        'validate-debug-mode',
        'copy:package',
        'generate-recommendations',
        'generate-default-tslint-json',
        'generate-sdl-report',
        'create-package-json-for-npm'
    ]);

    grunt.registerTask('default', ['all']);

};
<|endoftext|>


<commit_before>module.exports = function (grunt) {

    // 1. All configuration goes here
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        qunit: {
            hello: [
                'test/helloQUnit.html'
             ]
        },

        concat: {
            igv: {
                src: [
                    'js/**/*.js',
                    'vendor/inflate.js',
                    'vendor/zlib_and_gzip.min.js',
                    'vendor/colorpickers/vanderlee-github-io/jquery.colorpicker.js',
                    'vendor/colorpickers/vanderlee-github-io/i18n/jquery.ui.colorpicker-nl.js',
                    'vendor/colorpickers/vanderlee-github-io/swatches/jquery.ui.colorpicker-pantone.js',
                    'vendor/colorpickers/vanderlee-github-io/parts/jquery.ui.colorpicker-rgbslider.js',
                    'vendor/colorpickers/vanderlee-github-io/parts/jquery.ui.colorpicker-memory.js',
                    'vendor/colorpickers/vanderlee-github-io/parsers/jquery.ui.colorpicker-cmyk-parser.js',
                    'vendor/colorpickers/vanderlee-github-io/parsers/jquery.ui.colorpicker-cmyk-percentage-parser.js'
                ],
                dest: 'dist/igv-all.js'
            }
        },

        uglify: {
            options: {
                mangle: false,
                sourceMap: true
            },

            igv: {
                src: 'dist/igv-all.js',
                dest: 'dist/igv-all.min.js'
            }
        },

        md2html: {
            options: {
                layout: 'docs/api_layout.html'
            },
            igv: {
                src: ['docs/api.md'],
                dest: 'dist/api.html'
            }
        }

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-md2html');
    grunt.loadNpmTasks('grunt-contrib-qunit');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    //grunt.registerTask('default', ['concat:igvexp', 'uglify:igvexp']);
    grunt.registerTask('default', ['concat:igv', 'uglify:igv', 'md2html:igv']);

};

<commit_msg>Gruntfile.js. Checking unit test task<commit_after>module.exports = function (grunt) {

    // 1. All configuration goes here
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        qunit: {
            hello: [
                'test/helloQUnit.html'
             ]
        },

        concat: {
            igv: {
                src: [
                    'js/**/*.js',
                    'vendor/inflate.js',
                    'vendor/zlib_and_gzip.min.js',
                    'vendor/colorpickers/vanderlee-github-io/jquery.colorpicker.js',
                    'vendor/colorpickers/vanderlee-github-io/i18n/jquery.ui.colorpicker-nl.js',
                    'vendor/colorpickers/vanderlee-github-io/swatches/jquery.ui.colorpicker-pantone.js',
                    'vendor/colorpickers/vanderlee-github-io/parts/jquery.ui.colorpicker-rgbslider.js',
                    'vendor/colorpickers/vanderlee-github-io/parts/jquery.ui.colorpicker-memory.js',
                    'vendor/colorpickers/vanderlee-github-io/parsers/jquery.ui.colorpicker-cmyk-parser.js',
                    'vendor/colorpickers/vanderlee-github-io/parsers/jquery.ui.colorpicker-cmyk-percentage-parser.js'
                ],
                dest: 'dist/igv-all.js'
            }
        },

        uglify: {
            options: {
                mangle: false,
                sourceMap: true
            },

            igv: {
                src: 'dist/igv-all.js',
                dest: 'dist/igv-all.min.js'
            }
        },

        md2html: {
            options: {
                layout: 'docs/api_layout.html'
            },
            igv: {
                src: ['docs/api.md'],
                dest: 'dist/api.html'
            }
        }

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-md2html');
    grunt.loadNpmTasks('grunt-contrib-qunit');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    //grunt.registerTask('default', ['concat:igvexp', 'uglify:igvexp']);
    //grunt.registerTask('default', ['concat:igv', 'uglify:igv', 'md2html:igv']);
    grunt.registerTask('default', ['qunit:hello', 'concat:igv', 'uglify:igv', 'md2html:igv']);

};

<|endoftext|>


<commit_before>module.exports = function(grunt) {

	grunt.initConfig({

		pkg: grunt.file.readJSON('package.json'),

		// Copy files that don't need compilation to dist/
		copy: {
			dist: {
				files: [
					// Copy all (non hidden) files (not directories) from src
					{dest: 'dist/', src: '*', filter: 'isFile', expand: true, cwd: 'src/'},

					// Copy the following hidden files
					{dest: 'dist/.htaccess', src: 'src/.htaccess'},

					// Copy any JavaScript libs
					{dest: 'dist/', src: 'js/vendor/*.min.js', expand: true, cwd: 'src/'},

					// Copy any CSS files (not LESS src)
					{dest: 'dist/', src: 'css/**/*.css', expand: true, cwd: 'src/'},

					// Copy other resources
					{dest: 'dist/', src: 'img/**', expand: true, cwd: 'src/'},
					{dest: 'dist/', src: 'font/**', expand: true, cwd: 'src/'}
				]
			}
		},

		includereplace: {
			dist: {
				options: {
					globals: {
						version: '<%= pkg.version %>',
						headHtml: ''
					}
				},
				files: [
					{src: '*.html', dest: 'dist/', expand: true, cwd: 'src/'},
					{src: 'inc/*.html', dest: 'dist/', expand: true, cwd: 'src/'}
				]
			}
		},

		// Compile the mobile first site stylesheet (and the no @media queries version for lt-ie8)
		less: {
			compile: {
				files: {
					'dist/css/main-<%= pkg.version %>.css': 'src/css/main.less'
				}
			}
		},

		browserify: {
			dist: {
				files: {'dist/js/bundle-<%= pkg.version %>.js': 'src/js/main.js'},
				options: {transform: ['brfs']}
			}
		},

		// Minify the site script
		uglify: {
			options: {
				/*compress: true,*/
				mangle: true,
				preserveComments: false,
				report: 'min'
			},
			compress: {
				src: 'dist/js/bundle-<%= pkg.version %>.js',
				dest: 'dist/js/bundle-<%= pkg.version %>.js'
			}
		},

		// Minify the site CSS
		cssmin: {
			compress: {
				options: {
					keepSpecialComments: 0,
					report: 'min'
				},
				files: {
					'dist/css/main-<%= pkg.version %>.css': 'dist/css/main-<%= pkg.version %>.css',
					'dist/css/font-awesome-ie7.css': 'dist/css/font-awesome-ie7.css'
				}
			}
		},

		// Lint the server JavaScript
		jshint: {
			files: ['*.js', 'src/js/*.js', 'test/*.js'],
			options: {
				'browser': false,
				'maxerr': 100,
				'node': true,
				/*'camelcase': true,*/
				'curly': true,
				'eqeqeq': true,
				'eqnull': true,
				'forin': true,
				'immed': true,
				'indent': 4,
				/*'latedef': true,*/
				'laxbreak': true,
				'laxcomma': true,
				'lastsemic': true,
				'loopfunc': true,
				'noarg': true,
				'newcap': true,
				'plusplus': false,
				'quotmark': 'single',
				'regexp': true,
				'shadow': true,
				'smarttabs': true,
				'strict': false,
				'sub': true,
				'trailing': true,
				'undef': true,
				'unused': true
			}
		},

		// Test the things
		nodeunit: {
			all: ['test/**/*_test.js']
		},

		// Watch JS, LESS & HTML files for changes, copy & compile but not minify for easy debug during dev
		watch: {
			project: {
				options: {atBegin: true},
				files: ['src/js/**/*.js', 'src/css/**/*.less', 'src/**/*.html', 'src/img/**/*'],
				tasks: ['copy', 'includereplace', 'less', 'browserify']
			}
		},

		clean: {
			dist: 'dist/*'
		}
	});

	// Load the grunt plugins
	grunt.loadNpmTasks('grunt-browserify');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-copy');
	grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-contrib-less');
	grunt.loadNpmTasks('grunt-contrib-nodeunit');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-watch');
	grunt.loadNpmTasks('grunt-include-replace');

	grunt.registerTask('default', ['jshint', 'nodeunit', 'copy', 'includereplace', 'less', 'browserify', 'uglify', 'cssmin']);
	grunt.registerTask('no-min', ['jshint', 'nodeunit', 'copy', 'includereplace', 'less', 'browserify']);
};
<commit_msg>We don't need ".htaccess" so don't copy it to dist.<commit_after>module.exports = function(grunt) {

	grunt.initConfig({

		pkg: grunt.file.readJSON('package.json'),

		// Copy files that don't need compilation to dist/
		copy: {
			dist: {
				files: [
					// Copy all (non hidden) files (not directories) from src
					{dest: 'dist/', src: '*', filter: 'isFile', expand: true, cwd: 'src/'},

					// Copy any JavaScript libs
					{dest: 'dist/', src: 'js/vendor/*.min.js', expand: true, cwd: 'src/'},

					// Copy any CSS files (not LESS src)
					{dest: 'dist/', src: 'css/**/*.css', expand: true, cwd: 'src/'},

					// Copy other resources
					{dest: 'dist/', src: 'img/**', expand: true, cwd: 'src/'},
					{dest: 'dist/', src: 'font/**', expand: true, cwd: 'src/'}
				]
			}
		},

		includereplace: {
			dist: {
				options: {
					globals: {
						version: '<%= pkg.version %>',
						headHtml: ''
					}
				},
				files: [
					{src: '*.html', dest: 'dist/', expand: true, cwd: 'src/'},
					{src: 'inc/*.html', dest: 'dist/', expand: true, cwd: 'src/'}
				]
			}
		},

		// Compile the mobile first site stylesheet (and the no @media queries version for lt-ie8)
		less: {
			compile: {
				files: {
					'dist/css/main-<%= pkg.version %>.css': 'src/css/main.less'
				}
			}
		},

		browserify: {
			dist: {
				files: {'dist/js/bundle-<%= pkg.version %>.js': 'src/js/main.js'},
				options: {transform: ['brfs']}
			}
		},

		// Minify the site script
		uglify: {
			options: {
				/*compress: true,*/
				mangle: true,
				preserveComments: false,
				report: 'min'
			},
			compress: {
				src: 'dist/js/bundle-<%= pkg.version %>.js',
				dest: 'dist/js/bundle-<%= pkg.version %>.js'
			}
		},

		// Minify the site CSS
		cssmin: {
			compress: {
				options: {
					keepSpecialComments: 0,
					report: 'min'
				},
				files: {
					'dist/css/main-<%= pkg.version %>.css': 'dist/css/main-<%= pkg.version %>.css',
					'dist/css/font-awesome-ie7.css': 'dist/css/font-awesome-ie7.css'
				}
			}
		},

		// Lint the server JavaScript
		jshint: {
			files: ['*.js', 'src/js/*.js', 'test/*.js'],
			options: {
				'browser': false,
				'maxerr': 100,
				'node': true,
				/*'camelcase': true,*/
				'curly': true,
				'eqeqeq': true,
				'eqnull': true,
				'forin': true,
				'immed': true,
				'indent': 4,
				/*'latedef': true,*/
				'laxbreak': true,
				'laxcomma': true,
				'lastsemic': true,
				'loopfunc': true,
				'noarg': true,
				'newcap': true,
				'plusplus': false,
				'quotmark': 'single',
				'regexp': true,
				'shadow': true,
				'smarttabs': true,
				'strict': false,
				'sub': true,
				'trailing': true,
				'undef': true,
				'unused': true
			}
		},

		// Test the things
		nodeunit: {
			all: ['test/**/*_test.js']
		},

		// Watch JS, LESS & HTML files for changes, copy & compile but not minify for easy debug during dev
		watch: {
			project: {
				options: {atBegin: true},
				files: ['src/js/**/*.js', 'src/css/**/*.less', 'src/**/*.html', 'src/img/**/*'],
				tasks: ['copy', 'includereplace', 'less', 'browserify']
			}
		},

		clean: {
			dist: 'dist/*'
		}
	});

	// Load the grunt plugins
	grunt.loadNpmTasks('grunt-browserify');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-copy');
	grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-contrib-less');
	grunt.loadNpmTasks('grunt-contrib-nodeunit');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-watch');
	grunt.loadNpmTasks('grunt-include-replace');

	grunt.registerTask('default', ['jshint', 'nodeunit', 'copy', 'includereplace', 'less', 'browserify', 'uglify', 'cssmin']);
	grunt.registerTask('no-min', ['jshint', 'nodeunit', 'copy', 'includereplace', 'less', 'browserify']);
};
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */
/*jslint regexp:true*/
/*global module, require, process*/
module.exports = function (grunt) {
    "use strict";

    var common  = require("./tasks/common")(grunt),
        resolve = common.resolve,
        platform = common.platform(),
        staging;

    if (platform === "mac") {
        staging = "installer/mac/staging/<%= build.name %>.app/Contents";
    } else if (platform === "win") {
        staging = "installer/win/staging";
    } else {
        staging = "installer/linux/debian/package-root/opt/brackets";
    }

    grunt.initConfig({
        "pkg":              grunt.file.readJSON("package.json"),
        "config-json":      staging + "/www/config.json",
        "curl-dir": {
            /* linux */
            "cef-linux32": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_linux32_release.zip"
            },
            "cef-linux64": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_linux64_release.zip"
            },
            "node-linux32": {
                "dest"      : "downloads/",
                "src"       : "http://nodejs.org/dist/v<%= node.version %>/node-v<%= node.version %>-linux-x86.tar.gz"
            },
            "node-linux64": {
                "dest"      : "downloads/",
                "src"       : "http://nodejs.org/dist/v<%= node.version %>/node-v<%= node.version %>-linux-x64.tar.gz"
            },
            /* mac */
            "cef-mac": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_macosx.zip"
            },
            "node-mac": {
                "dest"      : "downloads/",
                "src"       : "http://nodejs.org/dist/v<%= node.version %>/node-v<%= node.version %>-darwin-x86.tar.gz"
            },
            /* win */
            "cef-win": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_windows.zip"
            },
            "node-win": {
                "dest"      : "downloads/",
                "src"       : ["http://nodejs.org/dist/v<%= node.version %>/node.exe",
                               "http://nodejs.org/dist/npm/npm-<%= npm.version %>.zip"]
            }
        },
        "clean": {
            "downloads"         : ["downloads"],
            "installer-mac"     : ["installer/mac/*.dmg"],
            "installer-win"     : ["installer/win/*.msi"],
            "installer-linux"   : ["installer/linux/debian/*.deb"],
            "staging-mac"       : ["installer/mac/staging"],
            "staging-win"       : ["installer/win/staging"],
            "staging-linux"     : ["<%= build.staging %>"],
            "www"               : ["<%= build.staging %>/www", "<%= build.staging %>/samples"]
        },
        "copy": {
            "win": {
                "files": [
                    {
                        "expand"    : true,
                        "cwd"       : "Release/",
                        "src"       : [
                            "locales/**",
                            "node-core/**",
                            "Brackets.exe",
                            "Brackets-node.exe",
                            "cef.pak",
                            "devtools_resources.pak",
                            "icudt.dll",
                            "libcef.dll"
                        ],
                        "dest"      : "installer/win/staging/"
                    }
                ]
            },
            // FIXME: see stage-mac task issues with copying .app bundles
            /*
            "mac": {
                "files": [
                    {
                        "expand"    : true,
                        "cwd"       : "xcodebuild/Release/<%= build.name %>.app/",
                        "src"       : ["**"],
                        "dest"      : "installer/mac/staging/<%= build.name %>.app/"
                    }
                ]
            },
            */
            "linux": {
                "files": [
                    {
                        "expand"    : true,
                        "cwd"       : "out/Release/",
                        "src"       : [
                            "lib/**",
                            "locales/**",
                            "appshell*.png",
                            "Brackets",
                            "cef.pak",
                            "devtools_resources.pak",
                        ],
                        "dest"      : "<%= build.staging %>"
                    },
                    {
                        "expand"    : true,
                        "cwd"       : "installer/linux/debian/",
                        "src"       : [
                            "brackets.desktop"
                        ],
                        "dest"      : "<%= build.staging %>"
                    }
                ]
            },
            "www": {
                "files": [
                    {
                        "dot"       : true,
                        "expand"    : true,
                        "cwd"       : "<%= git.www.repo %>/src",
                        "src"       : ["**", "!**/.git*"],
                        "dest"      : "<%= build.staging %>/www/"
                    }
                ]
            },
            "samples": {
                "files": [
                    {
                        "dot"       : true,
                        "expand"    : true,
                        "cwd"       : "<%= git.www.repo %>/samples",
                        "src"       : ["**"],
                        "dest"      : "<%= build.staging %>/samples/"
                    }
                ]
            }
        },
        "unzip": {
            "cef": {
                "src"       : "<%= cef_zip %>",
                "dest"      : "deps/cef"
            }
        },
        "jshint": {
            "all"           : ["Gruntfile.js", "tasks/**/*.js"],
            "options": {
                "jshintrc"  : ".jshintrc"
            }
        },
        "build": {
            "name"              : "Brackets",
            "staging"           : staging
        },
        "git": {
            "www": {
                "repo"      : "../brackets",    // TODO user configurable?
                "branch"    : grunt.option("www-branch") || ""
            },
            "shell": {
                "repo"      : ".",
                "branch"    : grunt.option("shell-branch") || ""
            }
        },
        "cef": {
            "version"       : "3.1453.1279"
        },
        "node": {
            "version"       : "0.8.20"
        },
        "npm": {
            "version"       : "1.2.11"
        }
    });

    grunt.loadTasks("tasks");
    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-contrib-copy");
    grunt.loadNpmTasks("grunt-contrib-clean");
    grunt.loadNpmTasks("grunt-curl");

    grunt.registerTask("default", ["setup", "build"]);
};
<commit_msg>fix jshint error<commit_after>/*
 * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */
/*jslint regexp:true*/
/*global module, require, process*/
module.exports = function (grunt) {
    "use strict";

    var common  = require("./tasks/common")(grunt),
        resolve = common.resolve,
        platform = common.platform(),
        staging;

    if (platform === "mac") {
        staging = "installer/mac/staging/<%= build.name %>.app/Contents";
    } else if (platform === "win") {
        staging = "installer/win/staging";
    } else {
        staging = "installer/linux/debian/package-root/opt/brackets";
    }

    grunt.initConfig({
        "pkg":              grunt.file.readJSON("package.json"),
        "config-json":      staging + "/www/config.json",
        "curl-dir": {
            /* linux */
            "cef-linux32": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_linux32_release.zip"
            },
            "cef-linux64": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_linux64_release.zip"
            },
            "node-linux32": {
                "dest"      : "downloads/",
                "src"       : "http://nodejs.org/dist/v<%= node.version %>/node-v<%= node.version %>-linux-x86.tar.gz"
            },
            "node-linux64": {
                "dest"      : "downloads/",
                "src"       : "http://nodejs.org/dist/v<%= node.version %>/node-v<%= node.version %>-linux-x64.tar.gz"
            },
            /* mac */
            "cef-mac": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_macosx.zip"
            },
            "node-mac": {
                "dest"      : "downloads/",
                "src"       : "http://nodejs.org/dist/v<%= node.version %>/node-v<%= node.version %>-darwin-x86.tar.gz"
            },
            /* win */
            "cef-win": {
                "dest"      : "downloads/",
                "src"       : "http://dev.brackets.io/cef/cef_binary_<%= cef.version %>_windows.zip"
            },
            "node-win": {
                "dest"      : "downloads/",
                "src"       : ["http://nodejs.org/dist/v<%= node.version %>/node.exe",
                               "http://nodejs.org/dist/npm/npm-<%= npm.version %>.zip"]
            }
        },
        "clean": {
            "downloads"         : ["downloads"],
            "installer-mac"     : ["installer/mac/*.dmg"],
            "installer-win"     : ["installer/win/*.msi"],
            "installer-linux"   : ["installer/linux/debian/*.deb"],
            "staging-mac"       : ["installer/mac/staging"],
            "staging-win"       : ["installer/win/staging"],
            "staging-linux"     : ["<%= build.staging %>"],
            "www"               : ["<%= build.staging %>/www", "<%= build.staging %>/samples"]
        },
        "copy": {
            "win": {
                "files": [
                    {
                        "expand"    : true,
                        "cwd"       : "Release/",
                        "src"       : [
                            "locales/**",
                            "node-core/**",
                            "Brackets.exe",
                            "Brackets-node.exe",
                            "cef.pak",
                            "devtools_resources.pak",
                            "icudt.dll",
                            "libcef.dll"
                        ],
                        "dest"      : "installer/win/staging/"
                    }
                ]
            },
            // FIXME: see stage-mac task issues with copying .app bundles
            /*
            "mac": {
                "files": [
                    {
                        "expand"    : true,
                        "cwd"       : "xcodebuild/Release/<%= build.name %>.app/",
                        "src"       : ["**"],
                        "dest"      : "installer/mac/staging/<%= build.name %>.app/"
                    }
                ]
            },
            */
            "linux": {
                "files": [
                    {
                        "expand"    : true,
                        "cwd"       : "out/Release/",
                        "src"       : [
                            "lib/**",
                            "locales/**",
                            "appshell*.png",
                            "Brackets",
                            "cef.pak",
                            "devtools_resources.pak"
                        ],
                        "dest"      : "<%= build.staging %>"
                    },
                    {
                        "expand"    : true,
                        "cwd"       : "installer/linux/debian/",
                        "src"       : [
                            "brackets.desktop"
                        ],
                        "dest"      : "<%= build.staging %>"
                    }
                ]
            },
            "www": {
                "files": [
                    {
                        "dot"       : true,
                        "expand"    : true,
                        "cwd"       : "<%= git.www.repo %>/src",
                        "src"       : ["**", "!**/.git*"],
                        "dest"      : "<%= build.staging %>/www/"
                    }
                ]
            },
            "samples": {
                "files": [
                    {
                        "dot"       : true,
                        "expand"    : true,
                        "cwd"       : "<%= git.www.repo %>/samples",
                        "src"       : ["**"],
                        "dest"      : "<%= build.staging %>/samples/"
                    }
                ]
            }
        },
        "unzip": {
            "cef": {
                "src"       : "<%= cef_zip %>",
                "dest"      : "deps/cef"
            }
        },
        "jshint": {
            "all"           : ["Gruntfile.js", "tasks/**/*.js"],
            "options": {
                "jshintrc"  : ".jshintrc"
            }
        },
        "build": {
            "name"              : "Brackets",
            "staging"           : staging
        },
        "git": {
            "www": {
                "repo"      : "../brackets",    // TODO user configurable?
                "branch"    : grunt.option("www-branch") || ""
            },
            "shell": {
                "repo"      : ".",
                "branch"    : grunt.option("shell-branch") || ""
            }
        },
        "cef": {
            "version"       : "3.1453.1279"
        },
        "node": {
            "version"       : "0.8.20"
        },
        "npm": {
            "version"       : "1.2.11"
        }
    });

    grunt.loadTasks("tasks");
    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-contrib-copy");
    grunt.loadNpmTasks("grunt-contrib-clean");
    grunt.loadNpmTasks("grunt-curl");

    grunt.registerTask("default", ["setup", "build"]);
};
<|endoftext|>


<commit_before>module.exports = function (grunt) {

  grunt.loadNpmTasks('grunt-tizen');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-release');
  grunt.loadTasks('tools/grunt-tasks');

  grunt.initConfig({
    packageInfo: grunt.file.readJSON('package.json'),
    chromeInfo: grunt.file.readJSON('platforms/chrome-crx/manifest.json'),

    clean: ['build'],

    release: {
      options: {
        npm: false,
        npmtag: false,
        tagName: 'v<%= version %>'
      }
    },

    tizen_configuration: {
      // location on the device to install the tizen-app.sh script to
      // (default: '/tmp')
      tizenAppScriptDir: '/home/developer/',

      // path to the config.xml file for the Tizen wgt file - post templating
      // (default: 'config.xml')
      configFile: 'build/wgt/config.xml',

      // path to the sdb command (default: process.env.SDB or 'sdb')
      sdbCmd: 'sdb'
    },

    // minify JS
    uglify: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: 'app/js/**/*.js', dest: 'build/' }
        ]
      }
    },

    // minify CSS
    cssmin: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: ['app/css/**/*.css'], dest: 'build/' }
        ]
      }
    },

    copy: {
      common: {
        files: [
          { expand: true, cwd: '.', src: ['app/lib/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/audio/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/data/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['LICENSE'], dest: 'build/app/' },
          { expand: true, cwd: '.', src: ['app/README.txt'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/_locales/**'], dest: 'build/' }
        ]
      },

      wgt: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/wgt/' },
          { expand: true, cwd: '.', src: ['icon_128.png'], dest: 'build/wgt/' }
        ]
      },

      wgt_config: {
        files: [
          { expand: true, cwd: 'platforms/tizen-wgt/', src: ['config.xml'], dest: 'build/wgt/' }
        ],
        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }
      },

      crx: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/crx/' }
        ]
      },

      crx_manifest:
      {
        files: [
          { expand: true, cwd: 'platforms/chrome-crx/', src: ['manifest.json'], dest: 'build/crx/' }
        ],

        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }

      },

      xpk: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/xpk/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/xpk/' }
        ]
      },

      xpk_manifest:
      {
        files: [
          { expand: true, cwd: 'platforms/tizen-xpk/', src: ['manifest.json'], dest: 'build/xpk/' }
        ],

        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }

      },

      sdk: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['js/**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['css/**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['*.html'], dest: 'build/sdk/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/sdk/' }
        ]
      },

      sdk_platform:
      {
        files: [
          { expand: true, cwd: 'platforms/tizen-sdk/', src: ['.project'], dest: 'build/sdk/' },
          { expand: true, cwd: 'platforms/tizen-wgt/', src: ['config.xml'], dest: 'build/sdk/' }
        ],

        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }

      },

    },

    htmlmin: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: ['app/*.html'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/html/*.html'], dest: 'build/' }
        ],
        options: {
          removeComments: true,
          collapseWhitespace: true,
          removeCommentsFromCDATA: false,
          removeCDATASectionsFromCDATA: false,
          removeEmptyAttributes: true,
          removeEmptyElements: false
        }
      }
    },

    imagemin: {
      dist: {
        options: {
          optimizationLevel: 3,
          progressive: true
        },
        files: [
          { expand: true, cwd: '.', src: ['app/images/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/css/images/**'], dest: 'build/' }
        ]
      }
    },

    // make wgt package in build/ directory
    package: {
      wgt: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/wgt/**',
        stripPrefix: 'build/wgt/',
        outDir: 'build',
        suffix: '.wgt',
        addGitCommitId: false
      },
      sdk: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/sdk/**',
        stripPrefix: 'build/sdk/',
        outDir: 'build',
        suffix: '.zip'
      }
    },

    simple_server: {
      port: 30303,
      dir: 'build/app/'
    },

    tizen: {
      push: {
        action: 'push',
        localFiles: {
          pattern: 'build/*.wgt',
          filter: 'latest'
        },
        remoteDir: '/home/developer/'
      },

      install: {
        action: 'install',
        remoteFiles: {
          pattern: '/home/developer/<%= packageInfo.name %>*.wgt',
          filter: 'latest'
        }
      },

      uninstall: {
        action: 'uninstall'
      },

      start: {
        action: 'start',
        stopOnFailure: true
      },

      stop: {
        action: 'stop',
        stopOnFailure: false
      },

      debug: {
        action: 'debug',
        browserCmd: 'google-chrome %URL%',
        localPort: 9090,
        stopOnFailure: true
      }
    }
  });

  grunt.registerTask('dist', [
    'clean',
    'imagemin:dist',
    'uglify:dist',
    'cssmin:dist',
    'htmlmin:dist',
    'copy:common'
  ]);

  grunt.registerTask('crx', ['dist', 'copy:crx', 'copy:crx_manifest']);
  grunt.registerTask('wgt', ['dist', 'copy:wgt', 'copy:wgt_config', 'package:wgt']);
  grunt.registerTask('xpk', ['dist', 'copy:xpk', 'copy:xpk_manifest']);
  grunt.registerTask('sdk', [
    'clean',
    'imagemin:dist',
    'copy:common',
    'copy:sdk',
    'copy:sdk_platform',
    'package:sdk'
  ]);

  grunt.registerTask('perf', [
    'dist',
    'uglify:perf',
    'inline',
    'copy:wgt',
    'copy:wgt_config',
    'package:wgt'
  ]);

  grunt.registerTask('install', [
    'tizen:push',
    'tizen:stop',
    'tizen:uninstall',
    'tizen:install',
    'tizen:start'
  ]);

  grunt.registerTask('wait', function () {
    var done = this.async();
    setTimeout(function () {
      done();
    }, 10000);
  });

  grunt.registerTask('restart', ['tizen:stop', 'tizen:start']);

  grunt.registerTask('server', ['dist', 'simple_server']);

  grunt.registerTask('wgt-install', ['wgt', 'install']);
  grunt.registerTask('sdk-install', ['sdk', 'install']);

  grunt.registerTask('default', 'wgt');
};
<commit_msg>Added crx_unpacked grunt target<commit_after>module.exports = function (grunt) {

  grunt.loadNpmTasks('grunt-tizen');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-release');
  grunt.loadTasks('tools/grunt-tasks');

  grunt.initConfig({
    packageInfo: grunt.file.readJSON('package.json'),
    chromeInfo: grunt.file.readJSON('platforms/chrome-crx/manifest.json'),

    clean: ['build'],

    release: {
      options: {
        npm: false,
        npmtag: false,
        tagName: 'v<%= version %>'
      }
    },

    tizen_configuration: {
      // location on the device to install the tizen-app.sh script to
      // (default: '/tmp')
      tizenAppScriptDir: '/home/developer/',

      // path to the config.xml file for the Tizen wgt file - post templating
      // (default: 'config.xml')
      configFile: 'build/wgt/config.xml',

      // path to the sdb command (default: process.env.SDB or 'sdb')
      sdbCmd: 'sdb'
    },

    // minify JS
    uglify: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: 'app/js/**/*.js', dest: 'build/' }
        ]
      }
    },

    // minify CSS
    cssmin: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: ['app/css/**/*.css'], dest: 'build/' }
        ]
      }
    },

    copy: {
      common: {
        files: [
          { expand: true, cwd: '.', src: ['app/lib/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/audio/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/data/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['LICENSE'], dest: 'build/app/' },
          { expand: true, cwd: '.', src: ['app/README.txt'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/_locales/**'], dest: 'build/' }
        ]
      },

      wgt: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/wgt/' },
          { expand: true, cwd: '.', src: ['icon_128.png'], dest: 'build/wgt/' }
        ]
      },

      wgt_config: {
        files: [
          { expand: true, cwd: 'platforms/tizen-wgt/', src: ['config.xml'], dest: 'build/wgt/' }
        ],
        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }
      },

      crx: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/crx/' }
        ]
      },

      crx_unpacked: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/crx/' },
          { expand: true, cwd: 'app/', src: ['js/**'], dest: 'build/crx/' },
          { expand: true, cwd: 'app/', src: ['css/**'], dest: 'build/crx/' },
          { expand: true, cwd: 'app/', src: ['*.html'], dest: 'build/crx/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/crx/' }
        ]
      },

      crx_manifest:
      {
        files: [
          { expand: true, cwd: 'platforms/chrome-crx/', src: ['manifest.json'], dest: 'build/crx/' }
        ],

        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }

      },

      xpk: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/xpk/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/xpk/' }
        ]
      },

      xpk_manifest:
      {
        files: [
          { expand: true, cwd: 'platforms/tizen-xpk/', src: ['manifest.json'], dest: 'build/xpk/' }
        ],

        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }

      },

      sdk: {
        files: [
          { expand: true, cwd: 'build/app/', src: ['**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['js/**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['css/**'], dest: 'build/sdk/' },
          { expand: true, cwd: 'app/', src: ['*.html'], dest: 'build/sdk/' },
          { expand: true, cwd: '.', src: ['icon*.png'], dest: 'build/sdk/' }
        ]
      },

      sdk_platform:
      {
        files: [
          { expand: true, cwd: 'platforms/tizen-sdk/', src: ['.project'], dest: 'build/sdk/' },
          { expand: true, cwd: 'platforms/tizen-wgt/', src: ['config.xml'], dest: 'build/sdk/' }
        ],

        options:
        {
          processContent: function(content, srcpath)
          {
            return grunt.template.process(content);
          }
        }

      },

    },

    htmlmin: {
      dist: {
        files: [
          { expand: true, cwd: '.', src: ['app/*.html'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/html/*.html'], dest: 'build/' }
        ],
        options: {
          removeComments: true,
          collapseWhitespace: true,
          removeCommentsFromCDATA: false,
          removeCDATASectionsFromCDATA: false,
          removeEmptyAttributes: true,
          removeEmptyElements: false
        }
      }
    },

    imagemin: {
      dist: {
        options: {
          optimizationLevel: 3,
          progressive: true
        },
        files: [
          { expand: true, cwd: '.', src: ['app/images/**'], dest: 'build/' },
          { expand: true, cwd: '.', src: ['app/css/images/**'], dest: 'build/' }
        ]
      }
    },

    // make wgt package in build/ directory
    package: {
      wgt: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/wgt/**',
        stripPrefix: 'build/wgt/',
        outDir: 'build',
        suffix: '.wgt',
        addGitCommitId: false
      },
      sdk: {
        appName: '<%= packageInfo.name %>',
        version: '<%= packageInfo.version %>',
        files: 'build/sdk/**',
        stripPrefix: 'build/sdk/',
        outDir: 'build',
        suffix: '.zip'
      },
      'crx_zip': {
        appName: '<%= packageInfo.name %>-crx',
        version: '<%= packageInfo.version %>',
        files: 'build/crx/**',
        stripPrefix: 'build/crx/',
        outDir: 'build',
        suffix: '.zip'
      }
    },

    simple_server: {
      port: 30303,
      dir: 'build/app/'
    },

    tizen: {
      push: {
        action: 'push',
        localFiles: {
          pattern: 'build/*.wgt',
          filter: 'latest'
        },
        remoteDir: '/home/developer/'
      },

      install: {
        action: 'install',
        remoteFiles: {
          pattern: '/home/developer/<%= packageInfo.name %>*.wgt',
          filter: 'latest'
        }
      },

      uninstall: {
        action: 'uninstall'
      },

      start: {
        action: 'start',
        stopOnFailure: true
      },

      stop: {
        action: 'stop',
        stopOnFailure: false
      },

      debug: {
        action: 'debug',
        browserCmd: 'google-chrome %URL%',
        localPort: 9090,
        stopOnFailure: true
      }
    }
  });

  grunt.registerTask('dist', [
    'clean',
    'imagemin:dist',
    'uglify:dist',
    'cssmin:dist',
    'htmlmin:dist',
    'copy:common'
  ]);

  grunt.registerTask('crx', ['dist', 'copy:crx', 'copy:crx_manifest']);
  grunt.registerTask('crx_unpacked', [
    'clean',
    'imagemin:dist',
    'copy:common',
    'copy:crx_unpacked',
    'copy:crx_manifest',
    'package:crx_zip'
  ]);
  grunt.registerTask('wgt', ['dist', 'copy:wgt', 'copy:wgt_config', 'package:wgt']);
  grunt.registerTask('xpk', ['dist', 'copy:xpk', 'copy:xpk_manifest']);
  grunt.registerTask('sdk', [
    'clean',
    'imagemin:dist',
    'copy:common',
    'copy:sdk',
    'copy:sdk_platform',
    'package:sdk'
  ]);

  grunt.registerTask('perf', [
    'dist',
    'uglify:perf',
    'inline',
    'copy:wgt',
    'copy:wgt_config',
    'package:wgt'
  ]);

  grunt.registerTask('install', [
    'tizen:push',
    'tizen:stop',
    'tizen:uninstall',
    'tizen:install',
    'tizen:start'
  ]);

  grunt.registerTask('wait', function () {
    var done = this.async();
    setTimeout(function () {
      done();
    }, 10000);
  });

  grunt.registerTask('restart', ['tizen:stop', 'tizen:start']);

  grunt.registerTask('server', ['dist', 'simple_server']);

  grunt.registerTask('wgt-install', ['wgt', 'install']);
  grunt.registerTask('sdk-install', ['sdk', 'install']);

  grunt.registerTask('default', 'wgt');
};
<|endoftext|>


<commit_before>/*!
 * FastGap's Gruntfile
 * http://fastgap.mobi/
 * Licensed under MIT
 */

var buildConfig = require('./config/build');

module.exports = function (grunt) {
  "use strict";

  var appConfig = {

    // Default Paths
    paths: {
      src: 'src',
      dist: 'dist',
      bower: 'bower_components'
    },

    // Assets directory
    dirs: {
      sass: "<%= paths.src %>/assets/scss",
      css: "<%= paths.src %>/assets/css",
      img: "<%= paths.src %>/assets/images",
      vendor: "<%= paths.src %>/vendor",
      pages: "<%= paths.src %>/pages",
      fonts: "<%= paths.src %>/vendor/topcoat/font"
    },

    // Load package.json
    pkg: grunt.file.readJSON("package.json"),

    // Banner
    banner: '/*!\n' +
            " * FastGap v<%= pkg.version %> (<%= pkg.homepage %>)\n" +
            " * Author: <%= pkg.author %>\n" +
            " * Maintainers: <%= pkg.maintainers %>\n" +
            " * Copyright (c) <%= grunt.template.today(\"yyyy\") %>\n" +
            ' * Licensed under <%= pkg.licenses.type %>\n' +
            ' */\n',

    // Watch files
    watch: {
      options: {
        livereload: true
      },
      css: {
        files: ["<%= dirs.sass %>/{,*/}*.{scss,sass}"],
        tasks: ["compass", "notify:compass"]
      },
      js: {
        files: ["<%= jshint.all %>"],
        tasks: ["jshint", "uglify", "notify:js"]
      },
      html: {
        files: [
          // carregamento automático do browser para as atualizações das extensões abaixo
          "/*.{html,htm,shtml,shtm,xhtml,php,jsp,asp,aspx,erb,ctp}"
        ]
      }
    },

    // Files Validation
    jshint: {
      options: {
          jshintrc: ".jshintrc"
      },
      all: [
          "Gruntfile.js",
          "<%= dirs.js %>/main.js"
      ]
    },

    /************************************
     * grunt-contrib-concat
     * Concatenate files
     ************************************/
    concat: {
      fastgapControllers: {
        src: [
          // Main
          '<%= paths.src %>/js/controllers/AppController.js',
          '<%= paths.src %>/js/controllers/HomeController.js',
          // Custom
          '<%= paths.src %>/js/controllers/Page1Controller.js',
          '<%= paths.src %>/js/controllers/Page2Controller.js',
          '<%= paths.src %>/js/controllers/Page3Controller.js',
          '<%= paths.src %>/js/controllers/Page4Controller.js',
          '<%= paths.src %>/js/controllers/Page5Controller.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.controllers.js'
      },
      librariesJs: {
        src: [
          // Main
          '<%= paths.bower %>/zepto/zepto.js',
          '<%= paths.bower %>/fastclick/lib/fastclick.js',
          // Scroll
          '<%= paths.bower %>/overthrow-dist/overthrow.js',
          // Snap.js (menu)
          '<%= paths.bower %>/snapjs/snapjs.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.libs.js'
      },
      fastgapCore: {
        src: [
          // Main
          '<%= paths.src %>/js/History.js',
          '<%= paths.src %>/js/FG.js',
          '<%= paths.src %>/js/Navigator.js',
          '<%= paths.src %>/js/Transition.js',
          '<%= paths.src %>/js/PageLoad.js',
          '<%= paths.src %>/js/index.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.core.js'
      },
      fastgap: {
        src: [
          '<%= paths.dist %>/js/fastgap.controllers.js',
          '<%= paths.dist %>/js/fastgap.libs.js',
          '<%= paths.dist %>/js/fastgap.core.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.js'
      }
    },

    // Minification
    uglify: {
      options: {
        mangle: false,
        banner: "<%= banner %>"
      }
          // ,
          // dist: {
          //     files: {
          //         "<%= dirs.js %>/main.min.js": [
          //         "<%= dirs.js %>/main.js"
          //         ]
          //     }
          // }
    },

      // Compass for SCSS
      /*compass: {
      dist: {
          options: {
              force: true,
              sassDir: "<%= dirs.sass %>",
              cssDir: "<%= dirs.css %>",
              banner: "<%= banner %>",
              specify: "<%= dirs.sass %>/*.scss"
          }
      }
  },*/

    // Notificações
    notify: {
      compass: {
        options: {
          title: "SASS - <%= pkg.title %>",
          message: "Build with success!"
        }
      },
      js: {
        options: {
          title: "Javascript - <%= pkg.title %>",
          message: "Minified and validated with success!"
        }
      }
    },

    copy: {
      /* COPY FONTS FOLDER */
      distFonts: {
        files: [{
          expand: true,
          cwd: '<%= paths.bower %>/topcoat/font',
          src: '*.otf',
          dest: '<%= paths.dist %>/fonts'
        }]
      },
      distHtml: {
        files: [{
          expand: true,
          cwd: "<%= paths.src %>/",
          src: buildConfig.htmlFiles,
          dest: "<%= paths.dist %>/"
        }]
      },
      distCss: {
        files: [{
          expand: true,
          cwd: "<%= dirs.css %>/",
          src: buildConfig.cssFiles,
          dest: "<%= paths.dist %>/assets/css"
        }]
      },
      distJs: {
        files: [{
          expand: true,
          cwd: "<%= dirs.js %>/",
          src: buildConfig.jsFiles,
          dest: "<%= paths.dist %>/assets/js"
        }]
      },
      distImages: {
        files: [{
          expand: true,
          cwd: "<%= dirs.img %>/",
          src: "**",
          dest: "<%= paths.dist %>/assets/images"
        }]
      },
      distPages: {
        files: [{
          expand: true,
          cwd: "<%= dirs.pages %>/",
          src: "**",
          dest: "<%= paths.dist %>/pages"
      }]
      }
    },

    /************************************
     * grunt-banner
     * Adds a simple banner to files
     ************************************/
    usebanner: {
      options: {
        position: 'top',
        banner: '<%= banner %>'
      },
      files: {
        src: '<%= paths.dist %>/{css,js}/{*.css,*.js}'
      }
    },

    /************************************
     * grunt-bump
     * Bump package version, create tag, commit, push...
     ************************************/
    bump: {
      options: {
        files: ['package.json', 'bower.json'],
        updateConfigs: [],
        commit: true,
        commitMessage: '%VERSION%',
        commitFiles: ['package.json', 'bower.json', 'dist/'], // '-a' for all files
        createTag: true,
        tagName: '%VERSION%',
        tagMessage: '%VERSION%',
        push: true,
        pushTo: 'master',
        gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d' // options to use with '$ git describe'
      }
    }

  };

  // Init grunt configurations
  grunt.initConfig(appConfig);

  // Tasks
  // --------------------------

  // load all grunt tasks matching the `grunt-*` pattern
  require('load-grunt-tasks')(grunt);

  // Dist JS
  grunt.registerTask('dist-js', ['concat']);

  // Watch Task
  grunt.registerTask('w', ['watch']);

  // Default task
  grunt.registerTask('dist', ['copy']);
  grunt.registerTask('build', ['dist']);
  grunt.registerTask('default', ['dist']);

};
<commit_msg>Update Gruntfile.js<commit_after>/*!
 * FastGap's Gruntfile
 * http://fastgap.mobi/
 * Licensed under MIT
 */

var buildConfig = require('./config/build');

module.exports = function (grunt) {
  "use strict";

  var appConfig = {

    // Default Paths
    paths: {
      src: 'src',
      dist: 'dist',
      bower: 'bower_components'
    },

    // Assets directory
    dirs: {
      sass: "<%= paths.src %>/assets/scss",
      css: "<%= paths.src %>/assets/css",
      img: "<%= paths.src %>/assets/images",
      vendor: "<%= paths.src %>/vendor",
      pages: "<%= paths.src %>/pages",
      fonts: "<%= paths.src %>/vendor/topcoat/font"
    },

    // Load package.json
    pkg: grunt.file.readJSON("package.json"),

    // Banner
    banner: '/*!\n' +
            " * FastGap v<%= pkg.version %> (<%= pkg.homepage %>)\n" +
            " * Author: <%= pkg.author %>\n" +
            " * Maintainers: <%= pkg.maintainers %>\n" +
            " * Copyright (c) <%= grunt.template.today(\"yyyy\") %>\n" +
            ' * Licensed under <%= pkg.licenses.type %>\n' +
            ' */\n',

    // Watch files
    watch: {
      options: {
        livereload: true
      },
      css: {
        files: ["<%= dirs.sass %>/{,*/}*.{scss,sass}"],
        tasks: ["compass", "notify:compass"]
      },
      js: {
        files: ["<%= jshint.all %>"],
        tasks: ["jshint", "uglify", "notify:js"]
      },
      html: {
        files: [
          // carregamento automático do browser para as atualizações das extensões abaixo
          "/*.{html,htm,shtml,shtm,xhtml,php,jsp,asp,aspx,erb,ctp}"
        ]
      }
    },

    // Files Validation
    jshint: {
      options: {
          jshintrc: ".jshintrc"
      },
      all: [
          "Gruntfile.js",
          "<%= dirs.js %>/main.js"
      ]
    },

    /************************************
     * grunt-contrib-concat
     * Concatenate files
     ************************************/
    concat: {
      fastgapControllers: {
        src: [
          // Main
          '<%= paths.src %>/js/controllers/AppController.js',
          '<%= paths.src %>/js/controllers/HomeController.js',
          // Custom
          '<%= paths.src %>/js/controllers/Page1Controller.js',
          '<%= paths.src %>/js/controllers/Page2Controller.js',
          '<%= paths.src %>/js/controllers/Page3Controller.js',
          '<%= paths.src %>/js/controllers/Page4Controller.js',
          '<%= paths.src %>/js/controllers/Page5Controller.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.controllers.js'
      },
      librariesJs: {
        src: [
          // Main
          '<%= paths.bower %>/zepto/zepto.js',
          '<%= paths.bower %>/fastclick/lib/fastclick.js',
          // Scroll
          '<%= paths.bower %>/overthrow-dist/overthrow.js',
          // Snap.js (menu)
          '<%= paths.bower %>/snapjs/snapjs.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.libs.js'
      },
      fastgapCore: {
        src: [
          // Main
          '<%= paths.src %>/js/History.js',
          '<%= paths.src %>/js/FG.js',
          '<%= paths.src %>/js/Navigator.js',
          '<%= paths.src %>/js/Transition.js',
          '<%= paths.src %>/js/PageLoad.js',
          '<%= paths.src %>/js/index.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.core.js'
      },
      fastgap: {
        src: [
          '<%= paths.dist %>/js/fastgap.controllers.js',
          '<%= paths.dist %>/js/fastgap.libs.js',
          '<%= paths.dist %>/js/fastgap.core.js'
        ],
        dest: '<%= paths.dist %>/js/fastgap.js'
      }
    },

    // Minification
    uglify: {
      options: {
        mangle: false,
        banner: "<%= banner %>"
      }
          // ,
          // dist: {
          //     files: {
          //         "<%= dirs.js %>/main.min.js": [
          //         "<%= dirs.js %>/main.js"
          //         ]
          //     }
          // }
    },

      // Compass for SCSS
      /*compass: {
      dist: {
          options: {
              force: true,
              sassDir: "<%= dirs.sass %>",
              cssDir: "<%= dirs.css %>",
              banner: "<%= banner %>",
              specify: "<%= dirs.sass %>/*.scss"
          }
      }
  },*/

    // Notificações
    notify: {
      compass: {
        options: {
          title: "SASS - <%= pkg.title %>",
          message: "Build with success!"
        }
      },
      js: {
        options: {
          title: "Javascript - <%= pkg.title %>",
          message: "Minified and validated with success!"
        }
      }
    },

    copy: {
      /* COPY FONTS FOLDER */
      distFonts: {
        files: [{
          expand: true,
          cwd: '<%= paths.bower %>/topcoat/font',
          src: '*.otf',
          dest: '<%= paths.dist %>/fonts'
        }]
      },
      distCss: {
        files: [{
          expand: true,
          cwd: "<%= dirs.css %>/",
          src: buildConfig.cssFiles,
          dest: "<%= paths.dist %>/assets/css"
        }]
      },
      distJs: {
        files: [{
          expand: true,
          cwd: "<%= dirs.js %>/",
          src: buildConfig.jsFiles,
          dest: "<%= paths.dist %>/assets/js"
        }]
      },
      distImages: {
        files: [{
          expand: true,
          cwd: "<%= dirs.img %>/",
          src: "**",
          dest: "<%= paths.dist %>/assets/images"
        }]
      },
      distPages: {
        files: [{
          expand: true,
          cwd: "<%= dirs.pages %>/",
          src: "**",
          dest: "<%= paths.dist %>/pages"
      }]
      }
    },

    /************************************
     * grunt-banner
     * Adds a simple banner to files
     ************************************/
    usebanner: {
      options: {
        position: 'top',
        banner: '<%= banner %>'
      },
      files: {
        src: '<%= paths.dist %>/{css,js}/{*.css,*.js}'
      }
    },

    /************************************
     * grunt-bump
     * Bump package version, create tag, commit, push...
     ************************************/
    bump: {
      options: {
        files: ['package.json', 'bower.json'],
        updateConfigs: [],
        commit: true,
        commitMessage: '%VERSION%',
        commitFiles: ['package.json', 'bower.json', 'dist/'], // '-a' for all files
        createTag: true,
        tagName: '%VERSION%',
        tagMessage: '%VERSION%',
        push: true,
        pushTo: 'master',
        gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d' // options to use with '$ git describe'
      }
    }

  };

  // Init grunt configurations
  grunt.initConfig(appConfig);

  // Tasks
  // --------------------------

  // load all grunt tasks matching the `grunt-*` pattern
  require('load-grunt-tasks')(grunt);

  // Dist JS
  grunt.registerTask('dist-js', ['concat']);

  // Watch Task
  grunt.registerTask('w', ['watch']);

  // Default task
  grunt.registerTask('dist', ['copy']);
  grunt.registerTask('build', ['dist']);
  grunt.registerTask('default', ['dist']);

};
<|endoftext|>