sprity-dirs
apply sprity to multiple directories and generate multiple sprites and css
Last updated 5 years ago by zoubin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sprity-dirs 
SYNC missed versions from official npm registry.

sprity-dirs

Apply sprity to multiple directories and generate seperate sprite and css for each directory.

Example

var sprityDir = require('sprity-dirs');
sprityDir('src/*', 'build')
  .then(function () {
    console.log('done');
  })
  .catch(function (er) {
    console.log(er);
  })
;
var sprityDir = require('sprity-dirs');
var opts = {
  to: 'build'
};
sprityDir('src/*', opts)
  .then(function () {
    console.log('done');
  })
  .catch(function (er) {
    console.log(er);
  })
;
;
var sprityDir = require('sprity-dirs');
var path = require('path');
sprityDir('src/*', function (dir) {
  var name = path.basename(dir);
  return {
    out: path.resolve(__dirname, 'build', name),
    prefix: 'sp-' + name,
    style: './index.css',
    name: name,
    cssPath: '.',
  };
})
.then(function () {
  console.log('done');
})
.catch(function (er) {
  console.log(er);
})
;
⌘ tree src/
src/
├── delivery
│   ├── address_36.png
│   ├── mobile_36.png
│   ├── taketime_36.png
│   └── user_36.png
└── icon
    ├── cart_36.png
    ├── category_36.png
    ├── checked_40.png
    ├── close_30.png
    ├── disable_40.png
    ├── failure_66.png
    ├── message_30.png
    ├── success_66.png
    └── unchecked_40.png

output:

⌘ tree build/
build/
├── delivery
│   ├── delivery.png
│   └── index.css
└── icon
    ├── icon.png
    └── index.css

Api Usage

sprityDir(dirPattern, opts)

Returns a promise.

dirPattern

Type: String, Array

Pattern used by xglob to locate the directories, each corresponding to a sprite with all pics in it. Actually, anything that matches the pattern but not a directory will be ignored.

opts

Type: Function, Object, String

When Function, it receives the dir path, and should return a sprity option object to generate the sprite. No need to specify src.

When String, it indicates the directory where all the output sprites directories lie.

When Object, it should be sprity option common for all sprites, with the following default values:

  • out. For each sprite, it will be path.resolve(options.to, dirName)
  • prefix. sp-{dirName}
  • style. ./index.css
  • name. {dirname}
  • cssPath. .

Command Line Usage

Right now you can only specify the source directories and the output root.

npm i sprity-dirs -g
sprity-dirs src/* build

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

3 Versions

  • 1.0.0                                ...           5 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 2
Dependencies (5)
Dev Dependencies (4)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |