0.1.3 • Published 5 years ago

package-assets v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Package Assets

Build Status NpmLicense

Conveniently handle static assets in your node package.

Installation

npm install package-assets

Usage

To get started:

const PackageAssets = require('package-assets');

//set asset directory
const assets = PackageAssets('config');

.readAssetFile

Reads an asset file from the asset directory.

assets.readAsset('configFile.json')
.then((result) => {
    return JSON.parse(result);
})
.catch(err => console.log(err));
.readAssetFile(path)

path the relative path from the asset root of the project

.writeAsset

Writes a string or buffer out to the asset file.

var string = "Hello Package Assets!";
assets.write("hello.txt", string)
.then(success => console.log(success));
.writeAsset(fileName, fileContent)

fileName (required) the file name in which to save your asset content, under the asset path.
fileContent (optional) the file content to save.

.copyAssetDir

Copies the asset directory to the current working directory. Takes an optional argument dest.

assets.copyAssetDir()
.then((result) => {
    console.log(result.length);
})
.catch(err => console.log(err));
.copyAssetDir(dest)

dest an optional destination directory name to copy the asset resources to within the current working directory. By default assets will just be unpacked from the source directory directly into the working directory.

.resolveAssetDir

Resolves the full file path of the asset directory in your given package.

var path = assets.resolveAssetDir()

console.log(path);

.setAssetDir

Setter method for the asset directory on the PackageAssets object.

var success = assets.setAssetDir('my/new/assets/dir');

console.log(success);
.setAssetDir(path)

path an required asset directory relative to package root.

License

This package has an MIT license, see LICENSE for the the full text.

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago