npm install makestatic-core> Generic file processing library
---
- Install
- API
- LifeCycle
- LifeCycle
- config
- context
- main
- deploy
- .getPlugins
- .getLifecycleConfig
- .process
- phase
- phases
- .run
- Context
- Context
- phase
- phases
- .getFile
- lifecycle
- log
- config
- options
- list
- files
- assets
- agent
- graph
- manifest
- sitemap
- data
- TreeAdapter
- FileList
- FileList
- context
- root
- sources
- files
- assets
- .add
- .remove
- .rewrite
- .rename
- .get
- .getFile
- .propagate
- TreeAdapter
- TreeAdapter
- .parse
- .serialize
- .clone
- .getSeal
- .modify
- .walk
- content
- result
- dirty
- License
---
```
yarn add makestatic-core
Core library for the processing lifecycle.
#### LifeCycle
`javascript`
new LifeCycle(options)
Creates a new LifeCycle.
* options Object the processing options.
#### config
`javascript`
readonly Config config
The lifecycle configuration.
#### context
`javascript`
readonly Context context
The processing context for this lifecycle.
#### main
`javascript`
readonly Array main
List of standard lifecycle phases.
#### deploy
`javascript`
readonly Array deploy
List of deploy lifecycle phases.
#### .getPlugins
`javascript`
LifeCycle.prototype.getPlugins(argv)
Builds the list of phases to execute.
Returns array list of phase plugins.
* argv Object map of option overrides.
#### .getLifecycleConfig
`javascript`
LifeCycle.prototype.getLifecycleConfig(opts, argv)
Abstract method to get a default lifecycle configuration.
Returns object map of lifecycle phase configurations.
* opts Object map of computed options.argv
* Object map of option overrides.
#### .process
`javascript`
LifeCycle.prototype.process(argv, phases)
Process the entire lifecycle.
This method will set the computed options on the config based onargv
the passed options merged with the options specified when
the instance was created.
It will then merge the result of calling getLifecycleConfig() into thelifecycle property of the computed options before retrieving thegetPlugins()
list of plugin phases to execute returned by .
Finally it creates a processing context for this lifecycle beforerun()
deferring execution to the method.
Returns a promise that resolves when all phases have completed.
* argv Object map of option overrides.phases
* Array list of phases to execute.
#### phase
`javascript`
readonly String phase
Name of the currently executing phase.
#### phases
`javascript`
readonly Array phases
List of phases that have already executed.
#### .run
`javascript`
LifeCycle.prototype.run(phases)
Run lifecycle processing phases.
Returns a promise that resolves when all phases have completed.
* phases Array list of phases to execute.
Encapsulates the processing context information.
#### Context
`javascript`
new Context(lifecycle, config)
Configure the information encapsulated by this context.
* lifecycle Object reference to the main lifecycle.config
* Object reference to the configuration.
#### phase
`javascript`
readonly String phase
Name of the currently executing phase.
#### phases
`javascript`
readonly Array phases
List of phases that have already executed.
#### .getFile
`javascript`
Context.prototype.getFile(opts)
Alias for FileList.getFile.
Returns a File instance.
* opts String|Object file creation options.
#### lifecycle
`javascript`
readonly Object lifecycle
Get the main lifecycle runner.
#### log
`javascript`
readonly Object log
Get the log helper.
#### config
`javascript`
readonly Object config
Get the configuration.
#### options
`javascript`
readonly Object options
Get the computed options encapsulated by the config.
#### list
`javascript`
readonly Object list
Get the file list manager.
#### files
`javascript`
readonly Array files
Get the output file list.
#### assets
`javascript`
Object assets
Map of output assets.
Compatible with the webpack asset map.
#### agent
`javascript`
Object agent
HTTP client agent.
Many plugins need to fetch resources from the network so it makes sense
for them to use a common API for loading network resources and allowing
resources to be cached which makes consecutive builds much faster.
Propagated when the http-cache plugin is used. The core-standardhttp-cache
package will load the plugin automatically.
#### graph
`javascript`
Object graph
Application resource graph.
Propagated when the graph-resources plugin is used.
#### manifest
`javascript`
Object manifest
Application manifest.
Propagated when the manifest plugin is used.
#### sitemap
`javascript`
Object sitemap
Application sitemap.
Propagated when the sitemap plugin is used.
#### data
`javascript`
readonly Object data
Property that allows plugins to assign arbitrary data to the processing
context that may be used by other plugins.
#### TreeAdapter
`javascript`
readonly Function TreeAdapter
Reference to the TreeAdapter class.
Parsers should use this class to provide a consistent API for
parsing documents to abstract syntax trees with the benefits
provided by the tree adapter implementation.
Encapsulates the output file lists.
The files list is an array of file objects whilstassets
the list is a map of relative file paths to file objects.
#### FileList
`javascript`
new FileList(context, sources)
Create a FileList.
* context Object the processing context.sources
* Array list of file names.
#### context
`javascript`
readonly Object context
The processing context.
#### root
`javascript`
readonly String root
The root directory for input files.
#### sources
`javascript`
readonly Array sources
Raw list of input file names.
#### files
`javascript`
readonly Array files
List of current output files.
#### assets
`javascript`
Object assets
Map of current output files.
#### .add
`javascript`
FileList.prototype.add(options)
Add a file to the list by name or pointer.
The file is not added if it already exists in the files list.
Returns the file on success otherwise undefined.
* options String|Object source file name or file properties.
#### .remove
`javascript`
FileList.prototype.remove(options)
Remove a file from the list by name or pointer.
Returns the file on success otherwise undefined.
* options String|Object source file name or file properties.
#### .rewrite
`javascript`
FileList.prototype.rewrite(options, dest)
Rewrite the output path for an existing file.
Returns the file on success otherwise undefined.
* options String|Object source file name or file properties.dest
* String the new output path for the file.
#### .rename
`javascript`
FileList.prototype.rename(options, name)
Rename the output file name for an existing file.
Returns the file on success otherwise undefined.
* options String|Object source file name or file properties.name
* String the new output name for the file.
#### .get
`javascript`
FileList.prototype.get(options)
Get a file from the list by name or pointer.
Returns a file object or undefined.
* options String|Object source file name or file properties.
#### .getFile
`javascript`
FileList.prototype.getFile(options)
Get a File pointer.
Accepts an input file path which becomes the file name or a map of
properties for the new file.
If a File is passed it is returned.
Returns a file object.
* options String|Object source file name or file properties.
#### .propagate
`javascript`
FileList.prototype.propagate(sources)
Propagates the file lists converting file path strings to
complex filewrap objects.
* sources Array list of input file names.
Abstraction for abstract syntax tree parsers and serializers that
provides a common API for interacting with abstract syntax trees.
This implementation provides a mechanism for lazily converting buffers to
strings when the tree is parsed and lazily parsing when the result
property is accessed.
It also allows for trees to be marked as dirty, if a tree has not been
marked as dirty and serialize is called the original content is returned.
#### TreeAdapter
`javascript`
new TreeAdapter(parse, serialize, iterator, content[, clone])
Create a TreeAdapter.
All constructor parameters are required.
* parse Function a closure that parses to an AST.serialize
* Function a closure that serializes an ASTiterator
* Function a closure that iterates the ASTcontent
* String|Buffer the content to parse.clone
* Function called when this AST adapter is cloned.
#### .parse
`javascript`
TreeAdapter.prototype.parse()
Calls the underlying AST parse closure and sets the result on
this adapter.
Returns this tree adapter.
#### .serialize
`javascript`
TreeAdapter.prototype.serialize()
Calls the underlying AST serialize closure.
Returns the serialize closure return value.
#### .clone
`javascript`
TreeAdapter.prototype.clone([content])
Gets a copy of this tree adapter sharing the same parse, serialize
iterator and clone closures.
If the consumer passed a clone function to the constructor it is called
with the cloned tree adapter so that the consumer can decorate the new
tree if necessary.
Returns a new tree adapter.
* content String content for the new tree adapter.
#### .getSeal
`javascript`
TreeAdapter.prototype.getSeal()
Gets a file seal closure for this adapter.
If this AST is not dirty the original content is returned.
Returns a seal closure.
#### .modify
`javascript`
TreeAdapter.prototype.modify(fn)
Calls a function passing the result AST and flags this tree as dirty.
If the passed function does not return a value it is assumed the tree is
dirty otherwise the return value is coerced to a boolean and set as the
dirty flag.
Returns this tree adapter.
* fn Function the tree modifier function.
#### .walk
`javascript`
TreeAdapter.prototype.walk(predicate, fn)
Walk the abstract syntax tree nodes.
Returns this tree adapter.
* predicate Function test if a node should be visited.fn
* Function visit a node.
#### content
`javascript`
readonly Buffer|String content
Source file content.
#### result
`javascript`
readonly Object result
A parse result object.
#### dirty
`javascript``
Boolean dirty
Determines if the tree is dirty.
MIT
---
Created by mkdoc on March 12, 2017
[docs]: https://makestatic.ws/docs/ "Documentation"
[standalone manual]: https://github.com/makestatic/website/blob/master/MANUAL.md "Standalone Manual"
[yarn]: https://yarnpkg.com "Yarn"
[webpack]: https://webpack.js.org "Webpack"
[babel]: https://babeljs.io "Babel"
[postcss]: http://postcss.org "Postcss"
[sugarss]: https://github.com/postcss/sugarss "Sugarss"
[reshape]: https://github.com/reshape/reshape "Reshape Source Code"
[reshapeml]: https://reshape.ml "Reshape"
[clean-css]: https://github.com/jakubpawlowicz/clean-css "Clean CSS"
[html-minifier]: https://github.com/kangax/html-minifier "Html Minifier"
[uglify-js]: https://github.com/mishoo/UglifyJS2 "Uglify JS"
[imagemin]: https://github.com/imagemin/imagemin "Imagemin"
[mkdoc]: https://github.com/mkdoc/mkdoc "Mkdoc"
[browsersync]: https://www.browsersync.io "Browsersync"
[yeoman]: http://yeoman.io "Yeoman"
[spike]: https://www.spike.cf "Spike"
[validator]: https://github.com/validator/validator "HTML Validator"
[github pages]: https://pages.github.com "Github Pages"
[amazon s3]: https://aws.amazon.com/s3/ "Amazon S3"
[google sitemaps]: https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 "Google Sitemaps"
[sitemaps]: https://www.sitemaps.org/ "Sitemaps"