Skip to content

Commit

Permalink
annotation function
Browse files Browse the repository at this point in the history
Function in annotation of source map options will be working properly
  • Loading branch information
Ser-Gen committed Dec 29, 2015
1 parent 4f9ab08 commit f470fca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,32 @@ function generateDataFile (css, opts) {
};
};

var dataOpts = {
to: (typeof opts.dest.path === 'function') ? opts.dest.path(opts) : opts.dest.path
};

// если нет информации о карте кода
if (!opts.dest.map) {
opts.dest.map = false;
}

// если информация есть
else {
dataOpts.map = opts.dest.map;

// если есть информация о положении карты кода
if (opts.dest.map.annotation) {

// информация может возвращаться функцией
// а при генерации нужна строка
dataOpts.map.annotation = (typeof opts.dest.map.annotation === 'function') ? opts.dest.map.annotation(dataOpts, opts) : opts.dest.map.annotation;

// разделители должны быть универсальными
dataOpts.map.annotation = dataOpts.map.annotation.replace(new RegExp('\\' + path.sep, 'g'), '/');
};
};

var data = dataCSS.toResult({
to: (typeof opts.dest.path === 'function') ? opts.dest.path(opts) : opts.dest.path,
map: opts.dest.map
});
var data = dataCSS.toResult(dataOpts);

if (!data.css.length) return;

Expand Down Expand Up @@ -243,12 +261,7 @@ function getMapPath (dataOpts, opts) {
var result;

if (dataOpts.map.annotation) {
if (typeof dataOpts.map.annotation === 'function') {
result = dataOpts.map.annotation(dataOpts, opts);
}
else {
result = path.join(path.dirname(dataOpts.to), dataOpts.map.annotation);
};
result = path.join(path.dirname(dataOpts.to), dataOpts.map.annotation);
}
else {
result = dataOpts.to +'.map';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-data-packer",
"version": "1.2.1",
"version": "1.2.2",
"description": "PostCSS plugin to move an embedded data into a separate file",
"keywords": [
"css",
Expand Down

0 comments on commit f470fca

Please sign in to comment.