Skip to content

Commit

Permalink
chore(build): add a validation step for angularFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko authored and petebacondarwin committed Dec 17, 2015
1 parent 62f79e8 commit 0387298
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
54 changes: 53 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ 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
Expand Down Expand Up @@ -339,6 +341,56 @@ 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']);
grunt.registerTask('test:jqlite', 'Run the unit tests with Karma' , ['tests:jqlite']);
Expand All @@ -354,7 +406,7 @@ module.exports = function(grunt) {

grunt.registerTask('minify', ['bower','clean', 'build', 'minall']);
grunt.registerTask('webserver', ['connect:devserver']);
grunt.registerTask('package', ['bower','clean', 'buildall', 'minall', 'collect-errors', 'docs', 'copy', 'write', 'compress']);
grunt.registerTask('package', ['bower', 'validate-angular-files','clean', 'buildall', 'minall', 'collect-errors', 'docs', 'copy', 'write', 'compress']);
grunt.registerTask('ci-checks', ['ddescribe-iit', 'merge-conflict', 'jshint', 'jscs']);
grunt.registerTask('default', ['package']);
};
2 changes: 1 addition & 1 deletion angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var angularFiles = {
],

'angularLoader': [
'stringify.js',
'src/stringify.js',
'src/minErr.js',
'src/loader.js'
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dgeni": "^0.4.0",
"dgeni-packages": "^0.11.0",
"event-stream": "~3.1.0",
"glob": "^6.0.1",
"grunt": "~0.4.2",
"grunt-bump": "~0.0.13",
"grunt-contrib-clean": "~0.6.0",
Expand Down

0 comments on commit 0387298

Please sign in to comment.