Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assets-manager

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assets-manager

Copy packages files based on manifest file

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

assets-manager NPM version Build Status Dependency Status Coverage percentage

Assets manager provides a different approach to transfer the required files from your registry distributions to the target.

Installation

$ npm install --save assets-manager

Usage

import AssetsManager from 'assets-manager';

const assets = new AssetsManager('./manifest.json');

// copy all packages files to destination
assets.copyPackages();

// clean all packages files from destination
assets.cleanPackages();

// look all packages
assets.forEachPackage(function(pkg){

});

// loop all js files in the packages
assets.forEachPackage('js', function(pkg, files){

});

Registries

Assets manager can work with different package manager like npm, bower. Also It can use custom folders.

Just defined the registries in the manifest.json.

"registries": {
  "vendor": "path-to-vendor",
  "libs": "path-to-lib"
}

Global options

cwd

The relative path to the root of the project. Defaults to the manifest.json directory.

flattenPackages

Whether to remove all package path parts from generated dest paths. Defaults to true.

flattenTypes

Whether to remove all type path parts from generated dest paths. Defaults to false.

verbose

Whether to console log copy and clean files. Defaults to true.

override

Whether to override old exists destination files. Defaults to true.

defaultRegistry

Set default registry when package dont have a registry specify. Defaults to npm.

types

Set types that assets manage will classicfy files automatically.

Defaults:

{
  js: '*.js',
  coffee: '*.coffee',
  es6: '*.es6.js',
  css: '*.css',
  stylus: '*.styl',
  scss: '*.scss',
  sass: '*.sass',
  less: '*.less',
  images: '*.{bmp,jpg,jpeg,png,gif,webp,tiff,wbmp,eps}',
  fonts: '*.{eot,otf,svg,ttc,ttf,woff,woff2}'
}

Packages

Package key

The package key in the manifest.json take the following form:

"registry:package"
"registry:package@version"
"package"
"package@version"

The "package" and "package@version" shorter form will use the default registry.

The name of the dependency in the package can be any custom alias, that is then only locally scoped to that specific package.

Typically semver-compatible versions should be used of the form ^x.y.z. Tilde ranges, ~x.y.z are also supported. Ranges without a patch or minor are also supported - x, x.y, ~x.y, ^x.y.

More info about versions: https://docs.npmjs.com/getting-started/semantic-versioning https://github.com/npm/node-semver#ranges

Package definition

You can write in the following ways define the package.

  1. simple mode
"PACKAGEKEY": true

It will use default types config and use default options.

  1. use options only
"PACKAGEKEY": [
  true,
  {
    "registry": "bower"
  }
]

It will use default types config and custom options.

  1. use types only
"PACKAGEKEY": [{
  "js": "dist/js",
  "css": "dist/css"
}]

It will use custom types config and default options.

  1. use types only alternatively
"PACKAGEKEY": {
  "js": "dist/js",
  "css": "dist/css"
}
  1. use types and options
"PACKAGEKEY": [
  {
    "js": "dist/js",
    "css": "dist/css"
  },
  {
    "registry": "bower"
  }
]

It will use custom types config and custom options.

Types config in the package definition

  1. Simple path mapping
{
  js: 'path-to-js',
  css: 'path-to-css'
}
  1. Glob support
{
  js: '*.js',
  css: 'css/*.css'
}
  1. Array support
{
  js: ['a.js', 'b.js'],
  css: ['css/*.css', '!css/*.min.css']
}
  1. You can rename the files
js: {
  'bootstrap.js': 'dist/js/bootstrap.js'
},
css: {
  'main.css':'dist/css/bootstrap.css',
  'theme.css':'dist/css/bootstrap-theme.css'
}

Package options

defaults
{
  flattenPackages: true,
  flattenTypes: false,
  verbose: true,
  override: true,
  main: false,
  registry: 'npm'
}
clean, flattenPackages, flattenTypes, registry

These options will override the global options.

main

Set to true will use bower/npm's main files.

Hooks

Assets manager provides 2 separate hooks that can be used to trigger other automated tools during assets copy operate.

"hook:pre": "<your command here>",
"hook:post": "<your command here>",

Example manifest.json

{
  "cwd": "./",
  "registries": {
    "vendor": "libs"
  },
  "defaultRegistry": "npm",
  "verbose": true,
  "override": true,
  "flattenPackages": true,
  "flattenTypes": false,
  "dest": "assets",
  "dests": {
    "images": "images",
    "fonts": "fonts",
    "js": "js",
    "coffee": "source/coffee",
    "es6": "source/es6",
    "css": "css",
    "stylus": "source/stylus",
    "less": "source/less",
    "sass": "source/sass",
    "scss": "source/scss"
  },
  "packages": {
    "bower:jquery": true,
    "npm:bootstrap": [{
      "js": "dist/js",
      "css": "dist/css",
      "less": "less",
      "fonts": "dist/fonts"
    }],
    "vendor:modernizr": {
        "modernizr.js": "dist/modernizr.min.js",
    }
  }
}

License

MIT © amazingSurge

Keywords

FAQs

Package last updated on 13 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc