makestatic-core
Generic file processing library
Last updated 2 years ago by tmpfs .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install makestatic-core 
SYNC missed versions from official npm registry.

Core

Generic file processing library



Install

yarn add makestatic-core

API

LifeCycle

Core library for the processing lifecycle.

LifeCycle

new LifeCycle(options)

Creates a new LifeCycle.

  • options Object the processing options.

config

readonly Config config

The lifecycle configuration.

context

readonly Context context

The processing context for this lifecycle.

main

readonly Array main

List of standard lifecycle phases.

deploy

readonly Array deploy

List of deploy lifecycle phases.

.getPlugins

LifeCycle.prototype.getPlugins(argv)

Builds the list of phases to execute.

Returns array list of phase plugins.

  • argv Object map of option overrides.

.getLifecycleConfig

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

LifeCycle.prototype.process(argv, phases)

Process the entire lifecycle.

This method will set the computed options on the config based on the passed argv options merged with the options specified when the instance was created.

It will then merge the result of calling getLifecycleConfig() into the lifecycle property of the computed options before retrieving the list of plugin phases to execute returned by getPlugins().

Finally it creates a processing context for this lifecycle before deferring execution to the run() 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

readonly String phase

Name of the currently executing phase.

phases

readonly Array phases

List of phases that have already executed.

.run

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.

Context

Encapsulates the processing context information.

Context

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

readonly String phase

Name of the currently executing phase.

phases

readonly Array phases

List of phases that have already executed.

.getFile

Context.prototype.getFile(opts)

Alias for FileList.getFile.

Returns a File instance.

  • opts String|Object file creation options.

lifecycle

readonly Object lifecycle

Get the main lifecycle runner.

log

readonly Object log

Get the log helper.

config

readonly Object config

Get the configuration.

options

readonly Object options

Get the computed options encapsulated by the config.

list

readonly Object list

Get the file list manager.

files

readonly Array files

Get the output file list.

assets

Object assets

Map of output assets.

Compatible with the webpack asset map.

agent

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-standard package will load the http-cache plugin automatically.

graph

Object graph

Application resource graph.

Propagated when the graph-resources plugin is used.

manifest

Object manifest

Application manifest.

Propagated when the manifest plugin is used.

sitemap

Object sitemap

Application sitemap.

Propagated when the sitemap plugin is used.

data

readonly Object data

Property that allows plugins to assign arbitrary data to the processing context that may be used by other plugins.

TreeAdapter

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.

FileList

Encapsulates the output file lists.

The files list is an array of file objects whilst the assets list is a map of relative file paths to file objects.

FileList

new FileList(context, sources)

Create a FileList.

  • context Object the processing context.
  • sources Array list of file names.

context

readonly Object context

The processing context.

root

readonly String root

The root directory for input files.

sources

readonly Array sources

Raw list of input file names.

files

readonly Array files

List of current output files.

assets

Object assets

Map of current output files.

.add

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

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

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

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

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

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

FileList.prototype.propagate(sources)

Propagates the file lists converting file path strings to complex filewrap objects.

  • sources Array list of input file names.

TreeAdapter

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

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 AST
  • iterator Function a closure that iterates the AST
  • content String|Buffer the content to parse.
  • clone Function called when this AST adapter is cloned.

.parse

TreeAdapter.prototype.parse()

Calls the underlying AST parse closure and sets the result on this adapter.

Returns this tree adapter.

.serialize

TreeAdapter.prototype.serialize()

Calls the underlying AST serialize closure.

Returns the serialize closure return value.

.clone

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

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

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

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

readonly Buffer|String content

Source file content.

result

readonly Object result

A parse result object.

dirty

Boolean dirty

Determines if the tree is dirty.

License

MIT


Created by mkdoc on March 12, 2017

Current Tags

  • 1.0.83                                ...           latest (2 years ago)

84 Versions

  • 1.0.83                                ...           2 years ago
  • 1.0.82                                ...           2 years ago
  • 1.0.81                                ...           3 years ago
  • 1.0.80                                ...           3 years ago
  • 1.0.79                                ...           3 years ago
  • 1.0.78                                ...           3 years ago
  • 1.0.77                                ...           3 years ago
  • 1.0.76                                ...           3 years ago
  • 1.0.75                                ...           3 years ago
  • 1.0.74                                ...           3 years ago
  • 1.0.73                                ...           3 years ago
  • 1.0.72                                ...           3 years ago
  • 1.0.71                                ...           3 years ago
  • 1.0.70                                ...           3 years ago
  • 1.0.69                                ...           3 years ago
  • 1.0.68                                ...           3 years ago
  • 1.0.67                                ...           3 years ago
  • 1.0.66                                ...           3 years ago
  • 1.0.65                                ...           3 years ago
  • 1.0.64                                ...           3 years ago
  • 1.0.63                                ...           3 years ago
  • 1.0.62                                ...           3 years ago
  • 1.0.61                                ...           3 years ago
  • 1.0.60                                ...           3 years ago
  • 1.0.59                                ...           3 years ago
  • 1.0.58                                ...           3 years ago
  • 1.0.57                                ...           3 years ago
  • 1.0.56                                ...           3 years ago
  • 1.0.55                                ...           3 years ago
  • 1.0.54                                ...           3 years ago
  • 1.0.53                                ...           3 years ago
  • 1.0.52                                ...           3 years ago
  • 1.0.51                                ...           3 years ago
  • 1.0.50                                ...           3 years ago
  • 1.0.49                                ...           3 years ago
  • 1.0.48                                ...           3 years ago
  • 1.0.47                                ...           3 years ago
  • 1.0.46                                ...           3 years ago
  • 1.0.45                                ...           3 years ago
  • 1.0.44                                ...           3 years ago
  • 1.0.43                                ...           3 years ago
  • 1.0.42                                ...           3 years ago
  • 1.0.41                                ...           3 years ago
  • 1.0.40                                ...           3 years ago
  • 1.0.39                                ...           3 years ago
  • 1.0.38                                ...           3 years ago
  • 1.0.37                                ...           3 years ago
  • 1.0.36                                ...           3 years ago
  • 1.0.35                                ...           3 years ago
  • 1.0.34                                ...           3 years ago
  • 1.0.33                                ...           3 years ago
  • 1.0.32                                ...           3 years ago
  • 1.0.31                                ...           3 years ago
  • 1.0.30                                ...           3 years ago
  • 1.0.29                                ...           3 years ago
  • 1.0.28                                ...           3 years ago
  • 1.0.27                                ...           3 years ago
  • 1.0.26                                ...           3 years ago
  • 1.0.25                                ...           3 years ago
  • 1.0.24                                ...           3 years ago
  • 1.0.23                                ...           3 years ago
  • 1.0.22                                ...           3 years ago
  • 1.0.21                                ...           3 years ago
  • 1.0.20                                ...           3 years ago
  • 1.0.19                                ...           3 years ago
  • 1.0.18                                ...           3 years ago
  • 1.0.17                                ...           3 years ago
  • 1.0.16                                ...           3 years ago
  • 1.0.15                                ...           3 years ago
  • 1.0.14                                ...           3 years ago
  • 1.0.13                                ...           3 years ago
  • 1.0.12                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 84
Dependencies (4)
Dev Dependencies (4)

Copyright 2014 - 2017 © taobao.org |