@sepalang/runner

0.13.1 • Public • Published

CircleCI Codacy Badge Greenkeeper badge

🏃 runner

It was created to make child processes easier.

usage

Run the command from your npm project.

npm install @sepalang/runner

Then write an async await function to execute sequentially.

block run

const runner = require("@sepalang/runner"); //or import runner form "runner";

// Generate processors sequentially.
runner(async ({ run })=>{

  // Sequential execution using await
  await run("pwd");
  // /Users/user/runner/test

  // Can run vim.
  await run("vim");
  
  // Can run npm.
  await run("npm run-script");
  

  let stdout;
  const { stdout } = await run("pwd",{ capture:true }));
  // /Users/user/runner/test
  console.log({stdout}) // {stdout:['/Users/user/runner/test']}

  ({ stdout } = await run("ls -a",{ capture:true, silent:true }));
  console.log(stdout); // [ 'test-vim.js','ntest1.js','test3.js' ]
  
})

block utils

// Provides frequently used parameters when executing a process.
runner(async ({ pwd, cwd, fwd, timeoutPromise })=>{

  console.log("cwd", cwd); // /Users/user/runner
  console.log("pwd", pwd); // /Users/user/runner/test
  console.log("fwd", fwd); // /Users/user/runner/test/test.js
  
  //wait 3000ms
  await timeoutPromise(3000);  
  await timeoutPromise(()=>{
    //wait 3000ms
  },3000);

})

confirm

runner(async ({ confirm })=>{
  const isOk = await confirm("Are you sure?")
});

prompt

runner(async ({ prompt })=>{
  //prompt
  const anyKey = await prompt("Please enter any key")
  console.log(`You entered is '${anyKey}'.`)
  
  const yn = await prompt({
    message: "Please enter y or n.",
    validate: (input)=>["y","n"].includes(input) ? true : "Be sure to enter y or n."
  })
  console.log(`You entered is ${yn}`)

  const keywords = await prompt({
    type: "list",
    message: "Enter keywords."
  }) // 1,2,3,4,5,
  console.log(`You entered is ${keywords}`) // ['1','2','3','4','5']
})

select

// Provide input.
runner(async ({ select })=>{
  //select
  const options = [
    {label:"foo", value:"SELECTED_FOO", description: "I'm FOO"},
    {label:"bar", value:"SELECTED_BAR", description: "I'm BAR"},
  ]

  const selectSingle = await select({
    message: "selectSingle",
    options,
  })
  console.log("selectSingle", selectSingle) // ['SELECTED_FOO']

  const selectMultiple = await select({
    message: "selectMultiple",
    multiple: true,
    options,
  })
  console.log("selectMultiple", selectMultiple) // ['SELECTED_FOO', 'SELECTED_BAR']
})

inline run

// Load parameters outside the block
async function asyncBlock(){
  const { run } = await runner()
  await run("pwd");
}

with process

// Works as a Promise Base.
runner(()=>{})
.then(()=>{
  // finally block
  process.exit(0);
})
.catch((e)=>{
  // catch block;
  process.exit(1);
});

cmd

runner npm start
runner ./other/cwd/path npm start

Updated

0.13.1

  • Fixed a problem in which the silent option did not work properly.

0.13.0

  • The stdout of the capture option was truncated in versions 0.12.x and below. This bug has been fixed.

Readme

Keywords

Package Sidebar

Install

npm i @sepalang/runner

Weekly Downloads

1

Version

0.13.1

License

MIT

Unpacked Size

17.3 kB

Total Files

6

Last publish

Collaborators

  • hojung