{"id":15177344,"url":"https://github.com/zoxon/emitty","last_synced_at":"2025-10-01T16:31:12.545Z","repository":{"id":57171082,"uuid":"151819201","full_name":"zoxon/emitty","owner":"zoxon","description":"📦 Determine the inheritance of template and style files.","archived":false,"fork":true,"pushed_at":"2018-10-06T09:17:55.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-14T19:42:27.808Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mrmlnc/emitty","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoxon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-06T08:19:58.000Z","updated_at":"2018-10-06T09:17:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zoxon/emitty","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoxon%2Femitty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoxon%2Femitty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoxon%2Femitty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoxon%2Femitty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoxon","download_url":"https://codeload.github.com/zoxon/emitty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234882636,"owners_count":18901301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-27T14:21:19.949Z","updated_at":"2025-10-01T16:31:12.171Z","avatar_url":"https://github.com/zoxon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# emitty\n\n\u003e Determine the inheritance of template and style files.\n\n## What is it? or what is problem?\n\nMost HTML and CSS preprocessors use a synchronous API to access file system and don't use cache for already read files.\nIt degrades performance and increases the time required to compile the code.\n\nAlso, when your project is very large and has a large number of dependencies between blocks (e.g. many mixins) — compiles all files of a project may take seconds or even minutes.\nThis is unacceptable if you are working with a \"watch\" mode.\n\n**Solution?**\n\nThis module allows you to compile only those files that depend on the changed file and require compilation.\n\nFor example, if you have the following files:\n\n  * templates/\n    * `a.pug` — depends on `b.pug`\n    * `b.pug`\n    * `c.pug`\n\nIf you change the `c.pug` file, then will be compiled only it. If you change the `b.pug` file, then will be compiled `a.pug` file.\n\n## Install\n\n```\n$ npm i -D emitty\n```\n\n## Why?\n\n  * See [«What is it? or what is problem?»](#what-is-it-or-what-is-problem) section.\n  * This solution does not use redundant modules such as Pug parser and Glob.\n  * Sufficiently flexible.\n\n## Usage\n\n```js\nconst emitty = require('emitty').setup('templates', 'jade');\n\nemitty.scan().then(() =\u003e {\n  console.log(emitty.storage());\n  // {\n  //   'a.pug': {\n  //     dependencies: ['components/b.pug'],\n  //     ctime: new Date()\n  //   },\n  //   'components/b.pug': {\n  //     dependencies: [],\n  //     ctime: new Date()\n  //   }\n  // }\n  }\n});\n```\n\n## Setup\n\n### setup(directory, language, [options])\n\nCreates API for **emitty**.\n\n| Parameter   | Type                 | Default | Required | Description |\n|:-----------:|:--------------------:|:-------:|:--------:|:------------|\n| `directory` | `String`             | `null`  | +        | Directory to start from. |\n| `language`  | `String` or `Object` | `null`  | +        | The settings for the language that you want to use. For more details see [«Language»](#language) section. |\n| `[options]` | `Object`             | `{}`    | -        | For more details see [«Options»](#options) section. |\n\n## API\n\n```js\nconst emitty = require('emitty').setup('templates', 'pug');\n```\n\n### storage()\n\nReturns a snapshot of the Storage.\n\n```js\nconsole.log(emitty.storage());\n// {\n//   'a.pug': {\n//     dependencies: ['components/b.pug'],\n//     ctime: new Date()\n//   },\n//   'components/b.pug': {\n//     dependencies: [],\n//     ctime: new Date()\n//   }\n// }\n```\n\n### keys()\n\nReturns the keys of the Storage.\n\n```js\nconsole.log(emitty.keys());\n// ['a.pug', 'components/b.pug']\n```\n\n### load(snapshot)\n\nClears the Storage and loads the new data.\n\n```js\nemitty.load({\n  'c.pug': {\n    dependencies: ['nope.pug'],\n    ctime: new Date()\n  }\n});\n// console.log(emitty.keys());\n// ['c.pug']\n```\n\n### scan([filepath], [stats]) =\u003e Promise\n\nScans directory and updates the Storage. If you specify a `filepath`, then only that file will be scanned. Also you can specify `stats` of file (to avoid doing unnecessary actions inside **emitty**).\n\n```js\nemitty.scan().then(() =\u003e {\n  // console.log(emitty.keys());\n  // ['a.pug', 'b.pug']\n});\n```\n\n### resolver\n\n#### getDependencies(filepath)\n\nReturns all files that depends on the specified file.\n\n```js\nemitty.scan().then(() =\u003e {\n  console.log(emitty.resolver.getDependencies('a.pug'));\n  // ['components/b.pug']\n});\n```\n\n#### checkDependencies(a, b)\n\nReturns True if A depends on B.\n\n```js\nemitty.scan().then(() =\u003e {\n  console.log(emitty.resolver.getDependencies('a.pug'));\n  // ['components/b.pug']\n  console.log(emitty.resolver.checkDependencies('a.pug', 'components/b.pug'));\n  // true\n  console.log(emitty.resolver.checkDependencies('a.pug', 'nope.pug'));\n  // false\n});\n```\n\n### stream([filepath], [stats]) =\u003e TransformStream\n\nIs [scan](#scanfilepath-stats--promise) method, but for Stream and combines `scan` + `resolver`.\n\nScans directory or file and updates the Storage. Then, if file in stream depends on the changed file — pass it further. Else skip it.\n\n\u003e **Warning**\n\u003e\n\u003e If you do not specify the filepath to the changed file, it will be the last file that has changed since the last scan.\n\n```js\nconst stream = emitty.stream();\nstream.on('end', () =\u003e {\n  // console.log(emitty.keys());\n  // ['a.pug', 'b.pug']\n});\n\nstream.end();\n```\n\n## filter(filepath) =\u003e TransformStream\n\nPasses continue to stream only those files that need to be compiled.\n\n## Options\n\n| Option            | Type       | Default                                              | For Stream | Description |\n|:-----------------:|:----------:|:----------------------------------------------------:|:----------:|:------------|\n| `snapshot`        | `Object`   | `{}`                                                 | -          | You can load the previous state of the project in the Storage using this option. |\n| `log`             | `Function` | `console.log`                                        | +          | The function that will be called if the file needs to be compiled. |\n| `cleanupInterval` | `Number`   | `null`                                               | -          | Time interval over which the Storage will be cleared of obsolete items. Recommended for projects very big projects. |\n| `makeVinylFile`   | `Boolean`  | `false`                                              | +          | You can use `gulp.src('patterns', { read: false })` to reduce access for filesystem. This option creates a Vinyl file within a Stream. |\n| `basedir`   | `String`   | `null`                                                 | -          | The root directory of all absolute inclusion. |\n| `scanner.depth`   | `Number`   | `30`                                                 | -          | The maximum number of nested directories to scan. |\n| `scanner.exclude` | `String[]` | `['.git', '**/node_modules', '**/bower_components']` | -          | List of Glob-patterns for directories that are excluded when scanning. |\n\n## Language\n\n### Built-in configs\n\nThe **emitty** contains built-in configs for the following instruments:\n\n  * `jade` — now it's Pug\n  * [`pug`](https://pugjs.org)\n  * [`nunjucks`](https://mozilla.github.io/nunjucks)\n  * [`posthtml`](https://github.com/posthtml/posthtml) — with `posthtml-include` and/or `posthtml-extend` plugin.\n  * [`sugarml`](https://github.com/posthtml/sugarml) — with `posthtml-include` and/or `posthtml-extend` plugin.\n  * [`less`](http://lesscss.org/)\n  * [`stylus`](http://stylus-lang.com/) — indent based syntax\n  * [`sass`](http://sass-lang.com/)\n  * [`scss`](http://sass-lang.com/)\n\nYou can use them when you configure **emitty**:\n\n```js\nconst emitty = require('emitty');\nconst emittyJade = emitty.setup('templates', 'pug');\nconst emittySugarml = emitty.setup('templates', 'sugarml');\n// ...\n```\n\n### Your own config\n\nInstead of use built-in config you can specify your own config.\n\nFor example, config for [Slm](https://github.com/slm-lang/slm):\n\n```js\nconst emitty = require('emitty').setup('templates', {\n  extensions: ['.slm'],\n  matcher: /=?=\\s(?:partial|extend)\\(['\"]([^'\"]+)['\"].*?\\)/,\n  comments: {\n    start: '/',\n    end: ''\n  },\n  indentBased: true\n});\n```\n\n| Property         | Type       | Default | Required | Description |\n|:----------------:|:----------:|:-------:|:--------:|:------------|\n| `[extends]`      | `String`   | `null`  | -        | The name of built-in config, which will be basis for this config. If you specify this property, you can specify other properties **as needed**. |\n| `extensions`     | `String[]` | `null`  | +        | List of file extensions to be included in Storage when scanning. |\n| `matcher`        | `RegExp`   | `null`  | +        | Regexp to run on each line of source code to match dependency references. |\n| `comments.start` | `String`   | `null`  | +        | The start of a comment. |\n| `comments.end`   | `String`   | `null`  | +        | The end of a comment. |\n| `[indentBased]`  | `Boolean`  | `false` | -        | The syntax of the language is based on indentation? |\n| `[partials]`  | `Boolean`  | `false` | -        | Add additional partials files (files with `_` prefix, like Sass/SCSS) to dependencies. |\n\n## How to use with Gulp\n\n  * [Minimal](https://github.com/mrmlnc/emitty/blob/master/examples/stream-minimal.js)\n  * [Basic](https://github.com/mrmlnc/emitty/blob/master/examples/stream-basic.js)\n  * [Advanced](https://github.com/mrmlnc/emitty/blob/master/examples/stream-advanced.js)\n  * [Performance](https://github.com/mrmlnc/emitty/blob/master/examples/stream-performance.js) (recommended)\n  * [Ninja](https://github.com/mrmlnc/emitty/blob/master/examples/stream-ninja.js)\n\n## Changelog\n\nSee the [Releases section of our GitHub project](https://github.com/mrmlnc/emitty/releases) for changelogs for each release version.\n\n## License\n\nThis software is released under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoxon%2Femitty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoxon%2Femitty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoxon%2Femitty/lists"}