diff --git a/hammer.task.ts b/hammer.js similarity index 58% rename from hammer.task.ts rename to hammer.js index b95f3c9..ed4f236 100644 --- a/hammer.task.ts +++ b/hammer.js @@ -1,13 +1,13 @@ export async function clean() { - + console.log('clean') } export async function start() { - + console.log('start') } export async function build() { - + console.log('build') } diff --git a/package.json b/package.json index 68694ea..f5004ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sinclair/hammer", - "version": "0.12.6", + "version": "0.14.0", "description": "Build Tool for Browser and Node Applications", "author": "sinclairzx81", "keywords": [ diff --git a/readme.md b/readme.md index feeff47..f31c6ce 100644 --- a/readme.md +++ b/readme.md @@ -87,22 +87,21 @@ $ hammer watch worker.ts Use the `monitor` command to execute shell commands on file change. ```bash -$ hammer monitor fib.ts "asc fib.ts --binaryFile fib.wasm --optimize" +$ hammer monitor index.ts "deno run --allow-all index.ts" ``` -## Task +## Tasks -Use the `task` command to execute javascript functions in a file named `hammer.task.ts` or `hammer.task.js`. Hammer will look for this file in the current working directory and will allow any exported function to be called though the CLI. You can use tasks to run shell commands in parallel. Hammer includes a built in `shell()` function for this purpose. The following runs a `run` and `serve` task in parallel. +Hammer provides a built-in task runner for automating various workflow at the command line. Tasks are created with exported JavaScript functions specified in a file named `hammer.js`. Hammer will search for the `hammer.js` file in the current working directory and setup a callable command line interface to each exported function. Hammer provides a global `shell(...)` function that can be used to start command line processes within each task. Additional functionality can be imported via ESM `import`. The following shows running a Hammer website and server watch process in parallel. ```typescript -/** - * file: hammer.task.js - */ - -export async function start(dist = 'target') { - await shell([ - `hammer serve apps/website/index.html --dist ${dist}/website`, - `hammer run apps/server/index.ts --dist ${dist}/server` +// +// file: hammer.js +// +export async function start() { + await Promise.all([ + shell(`hammer serve apps/website/index.html --dist dist/website`), + shell(`hammer run apps/server/index.ts --dist dist/server`) ]) } ``` diff --git a/src/options/options.ts b/src/options/options.ts index 10d7b84..e5742e9 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -379,12 +379,12 @@ export function parseMonitorOptions(params: string[]): MonitorOptions { } function resolveHammerTaskFile(): string { - if(fs.existsSync(path.join(process.cwd(), 'hammer.task.ts'))) { - return path.join(process.cwd(), 'hammer.task.ts') - } else if(fs.existsSync(path.join(process.cwd(), 'hammer.task.js'))) { - return path.join(process.cwd(), 'hammer.task.js') + if(fs.existsSync(path.join(process.cwd(), 'hammer.ts'))) { + return path.join(process.cwd(), 'hammer.ts') + } else if(fs.existsSync(path.join(process.cwd(), 'hammer.js'))) { + return path.join(process.cwd(), 'hammer.js') } else { - throw Error(`No hammer tasks file found. Expected either 'hammer.task.ts' or 'hammer.task.js' in current directory.`) + throw Error(`No hammer tasks file found. Expected either 'hammer.ts' or 'hammer.js' in current directory.`) } }