# hbsmon

> Monitor .hbs (Handlebar) file for changes and execute specified .js file

Latest version **1.0.4** (published 2022-01-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install hbsmon
pnpm add hbsmon
yarn add hbsmon
bun add hbsmon
```

Provides the command `hbsmon`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-01-24 |
| First published | 2022-01-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Ion Gireada shytiger@yahoo.com |
| Maintainers | shytiger |
| Keywords | template, templates, Handlebars, watch, changes, productivity |

## Links

- npm: https://www.npmjs.com/package/hbsmon
- Repository: https://github.com/ioncakephper/hbsmon
- Homepage: https://github.com/ioncakephper/hbsmon#readme
- Issues: https://github.com/ioncakephper/hbsmon/issues
- npm.io page: https://npm.io/package/hbsmon

## Dependencies (6)

- [fs](https://npm.io/package/fs.md) ^0.0.1-security
- [path](https://npm.io/package/path.md) ^0.12.7
- [commander](https://npm.io/package/commander.md) ^8.3.0
- [file-easy](https://npm.io/package/file-easy.md) ^1.0.3
- [handlebars](https://npm.io/package/handlebars.md) ^4.7.7
- [child_process](https://npm.io/package/child_process.md) ^1.0.2

## Recent versions

- 1.0.4 (latest) — 2022-01-24
- 1.0.3 — 2022-01-24
- 1.0.2 — 2022-01-24
- 1.0.1 — 2022-01-24

## README

# hbsmon

Monitor .hbs (Handlebar) file for changes and execute specified .js 

## Installation

Install the package globally so you can use the `hbsmon` CLI command:

```bash
npm i -g hbsmon
```

## Usage

### Get help

```bash
hbsmon -h
```

### Get version

```bash
hbsmon -V
```

### Monitor `.hbs` file, run script file with template basename

```bash
hbsmon template
```

* Monitor changes of `template.hbs` file and run `template.js` script
* Template default extension: `.hbs`
* Default JavaScript default extension `.js`
* Default Javascript filename: template file basename
  
### Monitor `.hbs` file, run specified script

```
hbsmon template create-page
```

* Monitor changes of `template.hbs` file
* Template default extension: `.hbs`
* Default JavaScript default extension `.js`
* Run javacript file: `create-page.js`


## Quick demo

This example shows how you to monitor changes to a `.hbs` template file and run a script when the template file changes.

1. Create a `template.hbs` file: this is the file template file you will monitor for changes

```hbs
<body>
    <ul>
        {{#each items as |item|}}
        <li>
            <a href="{{{item.url}}}" title="">{{{item.text}}}</a>
        </li>
        {{/each}}
    </ul>
</body>
```

2. Create a `create.js` file: this is the script you will invoke when `template.hbs` file changes.

```js
const Handlebars = require('handlebars')
const fs = require('fs')

function render(source, data = {}) {
    let template = Handlebars.compile(source);
    return template(data);
}

let items = "First Second".split(/\s+/).map((label, idx) => {
    return {
        text: `${label} ${idx+1}`,
        url: `#`,
    }
})
let source = fs.readFileSync(`template.hbs`, "utf-8")
let output = render(source, {items: items})
fs.writeFileSync('result.html', output, "utf-8");
console.log(source);

```

3. Install `hbsmon` globally, if not already installed.

```bash
npm i -g hbsmon
```

To check `hbsmon` is already installed, type `hbsmon -V` at the command prompt.

4. Run `hbsmon` in a terminal

```bash
hbsmon template create
```

5. In your IDE, open `template.hbs` and `result.html`

As you type changes to your template, the `result.html` also changes. When `hbsmon` detects a change in the `.hbs` file, it invokes the `change.js` script, which uses the `.hbs` file to create the `result.html` file.

---
_Source: https://npm.io/package/hbsmon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
