Skip to content

Commit

Permalink
Add save method
Browse files Browse the repository at this point in the history
  • Loading branch information
belozer committed Jan 26, 2017
1 parent ad91d23 commit fea9834
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
parse: require('./parse'),
assign: require('./assign'),
load: require('./load'),
stringify: require('./stringify')
stringify: require('./stringify'),
save: require('./save')
};
26 changes: 26 additions & 0 deletions lib/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const fs = require('fs');
const promisify = require('es6-promisify');
const stringify = require('./stringify');

const writeFile = promisify(fs.writeFile);

/**
* Save normalized declaration to target format
*
* @param {String} filename Filename for save declaration
* @param {BemCell[]} cells Normalized declaraions
* @param {Object} opts Addtional options
* @param {String} opts.format Format for save declaration
* @param {String} opts.exportType The appointment of a modular system
* @returns {Promise.<void>}
*/
module.exports = (filename, cells, opts) => {
const data = stringify(cells, Object.assign({
format: 'v2',
exportType: 'cjs'
}, opts));

return writeFile(data)
}

0 comments on commit fea9834

Please sign in to comment.