From a1648737bdd550ecc95f047af6d5fc5f4136a197 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 17 Dec 2015 22:01:39 +0000 Subject: [PATCH] chore(GruntFile): move `validate-angular-files` task into its own file Closes #13569 --- Gruntfile.js | 50 ------------------------- lib/grunt/validate-angular-files.js | 58 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 50 deletions(-) create mode 100644 lib/grunt/validate-angular-files.js diff --git a/Gruntfile.js b/Gruntfile.js index 82d5b224b..e8f18bf50 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,9 +4,7 @@ var files = require('./angularFiles').files; var util = require('./lib/grunt/utils.js'); var versionInfo = require('./lib/versions/version-info'); var path = require('path'); -var fs = require('fs'); var e2e = require('./test/e2e/tools'); -var glob = require("glob"); module.exports = function(grunt) { //grunt plugins @@ -341,55 +339,7 @@ module.exports = function(grunt) { grunt.task.run('shell:npm-install'); } - grunt.registerTask('validate-angular-files', function() { - var combinedFiles = Object.assign({}, files.angularModules); - combinedFiles.ng = files.angularSrc; - combinedFiles.angularLoader = files.angularLoader; - var errorsDetected = false; - var directories = []; - var detectedFiles = { - "src/ng/rootElement.js": true - }; - - for (var section in combinedFiles) { - var sectionFiles = combinedFiles[section]; - - if (section != "angularLoader") { - directories.push("src/" + section); - } - - console.log("Validating " + sectionFiles.length + " files from the \"" + section + "\" module"); - - sectionFiles.forEach(function(file) { - detectedFiles[file] = true; - - if (!fs.existsSync(file)) { - grunt.log.error(file + " does not exist in the local file structure"); - errorsDetected = true; - } - }); - } - - directories.forEach(function(directory) { - glob.sync(directory + "/**/*").forEach(function(filePath) { - if (!fs.lstatSync(filePath).isDirectory()) { - var fileName = path.basename(filePath); - var isHiddenFile = fileName[0] == "."; - if (!isHiddenFile && !detectedFiles[filePath]) { - grunt.log.error(filePath + " exists in the local file structure but isn't used by any module"); - errorsDetected = true; - } - } - }); - }); - - if (errorsDetected) { - throw new Error("Not all files were properly detected the local file structure"); - } else { - console.log("All files were detected successfully!"); - } - }); //alias tasks grunt.registerTask('test', 'Run unit, docs and e2e tests with Karma', ['jshint', 'jscs', 'package','test:unit','test:promises-aplus', 'tests:docs', 'test:protractor']); diff --git a/lib/grunt/validate-angular-files.js b/lib/grunt/validate-angular-files.js new file mode 100644 index 000000000..74352abcb --- /dev/null +++ b/lib/grunt/validate-angular-files.js @@ -0,0 +1,58 @@ +'use strict'; + +var path = require('path'); +var fs = require('fs'); +var glob = require("glob"); +var _ = require('lodash'); +var files = require('../../angularFiles').files; + +module.exports = function(grunt) { + + grunt.registerTask('validate-angular-files', function() { + var combinedFiles = _.clone(files.angularModules); + combinedFiles.ng = files.angularSrc; + combinedFiles.angularLoader = files.angularLoader; + + var errorsDetected = false; + var directories = []; + var detectedFiles = {}; + + for (var section in combinedFiles) { + var sectionFiles = combinedFiles[section]; + + if (section != 'angularLoader') { + directories.push('src/' + section); + } + + grunt.log.debug('Validating ' + sectionFiles.length + ' files from the "' + section + '" module.'); + + sectionFiles.forEach(function(file) { + detectedFiles[file] = true; + + if (!fs.existsSync(file)) { + grunt.log.error(file + ' does not exist in the local file structure.'); + errorsDetected = true; + } + }); + } + + directories.forEach(function(directory) { + glob.sync(directory + '/**/*').forEach(function(filePath) { + if (!fs.lstatSync(filePath).isDirectory()) { + var fileName = path.basename(filePath); + var isHiddenFile = fileName[0] == '.'; + if (!isHiddenFile && !detectedFiles[filePath]) { + grunt.log.error(filePath + ' exists in the local file structure but isn\'t used by any module.'); + errorsDetected = true; + } + } + }); + }); + + if (errorsDetected) { + throw new Error('Not all files were properly detected in the local file structure.'); + } else { + grunt.log.ok('All files were detected successfully!'); + } + }); +};