8b1d78052d8fe1eb5d9f19b756927119e87f5c85
[platform/framework/web/wrtjs.git] / device_home / node_modules / jake / test / integration / jakefile.js
1 let fs=require("fs"),Q=require("q");desc("The default t."),task("default",(function(){console.log("default task")})),desc("No action."),task({noAction:["default"]}),desc("No action, no prereqs."),task("noActionNoPrereqs"),desc("Top-level zerbofrangazoomy task"),task("zerbofrangazoomy",(function(){console.log("Whaaaaaaaa? Ran the zerbofrangazoomy task!")})),desc("Task that throws"),task("throwy",(function(){let e=function(o){console.log("Emitted"),console.log(o.toString()),jake.removeListener("error",e)};throw jake.on("error",e),new Error("I am bad")})),desc("Task that rejects a Promise"),task("promiseRejecter",(function(){const e=jake.program.opts["allow-rejection"],o=function(s){console.log(s.toString()),jake.removeListener("error",o),jake.program.opts["allow-rejection"]=e};jake.on("error",o),jake.program.opts["allow-rejection"]=!1,Promise.reject("<promise rejected on purpose>")})),desc("Accepts args and env vars."),task("argsEnvVars",(function(){let e={args:arguments,env:{foo:process.env.foo,baz:process.env.baz}};console.log(JSON.stringify(e))})),namespace("foo",(function(){desc("The foo:bar t."),task("bar",(function(){arguments.length?console.log("foo:bar["+Array.prototype.join.call(arguments,",")+"] task"):console.log("foo:bar task")})),desc("The foo:baz task, calls foo:bar as a prerequisite."),task("baz",["foo:bar"],(function(){console.log("foo:baz task")})),desc("The foo:qux task, calls foo:bar with cmdline args as a prerequisite."),task("qux",["foo:bar[asdf,qwer]"],(function(){console.log("foo:qux task")})),desc("The foo:frang task,`invokes` foo:bar with passed args as a prerequisite."),task("frang",(function(){let e=jake.Task["foo:bar"];e.invoke.apply(e,arguments),e.on("complete",(()=>{console.log("foo:frang task")}))})),desc("The foo:zerb task, `executes` foo:bar with passed args as a prerequisite."),task("zerb",(function(){let e=jake.Task["foo:bar"];e.execute.apply(e,arguments),e.on("complete",(()=>{console.log("foo:zerb task")}))})),desc("The foo:zoobie task, has no prerequisites."),task("zoobie",(function(){console.log("foo:zoobie task")})),desc("The foo:voom task, run the foo:zoobie task repeatedly."),task("voom",(function(){let e=jake.Task["foo:bar"];e.on("complete",(function(){console.log("complete")})),e.execute.apply(e),e.execute.apply(e)})),desc("The foo:asdf task, has the same prereq twice."),task("asdf",["foo:bar","foo:baz"],(function(){console.log("foo:asdf task")}))})),namespace("bar",(function(){desc("The bar:foo task, has no prerequisites, is async, returns Promise which resolves."),task("foo",(async function(){return new Promise(((e,o)=>{console.log("bar:foo task"),e()}))})),desc("The bar:promise task has no prerequisites, is async, returns Q-based promise."),task("promise",(function(){return Q().then((function(){return console.log("bar:promise task"),123654}))})),desc("The bar:dependOnpromise task waits for a promise based async test"),task("dependOnpromise",["promise"],(function(){console.log("bar:dependOnpromise task saw value",jake.Task["bar:promise"].value)})),desc("The bar:brokenPromise task is a failing Q-promise based async task."),task("brokenPromise",(function(){return Q().then((function(){throw new Error("nom nom nom")}))})),desc("The bar:bar task, has the async bar:foo task as a prerequisite."),task("bar",["bar:foo"],(function(){console.log("bar:bar task")}))})),namespace("hoge",(function(){desc("The hoge:hoge task, has no prerequisites."),task("hoge",(function(){console.log("hoge:hoge task")})),desc("The hoge:piyo task, has no prerequisites."),task("piyo",(function(){console.log("hoge:piyo task")})),desc("The hoge:fuga task, has hoge:hoge and hoge:piyo as prerequisites."),task("fuga",["hoge:hoge","hoge:piyo"],(function(){console.log("hoge:fuga task")})),desc("The hoge:charan task, has hoge:fuga as a prerequisite."),task("charan",["hoge:fuga"],(function(){console.log("hoge:charan task")})),desc("The hoge:gero task, has hoge:fuga as a prerequisite."),task("gero",["hoge:fuga"],(function(){console.log("hoge:gero task")})),desc("The hoge:kira task, has hoge:charan and hoge:gero as prerequisites."),task("kira",["hoge:charan","hoge:gero"],(function(){console.log("hoge:kira task")}))})),namespace("fileTest",(function(){directory("foo"),desc("File task, concatenating two files together"),file("foo/concat.txt",["fileTest:foo","fileTest:foo/src1.txt","fileTest:foo/src2.txt"],(function(){console.log("fileTest:foo/concat.txt task");let e=fs.readFileSync("foo/src1.txt"),o=fs.readFileSync("foo/src2.txt");fs.writeFileSync("foo/concat.txt",e+o)})),desc("File task, async creation with writeFile"),file("foo/src1.txt",(function(){return new Promise((function(e,o){fs.writeFile("foo/src1.txt","src1",(function(s){s?o(s):(console.log("fileTest:foo/src1.txt task"),e())}))}))})),desc("File task, sync creation with writeFileSync"),file("foo/src2.txt",["default"],(function(){fs.writeFileSync("foo/src2.txt","src2"),console.log("fileTest:foo/src2.txt task")})),desc("File task, do not run unless the prereq file changes"),file("foo/from-src1.txt",["fileTest:foo","fileTest:foo/src1.txt"],(function(){let e=fs.readFileSync("foo/src1.txt").toString();fs.writeFileSync("foo/from-src1.txt",e),console.log("fileTest:foo/from-src1.txt task")})),desc("File task, run if the prereq file changes"),task("touch-prereq",(function(){fs.writeFileSync("foo/prereq.txt","UPDATED")})),desc("File task, has a preexisting file (with no associated task) as a prereq"),file("foo/from-prereq.txt",["fileTest:foo","foo/prereq.txt"],(function(){let e=fs.readFileSync("foo/prereq.txt");fs.writeFileSync("foo/from-prereq.txt",e),console.log("fileTest:foo/from-prereq.txt task")})),directory("foo/bar/baz"),desc("Write a file in a nested subdirectory"),file("foo/bar/baz/bamf.txt",["foo/bar/baz"],(function(){fs.writeFileSync("foo/bar/baz/bamf.txt","w00t")}))})),task("blammo"),task("voom",["blammo"],(function(){console.log(this.prereqs.length)})),task("voom",["noActionNoPrereqs"]),namespace("vronk",(function(){task("groo",(function(){let e=jake.Task["vronk:zong"];e.addListener("error",(function(e){console.log(e.message)})),e.invoke()})),task("zong",(function(){throw new Error("OMFGZONG")}))})),namespace("one",(function(){task("one",(function(){console.log("one:one")}))})),namespace("one",(function(){task("two",["one:one"],(function(){console.log("one:two")}))})),task("selfdepconst",[],(function(){task("selfdep",["selfdep"],(function(){console.log("I made a task that depends on itself")}))})),task("selfdepdyn",(function(){task("selfdeppar",[],{concurrency:2},(function(){console.log("I will depend on myself and will fail at runtime")})),task("selfdeppar",["selfdeppar"]),jake.Task.selfdeppar.invoke()})),namespace("large",(function(){task("leaf",(function(){console.log("large:leaf")}));const e=[];for(let o=0;o<2e3;o++)e.push("leaf");desc("Task with a large number of same prereqs"),task("same",e,{concurrency:2},(function(){console.log("large:same")}));const o=[];for(let e=0;e<2e3;e++){const s="leaf-"+e;task(s,(function(){"leaf-12"!==s&&"leaf-123"!==s||console.log(s)})),o.push(s)}desc("Task with a large number of different prereqs"),task("different",o,{concurrency:2},(function(){console.log("large:different")}))}));