<commit_before>/*
*	Code takes care of static analysis and generates "out_parsed_typescript.txt"
*	The output file consists of information about custom and common bindings that should be generated.
* 	
*	test command:
*		node transpiled_ts_parser.js "input\dir\path" "output\file\path" "interface\names\file\path"
*		node transpiled_ts_parser.js "D:\work\android-static-binding-generator\project\input_parced_typescript" "D:\work\android-static-binding-generator\project\out\out_parsed_typescript.txt" "D:\work\android-static-binding-generator\project\interface-name-generator\interfaces-names.txt"
*/

///////////////// CONFIGURATION /////////////////

var disableLogger = true;
if (process.env.AST_PARSER_DISABLE_LOGGING && process.env.AST_PARSER_DISABLE_LOGGING.trim() === "true") {
	disableLogger = true;
}

loggingSettings = {
	"logPath": require("path").dirname(require.main.filename) + "/logs/i.txt",
	"strategy": "console",
	"APP_NAME": "ast_parser",
	"disable": disableLogger
};

var fs = require("fs"),
	babelParser = require("babylon"),
	traverse = require("babel-traverse"),
	logger = require('./helpers/logger')(loggingSettings),
	fileHelpers = require("./helpers/file_helpers")({ logger: logger }),
	path = require("path"),
	stringify = require("./helpers/json_extension"),
	es5_visitors = require("./visitors/es5-visitors"),
	t = require("babel-types"),
	lazy = require("lazy"),
	eol = require('os').EOL,

	arguments = process.argv,
	appDir = path.dirname(require.main.filename),
	extendDecoratorName = "JavaProxy",
	outFile = "out/out_parsed_typescript.txt", // default out file
	inputDir = "input_parced_typescript", // default input folder
	interfacesNamesFilePath = "../interfaces-names.txt", //default interace_names file path
	interfaceNames = [];


//env variables
if (process.env.AST_PARSER_OUT_FILE) {
	outFile = process.env.AST_PARSER_OUT_FILE.trim();
}
if (process.env.AST_PARSER_INPUT_DIR) {
	inputDir = process.env.AST_PARSER_INPUT_DIR.trim();
}
if (process.env.AST_PARSER_INTERFACE_FILE_PATH) {
	interfacesNamesFilePath = process.env.AST_PARSER_INTERFACE_FILE_PATH.trim();
}


//console variables have priority
if (arguments && arguments.length >= 3) {
	inputDir = arguments[2]
	console.log("inputDir: " + inputDir)
}
if (arguments && arguments.length >= 4) {
	outFile = arguments[3]
	console.log("outFile: " + outFile)
}
if (arguments && arguments.length >= 5) {
	interfacesNamesFilePath = arguments[4]
	console.log("interface names path: " + interfacesNamesFilePath)
}

/////////////// PREPARATION ////////////////
fileHelpers.createFile(outFile)

/////////////// EXECUTE ////////////////

/*
*	Traverses a given input directory and attempts to visit every ".js" file.
*	It passes each found file down the line.
*/
var traverseAndAnalyseFilesDir = function (filesDir) {
	if (!fs.existsSync(filesDir)) {
		throw "The input dir: " + filesDir + " does not exist!";
	}

	traverseDirectory(filesDir);
}

function traverseDirectory(dir) {
	// list all files in directory

    fs.readdir(dir, function (err, files) {
		var pJsonFile;

		if (dir !== inputDir) {
			for (var i = 0; i < files.length; i++) {
				if (files[i] === "package.json") {
					pJsonFile = true;
					break;
				}
			}

			if (pJsonFile) {
				var fullPJsonPath = path.join(dir, "package.json");
				var pjson = require(fullPJsonPath);
				if (!pjson.nativescript) {
					// if (pjson.nativescript.sbgShouldNotVisit && pjson.nativescript.platforms) {
					// 	return;
					// }
					return;
				}
			}
		}

        for (var i = 0; i < files.length; i += 1) {
            var file = path.join(dir, files[i]);

			if (file.substring(file.length - 3, file.length) === '.js') {
				logger.info("Visiting JavaScript file: " + file);
<commit_msg>optimise static binding generator<commit_after>/*
*	Code takes care of static analysis and generates "out_parsed_typescript.txt"
*	The output file consists of information about custom and common bindings that should be generated.
* 	
*	test command:
*		node transpiled_ts_parser.js "input\dir\path" "output\file\path" "interface\names\file\path"
*		node transpiled_ts_parser.js "D:\work\android-static-binding-generator\project\input_parced_typescript" "D:\work\android-static-binding-generator\project\out\out_parsed_typescript.txt" "D:\work\android-static-binding-generator\project\interface-name-generator\interfaces-names.txt"
*/

///////////////// CONFIGURATION /////////////////

var disableLogger = true;
if (process.env.AST_PARSER_DISABLE_LOGGING && process.env.AST_PARSER_DISABLE_LOGGING.trim() === "true") {
	disableLogger = true;
}

loggingSettings = {
	"logPath": require("path").dirname(require.main.filename) + "/logs/i.txt",
	"strategy": "console",
	"APP_NAME": "ast_parser",
	"disable": disableLogger
};

var fs = require("fs"),
	babelParser = require("babylon"),
	traverse = require("babel-traverse"),
	logger = require('./helpers/logger')(loggingSettings),
	fileHelpers = require("./helpers/file_helpers")({ logger: logger }),
	path = require("path"),
	stringify = require("./helpers/json_extension"),
	es5_visitors = require("./visitors/es5-visitors"),
	t = require("babel-types"),
	lazy = require("lazy"),
	eol = require('os').EOL,

	arguments = process.argv,
	appDir = path.dirname(require.main.filename),
	extendDecoratorName = "JavaProxy",
	outFile = "out/out_parsed_typescript.txt", // default out file
	inputDir = "input_parced_typescript", // default input folder
	interfacesNamesFilePath = "../interfaces-names.txt", //default interace_names file path
	interfaceNames = [],
	rootTraversed = false;


//env variables
if (process.env.AST_PARSER_OUT_FILE) {
	outFile = process.env.AST_PARSER_OUT_FILE.trim();
}
if (process.env.AST_PARSER_INPUT_DIR) {
	inputDir = process.env.AST_PARSER_INPUT_DIR.trim();
}
if (process.env.AST_PARSER_INTERFACE_FILE_PATH) {
	interfacesNamesFilePath = process.env.AST_PARSER_INTERFACE_FILE_PATH.trim();
}


//console variables have priority
if (arguments && arguments.length >= 3) {
	inputDir = arguments[2]
	console.log("inputDir: " + inputDir)
}
if (arguments && arguments.length >= 4) {
	outFile = arguments[3]
	console.log("outFile: " + outFile)
}
if (arguments && arguments.length >= 5) {
	interfacesNamesFilePath = arguments[4]
	console.log("interface names path: " + interfacesNamesFilePath)
}

/////////////// PREPARATION ////////////////
fileHelpers.createFile(outFile)

/////////////// EXECUTE ////////////////

/*
*	Traverses a given input directory and attempts to visit every ".js" file.
*	It passes each found file down the line.
*/
var traverseAndAnalyseFilesDir = function (filesDir) {
	if (!fs.existsSync(filesDir)) {
		throw "The input dir: " + filesDir + " does not exist!";
	}

	traverseDirectory(filesDir);
}

function traverseDirectory(dir) {
	// list all files in directory

    fs.readdir(dir, function (err, files) {
		var pJsonFile;

		if (rootTraversed || dir !== inputDir) {
			for (var i = 0; i < files.length; i++) {
				if (files[i] === "package.json") {
					pJsonFile = true;
					break;
				}
			}

			if (pJsonFile) {
				var fullPJsonPath = path.join(dir, "package.json");
				var pjson = require(fullPJsonPath);
				if (!pjson.nativescript) {
					// if (pjson.nativescript.sbgShouldNotVisit && pjson.nativescript.platforms) {
					// 	return;
					// }
					return;
				}
			}
		} else {
			rootTraversed = true;
		}

        for (var i = 0; i < files.length; i += 1) {
            var file = path.join(dir, files[i]);

			if (file.substring(file.length - 3, file.length) === '.js') {
				logger.info("Visiting JavaScript file: " + file);

{'fraction_non_alphanumeric': 0.16651248843663274, 'fraction_numerical': 0.0031716664464120524, 'mean_word_length': 3.7868437697659707, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5941237', 'n_tokens_mistral': 2626, 'n_tokens_neox': 2489, 'n_words': 515}