<commit_before>const fs = require('fs');
const config = require('./config');
const readFile = function(dir) {
	return new Promise((success, fail) => {
		fs.readFile(dir, (err, data) => {
			if (err) return fail(err);
			success(data.toString())
		})
	})
}
const rewriteFile = function(dir, data) {
	let option = {
		flag: 'w'
	};
	return new Promise((success, fail) => {
		fs.writeFile(dir, data, option, err => {
			if (err) return fail(err);
			console.log(`rewrite file ${dir} success`);
			success(data);
		})
	})
}

const buildFile = async function(dir) {
	try {
		let html = await readFile(dir);
		let tags = html.match(/<script [^>]*>/g);
		tags.forEach(tag => {
			if (tag.indexOf(config.dir.controller) === -1 && tag.indexOf(config.dir.util) === -1) {
				return false;
			}
			tag = tag.replace(/t=[0-9]{13}/g, '');
			let replace = tag.replace('.js', `.js?t=${Date.now()}`);
			html = html.replace(tag, replace);
		});
		await rewriteFile(dir, html);
	} catch (err) {
		console.log(err);
	}
}

const init = async function() {
	try {
		let commonDir = config.views ? config.views : '.';
		config.files.forEach(dir => {
			dir = `${commonDir}${dir}`
			buildFile(dir)
		})<commit_msg>Create app.js<commit_after>const fs = require('fs');
const config = require('./config');
const readFile = function(dir) {
	return new Promise((success, fail) => {
		fs.readFile(dir, (err, data) => {
			if (err) return fail(err);
			success(data.toString())
		})
	})
}
const rewriteFile = function(dir, data) {
	let option = {
		flag: 'w'
	};
	return new Promise((success, fail) => {
		fs.writeFile(dir, data, option, err => {
			if (err) return fail(err);
			console.log(`rewrite file ${dir} success`);
			success(data);
		})
	})
}

const buildFile = async function(dir) {
	try {
		let html = await readFile(dir);
		let tags = html.match(/<script [^>]*>/g);
		let link = html.match(/<link [^>]*>/g);
		let timeStamp = Date.now();
		if (tags && tags.length > 0) {
			tags.forEach(tag => {
				var tempTag = tag;
				if (tag.indexOf(config.dir.controller) === -1 && tag.indexOf(config.dir.util) === -1) {
					return;
				}
				if (tag.indexOf('t=') !== -1) {
					tag = tag.replace(/t=[0-9]{13}/g, '');
				}
				if (tag.indexOf('js?"') !== -1 || tag.indexOf("js?'") !== -1) {
					tag = tag.replace('js?', 'js')
				}
				let replace = tag.replace('.js', `.js?t=${timeStamp}`);
				html = html.replace(tempTag, replace);
			});
		}
		if (link && link.length > 0) {
			link.forEach(tag => {
				var tempTag = tag;
				if (tag.indexOf(config.dir.css) === -1) {
					return;
				}
				if (tag.indexOf('t=') !== -1) {
					tag = tag.replace(/t=[0-9]{13}/g, '');
				}
				if (tag.indexOf('css?"') !== -1 || tag.indexOf("css?'") !== -1) {
					tag = tag.replace('css?', 'css')
				}
				let replace = tag.replace('.css', `.css?t=${timeStamp}`);
				html = html.replace(tempTag, replace);
			});
		}
		await rewriteFile(dir, html);
	} catch (err) {
		console.log(err);
	}
}

const init = async function() {
	try {
		let commonDir = config.views ? config.views : '.';
		config.files.forEach(dir => {
			dir = `${commonDir}${dir}`
			buildFile(dir)
		})
{'fraction_non_alphanumeric': 0.22115997450605482, 'fraction_numerical': 0.007966857871255577, 'mean_word_length': 3.1411609498680737, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 24, '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': '1925926', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1164, 'n_words': 247}