Node: Find all classnames / attributes in C# files

Date: 2020-02-11
const findInFiles = require('find-in-files');
const folder = "C:\\workspace\\"

//const term = "public class\\s+([^\\s]*)";
const term = "\\s(\\[[^:]+?\\])\\s";
const flags = 'ig';

let classes = [];

findInFiles.find({'term': term, 'flags': flags}, folder, '.cs$')
    .then(function(results) {
		for (const [_, res] of Object.entries(results)) {
			for (const match of res.matches) {
				const regEx = new RegExp(term, flags);
				const m = regEx.exec(match);
				if (m) {
					classes.push(m[1])
				} else {
					console.error("Fail: ", match);
				}
			}
        }
		const set = new Set(classes);
		const array = Array.from(set)
		array.sort();
		for(const item of array)
		{
			console.log(item);
		}
    });
33930cookie-checkNode: Find all classnames / attributes in C# files