Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(build): add a validation step for angularFiles #13553

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use lodash here for assign(), so no actual need for Node 4

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Punctuation is nice (here and in other messages) 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why console.log by grunt.log elsewhere?


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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detected the local --> detected in the local

} 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']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR, but there's a space missing before 'clean' 😁

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 @@ -85,7 +85,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