Created
May 19, 2020 15:37
-
-
Save VonHeikemen/638740d6fdd2a6407f0038fae381fedf to your computer and use it in GitHub Desktop.
minimal, no dependencies task runner for deno.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Command line usage examples: | |
// 1: deno run --allow-run ./Taskfile.js start | |
// 2: deno run --allow-run ./Taskfile.js echo "what?" | |
// 3: deno run --allow-run ./Taskfile.js do-stuff one two three | |
run(Deno.args, { | |
start() { | |
exec.cmd('deno run ./src/index.js'); | |
}, | |
echo(str) { | |
return exec(['echo', str ,"\nThis is javascript, y'all"]); | |
}, | |
async ['do-stuff'](...args) { | |
if(true) { | |
await this.echo(`Testing ${args.join(' ')}`); | |
} | |
} | |
}); | |
function run([name, ...args], tasks) { | |
name in tasks | |
? tasks[name](...args) | |
: console.log(`Task "${name}" not found`); | |
} | |
async function exec(cmd) { | |
const proc = await Deno.run({ cmd }).status(); | |
if(proc.success == false) { | |
Deno.exit(proc.code); | |
} | |
return proc; | |
} | |
exec.cmd = function(raw_cmd) { | |
return exec(split(raw_cmd)); | |
}; | |
// taken from: https://github.com/gpasq/deno-exec | |
function split(command) { | |
var myRegexp = /[^\s"]+|"([^"]*)"/gi; | |
var splits = []; | |
do { | |
//Each call to exec returns the next regex match as an array | |
var match = myRegexp.exec(command); | |
if (match != null) { | |
//Index 1 in the array is the captured group if it exists | |
//Index 0 is the matched text, which we use if no captured group exists | |
splits.push(match[1] ? match[1] : match[0]); | |
} | |
} while (match != null); | |
return splits; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not meant to be a module you download, but something you would write in the root of your project to execute external commands or automate some simple tasks.
These are proper task runner for deno: