AssetUtils Factory

Defined in: lib/AssetUtils.js

A bunch of utilities for dealing with asset files.

Do not instantiate this factory directly, instead, use the compiler's instance.

Public Functions

StringgetAssetPath(String)
StringgetRelativeAssetPath(String)
voidwriteAsset(String, String|Buffer)
voidwriteTmpFile()
Array.<String>globAndFilter(String|Array.<String>, Array.<String>|Array.<RegExp>)

Instance Constructor Documentation

AssetUtils(config: Object)

Parameters (1)

config
Object

megadoc's runtime config.

Instance Method Documentation

    getAssetPath(relativePath: String) -> String

    Convert a relative asset path into an absolute path.

    Parameters (1)

    relativePath
    String

    Return Value

    String

    Example

    getAssetPath("doc/*.md");
    // => "/path/to/project/doc/*.md"

    getRelativeAssetPath(absolutePath: String) -> String

    Convert a full asset path into one relative to the asset root.

    Parameters (1)

    absolutePath
    String

    Return Value

    String

    Example

    getRelativeAssetPath("/path/to/project/doc/something.md");
    // => "doc/something.md"

    globAndFilter(sourcePatterns: String|Array.<String>, rawFilters: Array.<String>|Array.<RegExp>) -> Array.<String>

    Glob a bunch of (relative) source paths for files and optionally filter them.

    Parameters (2)

    sourcePatterns
    String|Array.<String>

    Minimatch-style patterns of source files. These paths are expected to be relative to the assetRoot. See AssetUtils#getAssetPath.

    rawFilters
    Array.<String>|Array.<RegExp>

    Patterns to filter the globbed file paths by.

    Return Value

    Array.<String>

    A list of matched files.

    writeAsset(fileName: String, contents: String|Buffer)

    Copy a local file into the destination output directory.

    Parameters (2)

    fileName
    String

    Relative path to the output file. For example, if this is a JS script you need to require, this will be relative to index.html.

    contents
    String|Buffer

    The contents of the file.

    writeTmpFile()

    Write some contents to an arbitrary temporary file and get a handle to its filepath.