Skip to content

Commit

Permalink
Rename hammer.task.js to hammer.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Sep 1, 2021
1 parent f7ac402 commit 4857e8c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions hammer.task.ts → hammer.js
Original file line number Diff line number Diff line change
@@ -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')
}


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
21 changes: 10 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
])
}
```
Expand Down
10 changes: 5 additions & 5 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
}
}

Expand Down

0 comments on commit 4857e8c

Please sign in to comment.