0.10.8 • Published 2 years ago

@asset-toolkit/core v0.10.8

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

@asset-toolkit/core / Exports

@asset-toolkit/core

Table of contents

Variables

Functions

Variables

removeDir

Const removeDir: any

Defined in

index.d.ts:1

Functions

changeExtension

Const changeExtension(file, extension): string

Parameters

NameType
filestring
extensionstring

Returns

string

Defined in

index.d.ts:22


checkFileExt

Const checkFileExt(file, exts): boolean

Parameters

NameType
filestring
extsstring[]

Returns

boolean

Defined in

index.d.ts:8


copyFiles

Const copyFiles(pathIn, pathOut, exts?): void

Parameters

NameType
pathInstring
pathOutstring
exts?string[]

Returns

void

Defined in

index.d.ts:9


getUID

Const getUID(size): any

Parameters

NameType
sizenumber

Returns

any

Defined in

index.d.ts:11


logger

Const logger(): Object

Returns

Object

NameType
error(value: any) => any
info(value: any) => any
start(value: any) => any
success(value: any) => any

Defined in

index.d.ts:2


pipeline

Const pipeline(...fns): (props: any, options: any[], callback?: any[]) => any

Parameters

NameType
...fnsany

Returns

fn

▸ (props, options, callback?): any

Parameters
NameType
propsany
optionsany[]
callback?any[]
Returns

any

Defined in

index.d.ts:12


prepareOutputDir

Const prepareOutputDir(pathOut, exts): void

Parameters

NameType
pathOutstring
extsstring[]

Returns

void

Defined in

index.d.ts:10


watchPipeline

Const watchPipeline(pipeline, props, options?, callback?): void

Parameters

NameType
pipelineany
propsObject
props.pathInstring
props.pathOutstring
options?any[]
callback?any[]

Returns

void

Defined in

index.d.ts:13

Asset ToolKits

Node.js toolkits to optimize media assets.

Use a pipeline

A pipe function to concatenate toolkits.

const { pipeline } = require('@asset-toolkit/core')

const pipelineExample = pipeline(...fn)

pipelineExample({
  pathIn: './exampleIn/',
  pathOut: '../../exampleOut/',
})

Example with pipeline

With audio-sprite and json-minify tools. Use the function returned from pipeline to pass props and options.

The options is an array of object. Every object is linked to tools function passed to pipeline by our order.

npm i
@asset-toolkit/core
@asset-toolkit/audio-sprite
@asset-toolkit/json-minify
const { pipeline } = require('@asset-toolkit/core')
const audioSprite = require('@asset-toolkit/audio-sprite')
const jsonMinify = require('@asset-toolkit/json-minify')
const options = [
  {
    output: 'spriteTrack',
    export: 'mp3, m4a',
  },
] // first argument for first tool in pipeline

const pipelineAudio = pipeline(audioSprite, jsonMinify)

pipelineAudio(
  {
    pathIn: './audio/',
    pathOut: '../public/audio',
  },
  options,
)

Example with watcher

For relaunch automatically your pipeline everytime you add or modify the files in input folder.

const { pipeline, watchPipeline } = require('@asset-toolkit/core')
const jsonMinify = require('@asset-toolkit/json-minify')
const options = [
  {
    output: 'spriteTrack',
    export: 'mp3, m4a',
  },
] // first argument for first tool in pipeline

const pipelineJSON = pipeline(jsonMinify)

watchPipeline(pipelineJSON, {
  pathIn: './json/',
  pathOut: '../public/json',
})

How to use

Create a js file "example.js", with your code (import and configure the pipelines like examples).

Run your code with node: node example.js

License

MIT