const Vuedoc = require('@vuedoc/parser');
const Components = require('./components.json');

async function getTags() {
	const Tags = [];

	for (const tag in Components) {
		if (Object.hasOwnProperty.call(Components, tag)) {
			let files = Components[tag];

			if (typeof files == "string") {
				files = [files];
			}

			const el = {};

			for (i in files) {
				const result = await Vuedoc.parse({
					filename: files[i],
					features: ['name', 'description', 'props', 'events'],
				});

				if (i == 0) {
					el.name = result.name;
					el.description = result.description;
					el.attributes = [];
				}

				result.props.forEach(i => {
					el.attributes.push({ name: i.name });
					el.attributes.push({ name: `:${i.name}` });
				});

				result.events.forEach(i => {
					el.attributes.push({ name: `v-on:${i.name}` });
					el.attributes.push({ name: `@${i.name}` });
				});
			}

			Tags.push(el);
		}
	}

	return Tags;
}


getTags().then(tags => {
	console.log(JSON.stringify({
		version: 1.1,
		tags: tags,
		globalAttributes: [
			{name: 'v-background'},
			{name: 'v-copy'},
			{name: 'v-mask'},
			{name: 'v-size'},
			{name: 'v-tooltip'},
		]
	}, null, 2));
}).catch(err => {
	console.error(err);
})
