Last active
July 28, 2017 15:18
-
-
Save adautoneto/f906327fad9cf58f7e86051ff1e9e5ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
module.exports = function(grunt){ | |
directories = ['src/Venus.Web/Views', 'src/Venus.Admin.Web/Views']; | |
files_extensions = ['cshtml']; | |
//I get that function from https://gist.github.com/kethinov/6658166 | |
function getFileList(dir, fileList = []){ | |
fs.readdirSync(dir).forEach(file => { | |
const filePath = path.join(dir, file) | |
fileList.push( | |
fs.statSync(filePath).isDirectory() ? {[file]: getFileList(filePath)} | |
: file | |
) | |
}) | |
return fileList | |
} | |
function fileJsonToPath(fileObject){ | |
if(typeof fileObject == 'string') { | |
return fileObject; | |
} | |
var keys = Object.keys(fileObject); | |
results = [] | |
for(var i in keys){ | |
var key = keys[i]; | |
for(var j in fileObject[key]) | |
results.push(key + '\\' + fileJsonToPath(fileObject[key][j])); | |
} | |
return results; | |
} | |
function getFilesPaths(){ | |
var fileList = []; | |
for(i in directories){ | |
fileList.concat(getFileList(directories[i])); | |
} | |
files = [] | |
for(var i in fileList){ | |
var result = fileJsonToPath(fileList[i]); | |
files = files.concat(result); | |
} | |
return files; | |
} | |
function getFilesPathsByExtension(extensionFilter){ | |
return getFilesPaths().filter((item) => item.endsWith(extensionFilter)); | |
} | |
grunt.log.write('Checking if frontend files are in Venus.Web and Venus.Admin.Web'); | |
fs.readFile('src/Venus.Web/Venus.Web.csproj', 'utf8', function(err, csproj){ | |
if(err){ | |
return grunt.log.error(err); | |
} | |
var cshtmlFiles = getFilesPathsByExtension('cshtml'); | |
var fileMissing = false; | |
for(var i in cshtmlFiles){ | |
debugger; | |
if(!csproj.includes(cshtmlFiles[i])){ | |
fileMissing = true; | |
grunt.log.error('File ' + cshtmlFiles[i] + ' was not added to Venus.Web.csproj'); | |
} | |
} | |
if(!fileMissing){ | |
grunt.log.ok('All cshtml was added to csproj'); | |
} | |
else{ | |
grunt.fatal('Add all cshtml files to project or remove unused chstml files.'); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerTask('check_frontend_files', function () { | |
require('./tasks/check_frontend_files.js')(grunt); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment