# gulp-handlebars-typer

> This is a fairly simple gulp plugin to read a file of compiled Handlebars templates. It doesn't support a lot of options (yet?) so it's fairly simplisitic and it requires you to do things in a very specific way.

Latest version **0.1.0** (published 2015-07-03) · 0 weekly downloads

## Install

```sh
npm install gulp-handlebars-typer
pnpm add gulp-handlebars-typer
yarn add gulp-handlebars-typer
bun add gulp-handlebars-typer
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2015-07-03 |
| First published | 2015-07-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Martijn Arts |
| Maintainers | totempaaltj |

## Links

- npm: https://www.npmjs.com/package/gulp-handlebars-typer
- Repository: https://github.com/TotempaaltJ/gulp-handlebars-typer
- Issues: https://github.com/TotempaaltJ/gulp-handlebars-typer/issues
- npm.io page: https://npm.io/package/gulp-handlebars-typer

## Dependencies (3)

- [path](https://npm.io/package/path.md) ^0.11.14
- [through2](https://npm.io/package/through2.md) ^2.0.0
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.6

## Recent versions

- 0.1.0 (latest) — 2015-07-03

## README

# Handlebars Typescript Typer
This is a fairly simple gulp plugin to read a file of compiled Handlebars
templates. It doesn't support a lot of options (yet?) so it's fairly
simplisitic and it requires you to do things in a very specific way.


## So how do I use it?
Here's an example gulp script showing how I compile my templates:

    var tplPath = 'path/to/templates';

    gulp.task('handlebars', function() {
        return gulp.src(['./' + tplPath + '/**/*.hbs',
                         '!./' + tplPath + '/partials/*.hbs'])
            .pipe(handlebars())
            .pipe(wrap('Handlebars.template(<%= contents %>)'))
            .pipe(declare({
                root: 'module.exports',
                noRedeclare: true,
                processName: function(filePath) {
                    return declare.processNameByPath(
                        filePath.replace(tplPath + '/', '')
                    );
                }
            }))
            .pipe(concat('hbs.js'))
            .pipe(wrap('var Handlebars = require("handlebars");\n<%= contents %>'))

            .on('error', function(err) {
                gutil.log(gutil.colors.red('Typer Error:'), err.message);
            })
            .pipe(gulp.dest('./' + tplPath))
            .pipe(typer('hbs.d.ts'))
            .pipe(gulp.dest('./' + tplPath));
    });


## So what's it do?
Now I have a file called `hbs.js` with my compiled templates, and a file called
`hbs.d.ts` with a very simple definition for them. For a template structure
looking like this:

    .
    ├── index.hbs
    ├── test
    │   └── test2.hbs
    └── test.hbs

I get a typing definitions file that looks like this:

    interface Template {
        (data?: any): string,
    }

    interface HbsHierarchy {
        index: Template;
        test: {
            (): Template;
            test2: Template;

        }

    }

    declare module "hbs.js" {
        export var hbs: HbsHierarchy;
        export default hbs;
    }

Which, admittedly, is very simplistic. And it only targets ES6. And there's
some other flaws with it, probably, but it works for at least determining
whether or not a template actually exists at compile time.

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