a5269f5d8f9fb17a9d497d11145bc3b97c13854a
[platform/framework/web/wrtjs.git] / device_home / node_modules / jake / test / integration / jakelib / rule.jake.js
1 const PROJECT_DIR=process.env.PROJECT_DIR;let exec=require("child_process").execSync,fs=require("fs"),util=require("util"),{rule:rule,rmRf:rmRf}=require(`${PROJECT_DIR}/lib/jake`);directory("tmpsrc"),directory("tmpbin"),file("tmp",["tmp_init","tmp_dep1.o","tmp_dep2.o"],(function(t){console.log("tmp task");let e=fs.readFileSync("tmp_dep1.o"),n=fs.readFileSync("tmp_dep2.o");fs.writeFileSync("tmp",e+n)})),rule(".o",".c",(function(){let t=util.format("cp %s %s",this.source,this.name);console.log(t+" task"),exec(t)})),file("tmp_dep1.c",(function(){fs.writeFileSync("tmp_dep1.c","src_1"),console.log("tmp_dep1.c task")})),task("tmp_init",(function(){fs.writeFileSync("tmp_dep2.c","src_2"),console.log("tmp_dep2.c task")})),file("tmp_p",["tmp_init","tmp_dep1.oo","tmp_dep2.oo"],(function(t){console.log("tmp pattern task");let e=fs.readFileSync("tmp_dep1.oo"),n=fs.readFileSync("tmp_dep2.oo");fs.writeFileSync("tmp_p",e+n+" pattern")})),rule("%.oo","%.c",(function(){let t=util.format("cp %s %s",this.source,this.name);console.log(t+" task"),exec(t)})),file("tmp_pf",["tmp_src_init","tmpbin","tmpbin/tmp_dep1.oo","tmpbin/tmp_dep2.oo"],(function(t){console.log("tmp pattern folder task");let e=fs.readFileSync("tmpbin/tmp_dep1.oo"),n=fs.readFileSync("tmpbin/tmp_dep2.oo");fs.writeFileSync("tmp_pf",e+n+" pattern folder")})),rule("tmpbin/%.oo","tmpsrc/%.c",(function(){let t=util.format("cp %s %s",this.source,this.name);console.log(t+" task"),exec(t)})),file("tmpsrc/tmp_dep2.c",["tmpsrc"],(function(){fs.writeFileSync("tmpsrc/tmp_dep2.c","src/src_2"),console.log("tmpsrc/tmp_dep2.c task")})),task("tmp_src_init",["tmpsrc"],(function(){fs.writeFileSync("tmpsrc/tmp_dep1.c","src/src_1"),console.log("tmpsrc/tmp_dep1.c task")})),task("tmp_ns",["tmpbin","rule:init","tmpbin/tmp_dep2.oo","rule:tmpbin/dep1.oo","rule:tmpbin/file2.oo"],(function(){console.log("tmp pattern folder namespace task");let t=fs.readFileSync("tmpbin/dep1.oo"),e=fs.readFileSync("tmpbin/tmp_dep2.oo"),n=fs.readFileSync("tmpbin/file2.oo");fs.writeFileSync("tmp_ns",t+e+n+" pattern folder namespace")})),namespace("rule",(function(){task("init",["tmpsrc"],(function(){fs.writeFileSync("tmpsrc/file2.c","src/src_3"),console.log("tmpsrc/file2.c init task")})),file("tmpsrc/dep1.c",["tmpsrc"],(function(){fs.writeFileSync("tmpsrc/dep1.c","src/src_1"),console.log("tmpsrc/dep1.c task")}),{async:!0}),rule("tmpbin/%.oo","tmpsrc/%.c",(function(){let t=util.format("cp %s %s",this.source,this.name);console.log(t+" ns task"),exec(t)}))})),task("tmp_cr",["chainrule:init","chainrule:tmpbin/file1.pdf","chainrule:tmpbin/file2.pdf"],(function(){console.log("tmp chainrule namespace task");let t=fs.readFileSync("tmpbin/file1.pdf"),e=fs.readFileSync("tmpbin/file2.pdf");fs.writeFileSync("tmp_cr",t+e+" chainrule namespace")})),namespace("chainrule",(function(){task("init",["tmpsrc","tmpbin"],(function(){fs.writeFileSync("tmpsrc/file1.tex","tex1 "),fs.writeFileSync("tmpsrc/file2.tex","tex2 "),console.log("chainrule init task")})),rule("tmpbin/%.pdf","tmpbin/%.dvi",(function(){let t=util.format("cp %s %s",this.source,this.name);console.log(t+" dvi->pdf task"),exec(t)})),rule("tmpbin/%.dvi","tmpsrc/%.tex",["tmpbin"],(function(){let t=util.format("cp %s %s",this.source,this.name);console.log(t+" tex->dvi task"),exec(t)}))})),namespace("precedence",(function(){task("test",["foo.html"],(function(){console.log("ran test")})),rule(".html",".txt",(function(){console.log("created html");let t=fs.readFileSync(this.source);fs.writeFileSync(this.name,t.toString())}))})),namespace("regexPattern",(function(){task("test",["foo.html"],(function(){console.log("ran test")})),rule(/\.html$/,".txt",(function(){console.log("created html");let t=fs.readFileSync(this.source);fs.writeFileSync(this.name,t.toString())}))})),namespace("sourceFunction",(function(){task("test",["foo.html"],(function(){console.log("ran test")})),rule(".html",(function(t){return t.replace(/\.[^.]+$/,".txt")}),(function(){console.log("created html");let t=fs.readFileSync(this.source);fs.writeFileSync(this.name,t.toString())}))})),task("clean",(function(){rmRf("./foo"),rmRf("./tmp")}));