Skip to content package
emitty v1.3.0 Determine the inheritance of template and style files
node >=4.0.0 4 deps cjs types open source
overview readme
license MIT
deps 4
unpacked Unknown
files Unknown
node >=4.0.0 $ npm install emitty@1.3.0n npmREADME GitHub-flavored package documentation.
downloads Across all versions.
Download trend unavailable.
compatibility Runtime metadata.
keywords Tagged topics.
inheritance incremental building compile compiling dependencies performance tree cache pug jade nunjucks
versions Latest published Jun 25, 2017
maintainers Registry package owners.
contents emitty
Determine the inheritance of template and style files.
What is it? or what is problem?
Most HTML and CSS preprocessors use a synchronous API to access file system and don't use cache for already read files.
It degrades performance and increases the time required to compile the code.
Also, 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.
This is unacceptable if you are working with a "watch" mode.
Solution?
This module allows you to compile only those files that depend on the changed file and require compilation.
For example, if you have the following files:
templates/
a.pug — depends on b.pug
b.pug
c.pug
If 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.
Install
Why?
install size Estimated unpacked size across 21 packages.
1004.7 kB
Includes dependencies.
dependencies 4 direct · 4 outdated
This solution does not use redundant modules such as Pug parser and Glob.
Sufficiently flexible.
Usage const emitty = require ( 'emitty' ). setup ( 'templates' , 'jade' );
emitty. scan (). then (() => {
console. log (emitty. storage ());
// {
// 'a.pug': {
// dependencies: ['components/b.pug'],
// ctime: new Date()
// },
// 'components/b.pug': {
// dependencies: [],
// ctime: new Date()
// }
// }
}
}); copy
Setup
setup(directory, language, [options]) Parameter Type Default Required Description directoryStringnull+ Directory to start from. languageString or Objectnull+ The settings for the language that you want to use. For more details see «Language» section. [options]Object{}- For more details see «Options» section.
API const emitty = require ( 'emitty' ). setup ( 'templates' , 'pug' ); copy
storage() Returns a snapshot of the Storage.
console. log (emitty. storage ());
// {
// 'a.pug': {
// dependencies: ['components/b.pug'],
// ctime: new Date()
// },
// 'components/b.pug': {
// dependencies: [],
// ctime: new Date()
// }
// } copy
keys() Returns the keys of the Storage.
console. log (emitty. keys ());
// ['a.pug', 'components/b.pug'] copy
load(snapshot) Clears the Storage and loads the new data.
emitty. load ({
'c.pug' : {
dependencies: [ 'nope.pug' ],
ctime: new Date ()
}
});
// console.log(emitty.keys());
// ['c.pug'] copy
scan([filepath], [stats]) => Promise Scans 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 ).
emitty. scan (). then (() => {
// console.log(emitty.keys());
// ['a.pug', 'b.pug']
}); copy
resolver
getDependencies(filepath) Returns all files that depends on the specified file.
emitty. scan (). then (() => {
console. log (emitty. getDependencies ( 'a.pug' ));
// ['components/b.pug']
}); copy
checkDependencies(a, b) Returns True if A depends on B.
emitty. scan (). then (() => {
console. log (emitty. getDependencies ( 'a.pug' ));
// ['components/b.pug']
console. log (emitty. checkDependencies ( 'a.pug' , 'components/b.pug' ));
// true
console. log (emitty. checkDependencies ( 'a.pug' , 'nope.pug' ));
// false
}); copy
Is scan method, but for Stream and combines scan + resolver.
Scans directory or file and updates the Storage. Then, if file in stream depends on the changed file — pass it further. Else skip it.
Warning
If you do not specify the filepath to the changed file, it will be the last file that has changed since the last scan.
const stream = emitty. stream ();
stream. on ( 'end' , () => {
// console.log(emitty.keys());
// ['a.pug', 'b.pug']
});
stream. end (); copy
Passes continue to stream only those files that need to be compiled.
Options Option Type Default For Stream Description snapshotObject{}- You can load the previous state of the project in the Storage using this option. logFunctionconsole.log+ The function that will be called if the file needs to be compiled. cleanupIntervalNumbernull- Time interval over which the Storage will be cleared of obsolete items. Recommended for projects very big projects. makeVinylFileBooleanfalse+ You can use gulp.src('patterns', { read: false }) to reduce access for filesystem. This option creates a Vinyl file within a Stream. basedirStringnull- The root directory of all absolute inclusion. scanner.depthNumber30- The maximum number of nested directories to scan. scanner.excludeString[]['.git', '**/node_modules', '**/bower_components']- List of Glob-patterns for directories that are excluded when scanning.
Language
Built-in configs The emitty contains built-in configs for the following instruments:
You can use them when you configure emitty :
const emitty = require ( 'emitty' );
const emittyJade = emitty. setup ( 'templates' , 'pug' );
const emittySugarml = emitty. setup ( 'templates' , 'sugarml' );
// ... copy
Your own config Instead of use built-in config you can specify your own config.
For example, config for Slm :
const emitty = require ( 'emitty' ). setup ( 'templates' , {
extensions: [ '.slm' ],
matcher: /=?=\s(?:partial|extend)\(['"]([^'"]+)['"].*?\)/ ,
comments: {
start: '/' ,
end: ''
},
indentBased: true
}); copy Property Type Default Required Description [extends]Stringnull- 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 . extensionsString[]null+ List of file extensions to be included in Storage when scanning. matcherRegExpnull+ Regexp to run on each line of source code to match dependency references. comments.startStringnull+ The start of a comment. comments.endStringnull+ The end of a comment. [indentBased]Booleanfalse- The syntax of the language is based on indentation? [partials]Booleanfalse- Add additional partials files (files with _ prefix, like Sass/SCSS) to dependencies.
How to use with Gulp
Changelog
License This software is released under the terms of the MIT license.