import { spawn }  from 'node:child_process'

export function tree() {
		return new Promise((resolve, reject) => {
				const treeCmd = spawn(
						'tree', // unix tree command & parameters...
						[
								'-a', // print all files (event ones starting with dot)
								'-J',  // JSON output
								'--gitignore', // Uses git .gitignore files for filtering
								'--info', // .info files informations
								'--gitfile=.treeignore', // use this file like .gitignore
						],
				);
				treeCmd.on('close', reject)
				treeCmd.stderr.on('data', reject)
				treeCmd.stdout.on('data', (data) => {
						resolve(data.toString())
				})
		})
}
