Skip to content
This repository has been archived by the owner on Nov 13, 2017. It is now read-only.

Commit

Permalink
feat(options): Add export=false option
Browse files Browse the repository at this point in the history
  • Loading branch information
birhoff committed Apr 3, 2017
1 parent 5073fe6 commit 7ae75df
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Yields:

#### `options`

##### *String* exportType - determinate how to export bemjson. Default: `commonJS`
##### *string* exportType - determinate how to export bemjson. Default: `commonJS`

Value | Description
-----------|------------
Expand All @@ -78,7 +78,9 @@ Value | Description
`YModules` | Exports to [YModules](https://github.com/ymaps/modules). *Requires* exportName.
`no export`| Don't do any export. Just plain `JSON.stringify`.

##### *String* exportName - export bemjson with given name when use `modules`, `umd` or `YModules`.
##### *string* exportName - export bemjson with given name when use `modules`, `umd` or `YModules`.

##### *boolean* export - if `false` don't generate export. Default: `true`

##### *Function* augment - callback called on every node. [Signature](https://github.com/birhoff/mdast-util-to-bemjson#augmentbemnodebemnode-important-must-return-bemnode). Option passed to [`mdast-util-to-bemjson`](https://github.com/birhoff/mdast-util-to-bemjson).

Expand Down
3 changes: 2 additions & 1 deletion lib/defaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

module.exports = {
exportType: 'commonJS'
exportType: 'commonJS',
'export': true
};
2 changes: 2 additions & 0 deletions lib/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const ExportType = {
* @returns {String}
*/
function createExport(exportOptions, content) {
if (!content) return content;

const type = exportOptions.type;
const name = exportOptions.name;
const exportFunction = exportFabric(type);
Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function plugin(options) {
function compiler(node, file) {
const root = node && node.type && node.type === 'root';
const bemjson = toBemjson(node, { augment: options.augment });
const bjsonString = JSON.stringify(bemjson, null, 4);

const bjsonString = options.export ? JSON.stringify(bemjson, null, 4) : '';

if (file.extname) {
file.extname = '.js';
Expand All @@ -32,6 +33,8 @@ function plugin(options) {
file.stem = file.stem + '.bemjson';
}

file.data = bemjson;

return root ? createExport({ type: options.exportType, name: options.exportName }, bjsonString) : bjsonString;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ describe('remark-bemjson()', () => {

expect(bjsonFile.basename).to.equal('example.bemjson.js');
});

it('should not generate content with export=false', () => {
const file = vFile({ path: '~/example.md', contents: 'Alpha *braavo* charlie.' });
file.extname = '.md';

const bjsonFile = remark().use(bemjson, { 'export': false }).processSync(file);

expect(bjsonFile.data).to.have.property('block', 'md-root');
expect(bjsonFile.toString()).to.equal('');
});
});

0 comments on commit 7ae75df

Please sign in to comment.