const { bddy, file, virt, any } = require("../index");
const fs = require("fs-extra");

const dir = file(`${__dirname}/sample1`);

bddy(function(ctx, def) {
	def(any.file(`${dir}/b.txt`), async function(target) {
		let prerequisites = await this.need(`${dir}/a.txt`);
		await this.run("cp", prerequisites[0], target);
	});

	def(any.file(`${dir}/c.txt`), async function(target) {
		let prerequisites = await this.need(`${dir}/b.txt`);
		await this.run("cp", prerequisites[0], target);
	});

	def(any.virt("knot"), async function(target) {
		await this.need(`${dir}/b.txt`);
	});

	def(any.file(`${dir}/d.txt`), async function(target) {
		let prerequisites = await this.need("knot");
		await this.run("cp", `${dir}/b.txt`, target);
	});

	def(any.file(`${dir}/e.txt`), async function(target) {
		let [$1, $2] = await this.need(`${dir}/c.txt`, `${dir}/d.txt`);
		let txt1 = await fs.readFile(`${$1}`, "utf-8");
		let txt2 = await fs.readFile(`${$2}`, "utf-8");
		console.log(txt1, txt2);
		await fs.writeFile(`${target}`, txt1 + "\n\n" + txt2);
		this.message(`${target} written.`);
	});

	def(any.file(`${dir}/subdir`), ctx.ensureDir);

	def(any.file(`${dir}/subdir/f.txt`), async function(target) {
		let [$1, $2] = await this.need(`${dir}/subdir`, `${dir}/e.txt`);
		await this.run("cp", `${$2}`, `${$1}/f.txt`);
	});
}).wish(`${dir}/subdir/f.txt`);

@@ -152,21 +152,23 @@
 tx, 
-def
+forany
 ) %7B%0D%0A%09
-def(
+for
 any.
@@ -183,26 +183,29 @@
 dir%7D/b.txt%60)
-, 
+.def(
 async functi
@@ -326,36 +326,35 @@
 get);%0D%0A%09%7D);%0D%0A%0D%0A%09
-def(
+for
 any.file(%60$%7Bdir%7D
@@ -357,26 +357,29 @@
 dir%7D/c.txt%60)
-, 
+.def(
 async functi
@@ -504,28 +504,27 @@
 ;%0D%0A%09%7D);%0D%0A%0D%0A%09
-def(
+for
 any.virt(%22kn
@@ -527,18 +527,21 @@
 (%22knot%22)
-, 
+.def(
 async fu
@@ -595,36 +595,35 @@
 xt%60);%0D%0A%09%7D);%0D%0A%0D%0A%09
-def(
+for
 any.file(%60$%7Bdir%7D
@@ -626,26 +626,29 @@
 dir%7D/d.txt%60)
-, 
+.def(
 async functi
@@ -759,36 +759,35 @@
 get);%0D%0A%09%7D);%0D%0A%0D%0A%09
-def(
+for
 any.file(%60$%7Bdir%7D
@@ -790,26 +790,29 @@
 dir%7D/e.txt%60)
-, 
+.def(
 async functi
@@ -1124,28 +1124,27 @@
 ;%0D%0A%09%7D);%0D%0A%0D%0A%09
-def(
+for
 any.file(%60$%7B
@@ -1156,18 +1156,21 @@
 subdir%60)
-, 
+.def(
 ctx.ensu
@@ -1181,20 +1181,19 @@
 r);%0D%0A%0D%0A%09
-def(
+for
 any.file
@@ -1215,18 +1215,21 @@
 /f.txt%60)
-, 
+.def(
 async fu

update sample