const path = require('path');
const fs = require('fs');

let currentDir = path.resolve(__dirname, '../'); 
let srcDir =  path.resolve(currentDir,  './src');
let viewDir = path.resolve(currentDir, './src/views');
let assetDir = path.resolve(currentDir, './assets');

module.exports = {
	currentDir: currentDir,
	srcDir: srcDir,
	viewDir: viewDir,
	distDir: path.resolve(currentDir, './dist'),
	faviconDir: path.resolve(assetDir,  './img/favicon.ico'),
	viewPages: (() => {
		let views = [];
		fs.readdirSync(viewDir).forEach((f1) => {
			let fpath = viewDir + '/' + f1;
			if (!fs.statSync(fpath).isDirectory()) {
				return;
			}
						
			fs.readdirSync(fpath).forEach((f2) => {
				let fp = fpath + '/' + f2;
				if (!(fs.statSync(fp).isFile() && /\.js$/.test(fp))) {
					return;
				}
				let tfp = fp.replace('.js', '.html');
				if (!fs.existsSync(tfp)){
					return;
				}
				let isEcharts = fs.readFileSync(fp).indexOf('echarts') > -1;
				views.push({
					id: f1 + '/' + f2.replace('.js', ''),
					echarts: isEcharts,
					entry: fp,
					template: fp.replace('.js', '.html')
					});				
			})
		
		});
	return views;
})(),
}