Skip to content

danielsitek/gulp-tateru-cli

Repository files navigation

gulp-tateru-cli

NPM Version GitHub Release Build Status Codecov Code Climate maintainability Codacy Badge

gulp plugin to build templates, using tateru-cli

Issues

Simple gulp plugin for streamlining integration of the tateru-cli into gulp workflow. If you encounter problems related to file generation, please report them in the tateru-cli issues. Only create a new issue if it looks like you're having a problem with the plugin itself.

Requirements

  • Node.js v14 or higher
  • Gulp v4 or higher

Install

npm i -D gulp-tateru-cli

Usage

For further documentation about using tateru-cli, please look for its documentation. For further documentation about using Gulp, please look for its documentation.

Requirements

For correct resolving destination through pipe, set options.ext to empty string in tateru.config.json.

{
  "options": {
    "data": {},
    "src": "example/src/twig",
    "ext": ""
  }
}

You can find an example of a complete file in the fixtures: test/fixtures/tateru.config.json.

Basic usage

const { src, dest } = require("gulp");
const { gulpTateruCli } = require("gulp-tateru-cli");

const build = function build() {
  return src(["tateru.config.json"], {
    cwd: ".",
  })
    .pipe(gulpTateruCli())
    .pipe(dest("dist"));
};

With options

Plugin gulp-tateru-cli supports TypeScript, so you can use type annotations in your gulp files for better type safety and developer experience.

const { src, dest } = require("gulp");
const { gulpTateruCli } = require("gulp-tateru-cli");

/** @type {import('gulp-tateru-cli').GulpTateruCliOptions} */
const options = {
  env: "prod",
  lang: "cs",
};

const build = function build() {
  return src(["tateru.config.json"], {
    cwd: ".",
  })
    .pipe(gulpTateruCli(options))
    .pipe(dest("dist"));
};

Format contents

const { src, dest } = require("gulp");
const { gulpTateruCli } = require("gulp-tateru-cli");
const { html, js } = require("js-beautify");

/** @type {import('gulp-tateru-cli').Formatter} */
const formatContents = (contents, fileType) => {
  if (fileType && ["html", "xml"].includes(fileType)) {
    return html(contents, {
      indent_size: 4,
    });
  }

  if (fileType && ["json", "webmanifest"].includes(fileType)) {
    return js(contents, {
      indent_size: 2,
    });
  }

  return contents;
};

/** @type {import('gulp-tateru-cli').GulpTateruCliOptions} */
const options = {
  formatter: formatContents,
};

const build = function build() {
  return src(["tateru.config.json"], {
    cwd: ".",
  })
    .pipe(gulpTateruCli(options))
    .pipe(dest("dist"));
};

API

Options

env?: 'prod' | 'dev' | string

Optional. The environment to use from tateru.config.json. Example: dev, prod.

lang?: 'en' | 'cs' | string

Optional. The language to use from tateru.config.json for the generated files. Example: 'en', 'fr', 'es', etc.

page?: 'homepage' | 'about' | string

Optional. The page to use from tateru.config.json for the generated files. Example: 'home', 'about', 'contact', etc.

formatter?: (contents: string, fileType?: string) => string;

Optional. The formatter function to use for formatting the generated files, before minification.

  • contents - The contents of the file to format.
  • fileType - The file type to minify. Example: 'html', 'json', 'webmanifest', etc.
minify?: (contents: string, fileType?: string) => string;

Optional. The minify function to use for minifying the generated files.

  • contents - The contents of the file to minify.
  • fileType - The file type to minify. Example: 'html', 'json', 'webmanifest', etc.

Contributing

Want to contribute? Feel free to open an issue or pull request on GitHub! 🚀 We welcome bug reports, feature requests, and code contributions.

  1. Fork the repo
  2. Create a new branch (git checkout -b feature-branch)
  3. Make your changes
  4. Commit the changes (git commit -m "Add new feature")
  5. Push to the branch (git push origin feature-branch)
  6. Open a pull request 🚀

Support

If you have any questions or need help, feel free to open an issue on GitHub or contact me via GitHub profile.

License

MIT License © 2025 Daniel Sitek

About

Simple gulp plugin for streamlining integration of the tateru-cli into gulp workflow

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published