2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-15 11:59:37 +03:00

refactor(*): convert to babel and generation to lib, es, dist folders (#2)

* refactor(*): convert to babel and generation to lib, es, dist

* chore(*): remove generated files

* fix(*): lint run command
This commit is contained in:
Nikolay Kostyurin
2018-09-09 23:55:28 +02:00
committed by GitHub
parent d22a2895a4
commit 32a7fb51da
76 changed files with 930 additions and 10174 deletions
+86
View File
@@ -0,0 +1,86 @@
{
"presets": [
"react"
],
"plugins": [
"transform-decorators-legacy",
[
"transform-es2015-template-literals",
{
"loose": true
}
],
"transform-es2015-literals",
"transform-es2015-function-name",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
[
"transform-es2015-classes",
{
"loose": true
}
],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
[
"transform-es2015-computed-properties",
{
"loose": true
}
],
[
"transform-es2015-for-of",
{
"loose": true
}
],
"transform-es2015-sticky-regex",
"transform-es2015-unicode-regex",
"check-es2015-constants",
[
"transform-es2015-spread",
{
"loose": true
}
],
"transform-es2015-parameters",
[
"transform-es2015-destructuring",
{
"loose": true
}
],
"transform-es2015-block-scoping",
"transform-object-rest-spread",
"transform-react-jsx",
"syntax-jsx"
],
"env": {
"test": {
"plugins": [
[
"transform-es2015-modules-commonjs",
{
"loose": true
}
]
]
},
"commonjs": {
"plugins": [
[
"transform-es2015-modules-commonjs",
{
"loose": true
}
]
]
},
"rollup": {
"plugins": [
"external-helpers"
]
}
}
}
-9822
View File
File diff suppressed because it is too large Load Diff
+20 -4
View File
@@ -1,9 +1,9 @@
{
"scripts": {
"bootstrap": "lerna bootstrap",
"test": "lerna run test",
"test": "lerna run build && lerna run link && lerna run test",
"cover": "lerna run cover",
"lint": "lerna run lint"
"lint": "lerna run build && lerna run link && lerna run lint"
},
"author": {
"name": "Nikolay Kostyurin",
@@ -11,23 +11,36 @@
},
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-jest": "^23.4.2",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"benchmark": "^2.1.4",
"cross-env": "^5.2.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.9.1",
"husky": "^0.14.3",
"jest": "^23.1.0",
"jsdoc-to-markdown": "^4.0.1",
"lerna": "^2.11.0",
"lint-staged": "^7.2.2",
"microtime": "^2.1.8",
"posthtml-render": "^1.1.4",
"rollup": "^0.62.0",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^5.0.2",
"size-limit": "^0.18.5",
"xbbcode-parser": "^0.1.2"
},
@@ -38,5 +51,8 @@
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverage": true
},
"dependencies": {
"babel-plugin-transform-object-rest-spread": "^6.26.0"
}
}
+2
View File
@@ -1,2 +1,4 @@
dist
es
lib
test
+2
View File
@@ -1,2 +1,4 @@
dist
es
lib
test
+3 -1
View File
@@ -1,3 +1,5 @@
package-lock.json
coverage
dist
dist
lib
es
+2 -1
View File
@@ -1,6 +1,7 @@
package-lock.json
coverage
src
dist
!dist
!lib
!es
*.test.js
+2 -1
View File
@@ -4,10 +4,11 @@
```js
const bbob = require('@bbob/core');
const render = require('@bbob/html');
const presetHTML5 = require('@bbob/preset-html5');
const code = `[i]Text[/i]`;
const html = bbob([presetHTML5()]).process(code).html;
const html = bbob([presetHTML5()]).process(code, { render }).html;
console.log(html); // <span style="font-style: italic;">Text</span>
```
+53 -21
View File
@@ -1,40 +1,72 @@
{
"name": "@bbob/core",
"version": "1.1.0",
"description": "BBob is a tool to transform BBCode markup useing presets",
"main": "lib/index.js",
"directories": {
"lib": "lib"
},
"dependencies": {
"@bbob/html": "^1.1.0",
"@bbob/parser": "^1.2.0"
},
"peerDependencies": {
"@bbob/preset-html5": "^1.x"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JiLiZART/bbob.git"
},
"description": "Fast, flexible, and lean implementation of BBcode parser with plugins",
"keywords": [
"bbcode",
"parser",
"fast",
"bbcode parser",
"bbcodeparser",
"bbob",
"serializer",
"bbcode serializer",
"bbcode serializer",
"bbcodeserializer",
"parse",
"serialize",
"html",
"transform"
],
"dependencies": {
"@bbob/parser": "^1.2.0"
},
"devDependencies": {
"@bbob/html": "^1.x"
},
"peerDependencies": {
"@bbob/html": "^1.x",
"@bbob/preset-html5": "^1.x",
"@bbob/react": "^1.x",
"@bbob/preset-react": "^1.x"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobCore",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"homepage": "https://github.com/JiLiZART/bbob#readme",
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint ."
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
@@ -1,13 +1,11 @@
const parser = require('@bbob/parser');
const render = require('@bbob/html');
const { iterate, match } = require('./utils');
import { parse } from '@bbob/parser';
import { iterate, match } from './utils';
function walk(cb) {
return iterate(this, cb);
}
module.exports = function bbob(plugs) {
export default function bbob(plugs) {
const plugins = typeof plugs === 'function' ? [plugs] : plugs || [];
let options = {
@@ -18,8 +16,8 @@ module.exports = function bbob(plugs) {
process(input, opts) {
options = opts || {};
const parseFn = options.parser || parser;
const renderFn = options.render || render;
const parseFn = options.parser || parse;
const renderFn = options.render;
let tree = options.skipParse
? input || []
@@ -39,6 +37,9 @@ module.exports = function bbob(plugs) {
return {
get html() {
if (typeof renderFn !== 'function') {
throw new Error('"render" function not defined, please pass to "process(input, { render })"');
}
return renderFn(tree, tree.options);
},
tree,
@@ -46,4 +47,4 @@ module.exports = function bbob(plugs) {
};
},
};
};
}
@@ -59,7 +59,7 @@ function match(expression, cb) {
: iterate(this, node => (same(expression, node) ? cb(node) : node));
}
module.exports = {
export {
iterate,
match,
};
+7 -4
View File
@@ -1,10 +1,13 @@
const core = require('../lib');
import render from '@bbob/html'
import core from '../src'
const stringify = val => JSON.stringify(val);
const process = (plugins, input) => core(plugins).process(input, { render });
describe('@bbob/core', () => {
test('parse bbcode string to ast and html', () => {
const res = core().process('[style size="15px"]Large Text[/style]');
const res = process([], '[style size="15px"]Large Text[/style]');
const ast = res.tree;
expect(res.html).toBe(`<style size="15px">Large Text</style>`);
@@ -31,7 +34,7 @@ describe('@bbob/core', () => {
return node
});
const res = core([testPlugin()]).process('[mytag size="15px"]Large Text[/mytag]');
const res = process([testPlugin()], '[mytag size="15px"]Large Text[/mytag]');
const ast = res.tree;
expect(ast).toBeInstanceOf(Array);
@@ -61,7 +64,7 @@ describe('@bbob/core', () => {
return node
});
const res = core([testPlugin()]).process(`[mytag1 size="15"]Tag1[/mytag1][mytag2 size="16"]Tag2[/mytag2][mytag3]Tag3[/mytag3]`);
const res = process([testPlugin()], `[mytag1 size="15"]Tag1[/mytag1][mytag2 size="16"]Tag2[/mytag2][mytag3]Tag3[/mytag3]`);
const ast = res.tree;
expect(ast).toBeInstanceOf(Array);
+1 -1
View File
@@ -1,4 +1,4 @@
const { iterate } = require('../lib/utils');
import { iterate } from '../src/utils';
describe('@bbob/core utils', () => {
test('iterate', () => {
+2
View File
@@ -1,2 +1,4 @@
dist
es
lib
test
+3 -1
View File
@@ -1,3 +1,5 @@
package-lock.json
coverage
dist
dist
lib
es
+2 -1
View File
@@ -1,6 +1,7 @@
package-lock.json
coverage
src
dist
!dist
!lib
!es
*.test.js
+37 -7
View File
@@ -2,21 +2,51 @@
"name": "@bbob/html",
"version": "1.1.0",
"description": "HTML renderer for BBCode pareser BBob",
"main": "lib/index.js",
"keywords": [],
"dependencies": {
"@bbob/plugin-helper": "^1.1.0"
},
"devDependencies": {
"@bbob/parser": "^1.2.0"
},
"scripts": {
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint ."
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobHtml",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
@@ -43,4 +43,5 @@ const renderNodes = (nodes, { stripTags = false } = {}) => []
.concat(nodes)
.reduce((r, node) => r + renderNode(node, { stripTags }), '');
module.exports = renderNodes;
export const render = renderNodes;
export default renderNodes;
+11 -5
View File
@@ -1,14 +1,20 @@
const render = require('../lib/index');
const parse = require('@bbob/parser');
import {parse} from '@bbob/parser'
import {render} from '../src';
const process = (input, params) => render(parse(input), params);
const process = (input, params) => {
const ast = parse(input);
const html = render(ast, params);
return html
};
describe('@bbob/html', () => {
test('render bbcode tag with single param as html tag', () => {
const input = '[url=https://ru.wikipedia.org]Text[/url]';
const result = '<url url="https://ru.wikipedia.org">Text</url>';
const expected = '<url url="https://ru.wikipedia.org">Text</url>';
const result = process(input)
expect(process(input)).toBe(result);
expect(result).toBe(expected);
});
test('render bbcode tag with multiple params as html tag', () => {
+2 -1
View File
@@ -1,3 +1,4 @@
dist
es
lib
test
rollup.config.js
+3 -1
View File
@@ -1,3 +1,5 @@
package-lock.json
coverage
dist
dist
lib
es
+2 -1
View File
@@ -1,6 +1,7 @@
package-lock.json
coverage
src
dist
!dist
!lib
!es
*.test.js
-1
View File
@@ -1 +0,0 @@
module.exports = require('./parse');
+24 -16
View File
@@ -1,41 +1,46 @@
{
"name": "@bbob/parser",
"version": "1.3.0",
"description": "Fast, flexible, and lean implementation of BBcode parser",
"homepage": "https://github.com/JiLiZART/bbob",
"description": "Just parses BBcode to AST array",
"keywords": [
"bbcode",
"parser",
"fast",
"ast",
"bbcode parser",
"bbcodeparser",
"bbob",
"serializer",
"bbcode serializer",
"bbcode serializer",
"bbcodeserializer",
"parse",
"serialize",
"html"
"array",
"parse"
],
"main": "lib/index.js",
"dependencies": {
"@bbob/plugin-helper": "^1.1.0"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobParser",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build": "../../node_modules/.bin/rollup -c",
"dev": "../../node_modules/.bin/rollup -c -w",
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"size-limit": [
{
"path": "lib/index.js"
@@ -45,6 +50,9 @@
"registry": "https://registry.npmjs.org/"
},
"files": [
"lib"
"dist",
"lib",
"src",
"es"
]
}
-33
View File
@@ -1,33 +0,0 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import pkg from './package.json';
export default [
// browser-friendly UMD build
{
input: 'lib/index.js',
output: {
name: 'BBobParser',
file: pkg.browser,
format: 'umd',
},
plugins: [
resolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
],
},
// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the output` option, where we can specify
// `file` and `format` for each target)
{
input: 'lib/index.js',
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' },
],
},
];
@@ -1,9 +1,8 @@
const {
getChar,
import {
OPEN_BRAKET,
CLOSE_BRAKET,
SLASH,
} = require('@bbob/plugin-helper/lib/char');
} from '@bbob/plugin-helper/lib/char';
// type, value, line, row,
const TOKEN_TYPE_ID = 'type'; // 0;
@@ -28,7 +27,7 @@ const isTextToken = token =>
token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
const isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
const isTagEnd = token => getTokenValue(token).charCodeAt(0) === SLASH;
const isTagEnd = token => getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0);
const isTagStart = token => !isTagEnd(token);
const isAttrNameToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
const isAttrValueToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
@@ -40,14 +39,14 @@ const getTagName = (token) => {
};
const convertTagToText = (token) => {
let text = getChar(OPEN_BRAKET);
let text = OPEN_BRAKET;
if (isTagEnd(token)) {
text += getChar(SLASH);
text += SLASH;
}
text += getTokenValue(token);
text += getChar(CLOSE_BRAKET);
text += CLOSE_BRAKET;
return text;
};
@@ -109,15 +108,15 @@ class Token {
}
}
module.exports = Token;
module.exports.TYPE_ID = TOKEN_TYPE_ID;
module.exports.VALUE_ID = TOKEN_VALUE_ID;
module.exports.LINE_ID = TOKEN_LINE_ID;
module.exports.COLUMN_ID = TOKEN_COLUMN_ID;
module.exports.TYPE_WORD = TOKEN_TYPE_WORD;
module.exports.TYPE_TAG = TOKEN_TYPE_TAG;
module.exports.TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME;
module.exports.TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE;
module.exports.TYPE_SPACE = TOKEN_TYPE_SPACE;
module.exports.TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE;
export const TYPE_ID = TOKEN_TYPE_ID;
export const VALUE_ID = TOKEN_VALUE_ID;
export const LINE_ID = TOKEN_LINE_ID;
export const COLUMN_ID = TOKEN_COLUMN_ID;
export const TYPE_WORD = TOKEN_TYPE_WORD;
export const TYPE_TAG = TOKEN_TYPE_TAG;
export const TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME;
export const TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE;
export const TYPE_SPACE = TOKEN_TYPE_SPACE;
export const TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE;
export { Token };
export default Token;
+1
View File
@@ -0,0 +1 @@
export { parse, createTagNode } from './parse';
@@ -1,16 +1,17 @@
/* eslint-disable no-plusplus,no-param-reassign */
const c = require('@bbob/plugin-helper/lib/char');
const Token = require('./Token');
import {
OPEN_BRAKET,
CLOSE_BRAKET,
QUOTEMARK,
BACKSLASH,
SLASH,
SPACE,
TAB,
EQ,
N,
} from '@bbob/plugin-helper/lib/char';
const OPEN_BRAKET = c.getChar(c.OPEN_BRAKET);
const CLOSE_BRAKET = c.getChar(c.CLOSE_BRAKET);
const QUOTEMARK = c.getChar(c.QUOTEMARK);
const BACKSLASH = c.getChar(c.BACKSLASH);
const SLASH = c.getChar(c.SLASH);
const SPACE = c.getChar(c.SPACE);
const TAB = c.getChar(c.TAB);
const EQ = c.getChar(c.EQ);
const N = c.getChar(c.N);
import { Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD } from './Token';
const RESERVED_CHARS = [CLOSE_BRAKET, OPEN_BRAKET, QUOTEMARK, BACKSLASH, SPACE, TAB, EQ, N];
const NOT_CHAR_TOKENS = [OPEN_BRAKET, SPACE, TAB, N];
@@ -111,9 +112,9 @@ function createLexer(buffer, options = {}) {
tagName = attrStr;
} else if (isWhiteSpace(attrCharGrabber.getCurr()) || !attrCharGrabber.hasNext()) {
const escaped = unquote(trimChar(attrStr, QUOTEMARK));
attrTokens.push(createToken(Token.TYPE_ATTR_VALUE, escaped, row, col));
attrTokens.push(createToken(TYPE_ATTR_VALUE, escaped, row, col));
} else {
attrTokens.push(createToken(Token.TYPE_ATTR_NAME, attrStr, row, col));
attrTokens.push(createToken(TYPE_ATTR_NAME, attrStr, row, col));
}
attrCharGrabber.skip();
@@ -136,37 +137,37 @@ function createLexer(buffer, options = {}) {
col = 0;
row++;
emitToken(createToken(Token.TYPE_NEW_LINE, char, row, col));
emitToken(createToken(TYPE_NEW_LINE, char, row, col));
} else if (isWhiteSpace(char)) {
const str = grabber.grabWhile(isWhiteSpace);
emitToken(createToken(Token.TYPE_SPACE, str, row, col));
emitToken(createToken(TYPE_SPACE, str, row, col));
} else if (char === OPEN_BRAKET) {
const nextChar = grabber.getNext();
grabber.skip(); // skip [
if (isCharReserved(nextChar)) {
emitToken(createToken(Token.TYPE_WORD, char, row, col));
emitToken(createToken(TYPE_WORD, char, row, col));
} else {
const str = grabber.grabWhile(val => val !== CLOSE_BRAKET);
grabber.skip(); // skip ]
if (!(str.indexOf(EQ) > 0) || str[0] === SLASH) {
emitToken(createToken(Token.TYPE_TAG, str, row, col));
emitToken(createToken(TYPE_TAG, str, row, col));
} else {
const parsed = parseAttrs(str);
emitToken(createToken(Token.TYPE_TAG, parsed.tag, row, col));
emitToken(createToken(TYPE_TAG, parsed.tag, row, col));
parsed.attrs.map(emitToken);
}
}
} else if (char === CLOSE_BRAKET) {
grabber.skip();
emitToken(createToken(Token.TYPE_WORD, char, row, col));
emitToken(createToken(TYPE_WORD, char, row, col));
} else if (isCharToken(char)) {
const str = grabber.grabWhile(isCharToken);
emitToken(createToken(Token.TYPE_WORD, str, row, col));
emitToken(createToken(TYPE_WORD, str, row, col));
}
};
@@ -191,5 +192,5 @@ function createLexer(buffer, options = {}) {
};
}
module.exports = createLexer;
module.exports.createTokenOfType = createToken;
export const createTokenOfType = createToken;
export { createLexer };
@@ -1,5 +1,5 @@
const createLexer = require('./lexer');
const TagNode = require('@bbob/plugin-helper/lib/TagNode');
import TagNode from '@bbob/plugin-helper/lib/TagNode';
import { createLexer } from './lexer';
/**
* @private
@@ -227,5 +227,5 @@ const parse = (input, opts = {}) => {
return nodes;
};
module.exports = parse;
module.exports.createTagNode = createTagNode;
export { createTagNode, parse };
export default parse;
+3 -3
View File
@@ -1,5 +1,5 @@
const Token = require('../lib/Token');
const lexer = require('../lib/lexer');
const Token = require('../src/Token');
const { createLexer } = require('../src/lexer');
const TYPE = {
WORD: Token.TYPE_WORD,
@@ -10,7 +10,7 @@ const TYPE = {
NEW_LINE: Token.TYPE_NEW_LINE,
};
const tokenize = input => (lexer(input).tokenize());
const tokenize = input => (createLexer(input).tokenize());
describe('lexer', () => {
const expectOutput = (output, tokens) => {
+1 -1
View File
@@ -1,4 +1,4 @@
const parse = require('../lib/parse');
import { parse } from '../src'
describe('Parser', () => {
test('parse paired tags tokens', () => {
+2 -2
View File
@@ -1,5 +1,5 @@
const render = require('posthtml-render');
const parse = require('../lib');
import {parse} from '../src'
import render from 'posthtml-render'
describe('posthtml-render', () => {
@@ -1,2 +1,4 @@
dist
es
lib
test
+5
View File
@@ -0,0 +1,5 @@
package-lock.json
coverage
dist
lib
es
+7
View File
@@ -0,0 +1,7 @@
package-lock.json
coverage
src
!dist
!lib
!es
*.test.js
@@ -1,40 +0,0 @@
const {
getChar, OPEN_BRAKET, CLOSE_BRAKET, SLASH,
} = require('./char');
const { getNodeLength, appendToNode } = require('./index');
class TagNode {
constructor(tag, attrs, content) {
this.tag = tag;
this.attrs = attrs;
this.content = content;
}
attr(name, value) {
if (typeof value !== 'undefined') {
this.attrs[name] = value;
}
return this.attrs[name];
}
append(value) {
return appendToNode(this, value);
}
get length() {
return getNodeLength(this);
}
toString() {
const OB = getChar(OPEN_BRAKET);
const CB = getChar(CLOSE_BRAKET);
const SL = getChar(SLASH);
return OB + this.tag + CB + this.content.reduce((r, node) => r + node.toString(), '') + OB + SL + this.tag + CB;
}
}
module.exports = TagNode;
module.exports.create = (tag, attrs = {}, content = []) => new TagNode(tag, attrs, content);
module.exports.isOf = (node, type) => (node.tag === type);
-36
View File
@@ -1,36 +0,0 @@
const N = '\n'.charCodeAt(0);
const TAB = '\t'.charCodeAt(0);
const F = '\f'.charCodeAt(0);
const R = '\r'.charCodeAt(0);
const EQ = '='.charCodeAt(0);
const QUOTEMARK = '"'.charCodeAt(0);
const SPACE = ' '.charCodeAt(0);
const OPEN_BRAKET = '['.charCodeAt(0);
const CLOSE_BRAKET = ']'.charCodeAt(0);
const SLASH = '/'.charCodeAt(0);
const BACKSLASH = '\\'.charCodeAt(0);
const PLACEHOLDER_SPACE_TAB = ' ';
const PLACEHOLDER_SPACE = ' ';
const getChar = String.fromCharCode;
module.exports = {
getChar,
N,
F,
R,
TAB,
EQ,
QUOTEMARK,
SPACE,
OPEN_BRAKET,
CLOSE_BRAKET,
SLASH,
PLACEHOLDER_SPACE_TAB,
PLACEHOLDER_SPACE,
BACKSLASH,
};
+30 -13
View File
@@ -2,31 +2,48 @@
"name": "@bbob/plugin-helper",
"version": "1.1.0",
"description": "Set of utils to help write plugins",
"main": "lib/index.js",
"directories": {
"lib": "lib"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JiLiZART/bbob.git"
},
"keywords": [
"bbob",
"plugin",
"helper"
],
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobPluginHelper",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"homepage": "https://github.com/JiLiZART/bbob#readme",
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint ."
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
@@ -0,0 +1,39 @@
import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char';
import { getNodeLength, appendToNode } from './index';
class TagNode {
constructor(tag, attrs, content) {
this.tag = tag;
this.attrs = attrs;
this.content = content;
}
attr(name, value) {
if (typeof value !== 'undefined') {
this.attrs[name] = value;
}
return this.attrs[name];
}
append(value) {
return appendToNode(this, value);
}
get length() {
return getNodeLength(this);
}
toString() {
const OB = OPEN_BRAKET;
const CB = CLOSE_BRAKET;
return OB + this.tag + CB + this.content.reduce((r, node) => r + node.toString(), '') + OB + SLASH + this.tag + CB;
}
}
TagNode.create = (tag, attrs = {}, content = []) => new TagNode(tag, attrs, content);
TagNode.isOf = (node, type) => (node.tag === type);
export { TagNode };
export default TagNode;
+35
View File
@@ -0,0 +1,35 @@
const N = '\n';
const TAB = '\t';
const F = '\f';
const R = '\r';
const EQ = '=';
const QUOTEMARK = '"';
const SPACE = ' ';
const OPEN_BRAKET = '[';
const CLOSE_BRAKET = ']';
const SLASH = '/';
const BACKSLASH = '\\';
const PLACEHOLDER_SPACE_TAB = ' ';
const PLACEHOLDER_SPACE = ' ';
// const getChar = String.fromCharCode;
export {
N,
F,
R,
TAB,
EQ,
QUOTEMARK,
SPACE,
OPEN_BRAKET,
CLOSE_BRAKET,
SLASH,
PLACEHOLDER_SPACE_TAB,
PLACEHOLDER_SPACE,
BACKSLASH,
};
@@ -1,10 +1,8 @@
const { getChar, N } = require('./char');
import { N } from './char';
const isTagNode = el => typeof el === 'object' && !!el.tag;
const isStringNode = el => typeof el === 'string';
const EOL = getChar(N);
const isEOL = el => el === EOL;
const isEOL = el => el === N;
const getNodeLength = (node) => {
if (isTagNode(node)) {
@@ -35,7 +33,7 @@ const attrValue = (name, value) => {
return types[type] ? types[type]() : '';
};
module.exports = {
export {
attrValue,
appendToNode,
getNodeLength,
@@ -1,4 +1,4 @@
const TagNode = require('../lib/TagNode');
import TagNode from '../src/TagNode'
describe('@bbob/plugin-helper/lib/TagNode', () => {
test('create', () => {
@@ -1,10 +1,10 @@
const {
import {
attrValue,
appendToNode,
getNodeLength,
isTagNode,
isStringNode,
} = require('../lib');
} from '../src';
describe('@bbob/plugin-helper', () => {
test('appendToNode', () => {
@@ -61,7 +61,7 @@ describe('@bbob/plugin-helper', () => {
});
test('attrValue object', () => {
const attrs = { tag: 'test'};
const attrs = { tag: 'test' };
expect(attrValue('test', attrs)).toBe('test="{&quot;tag&quot;:&quot;test&quot;}"');
});
+2
View File
@@ -1,2 +1,4 @@
dist
es
lib
test
+3 -1
View File
@@ -1,3 +1,5 @@
package-lock.json
coverage
dist
dist
lib
es
+2 -1
View File
@@ -1,6 +1,7 @@
package-lock.json
coverage
src
dist
!dist
!lib
!es
*.test.js
+38 -19
View File
@@ -2,20 +2,6 @@
"name": "@bbob/preset-html5",
"version": "1.1.0",
"description": "HTML5 Preset to transform BBCode to HTML",
"main": "lib/index.js",
"directories": {
"lib": "lib"
},
"dependencies": {
"@bbob/plugin-helper": "^1.1.0"
},
"devDependencies": {
"@bbob/core": "^1.1.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JiLiZART/bbob.git"
},
"keywords": [
"bbcode",
"preset",
@@ -23,18 +9,51 @@
"bbode",
"transform"
],
"dependencies": {
"@bbob/plugin-helper": "^1.1.0",
"@bbob/preset": "^1.1.0"
},
"devDependencies": {
"@bbob/core": "^1.1.0",
"@bbob/html": "^1.1.0"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobPresetHTML5",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"homepage": "https://github.com/JiLiZART/bbob#readme",
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint ."
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
@@ -1,6 +1,6 @@
/* eslint-disable no-plusplus,no-lonely-if */
const { isStringNode, isTagNode } = require('@bbob/plugin-helper');
const TagNode = require('@bbob/plugin-helper/lib/TagNode');
import { isStringNode, isTagNode } from '@bbob/plugin-helper';
import TagNode from '@bbob/plugin-helper/lib/TagNode';
const isStartsWith = (node, type) => (node[0] === type);
@@ -56,7 +56,7 @@ const asListItems = (content) => {
return [].concat(listItems);
};
module.exports = {
export default {
b: node => ({
tag: 'span',
attrs: {
@@ -1,6 +1,6 @@
/* eslint-disable indent */
const { isTagNode } = require('@bbob/plugin-helper');
const defaultTags = require('./default');
import { isTagNode } from '@bbob/plugin-helper';
import defaultTags from './defaultTags';
function process(tags, tree, core) {
tree.walk(node => (isTagNode(node) && tags[node.tag]
@@ -20,5 +20,6 @@ function extend(callback) {
return () => (tree, core) => process(tags, tree, core);
}
module.exports = html5Preset;
module.exports.extend = extend;
html5Preset.extend = extend;
export default html5Preset;
@@ -1,7 +1,8 @@
const preset = require('../lib/index');
const core = require('@bbob/core');
import core from '@bbob/core'
import { render } from '@bbob/html'
import preset from '../src'
const parse = input => core([preset()]).process(input).html;
const parse = input => core([preset()]).process(input, {render}).html;
describe('@bbob/preset-html5', () => {
test('[b]bolded text[/b]', () => {
+4
View File
@@ -0,0 +1,4 @@
dist
es
lib
test
+5
View File
@@ -0,0 +1,5 @@
package-lock.json
coverage
dist
lib
es
+7
View File
@@ -0,0 +1,7 @@
package-lock.json
coverage
src
!dist
!lib
!es
*.test.js
+48
View File
@@ -0,0 +1,48 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
<a name="1.1.0"></a>
# [1.1.0](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.6...@bbob/preset-html5@1.1.0) (2018-08-09)
### Features
* react render support, move some helper functions to plugin-helper ([1a84968](https://github.com/JiLiZART/bbob/commit/1a84968))
* **preset-html5:** add basic preset with tests ([18ab61b](https://github.com/JiLiZART/bbob/commit/18ab61b))
<a name="1.0.6"></a>
## [1.0.6](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.5...@bbob/preset-html5@1.0.6) (2018-07-13)
**Note:** Version bump only for package @bbob/preset-html5
<a name="1.0.5"></a>
## [1.0.5](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.4...@bbob/preset-html5@1.0.5) (2018-07-11)
**Note:** Version bump only for package @bbob/preset-html5
<a name="1.0.4"></a>
## [1.0.4](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.3...@bbob/preset-html5@1.0.4) (2018-07-10)
**Note:** Version bump only for package @bbob/preset-html5
<a name="1.0.3"></a>
## [1.0.3](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.2...@bbob/preset-html5@1.0.3) (2018-07-10)
**Note:** Version bump only for package @bbob/preset-html5
+1
View File
@@ -0,0 +1 @@
Preset to render BBCode to HTML tags
+57
View File
@@ -0,0 +1,57 @@
{
"name": "@bbob/preset-react",
"version": "1.1.0",
"description": "React preset to transform BBCode to React Components",
"keywords": [
"bbcode",
"preset",
"react",
"bbode",
"transform"
],
"dependencies": {
"@bbob/preset-html5": "*"
},
"devDependencies": {
"@bbob/core": "^1.1.0"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobPresetReact",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
@@ -1,6 +1,6 @@
const presetHTML5 = require('@bbob/preset-html5');
import presetHTML5 from '@bbob/preset-html5';
module.exports = presetHTML5.extend(tags => ({
export default presetHTML5.extend(tags => ({
...tags,
b: (...args) => ({
@@ -0,0 +1,7 @@
import preset from '../src'
describe('@bbob/preset-react', () => {
test('is a function', () => {
expect(preset).toBeInstanceOf(Function)
})
});
+4
View File
@@ -0,0 +1,4 @@
dist
es
lib
test
+5
View File
@@ -0,0 +1,5 @@
package-lock.json
coverage
dist
lib
es
+7
View File
@@ -0,0 +1,7 @@
package-lock.json
coverage
src
!dist
!lib
!es
*.test.js
+54
View File
@@ -0,0 +1,54 @@
{
"name": "@bbob/preset",
"version": "1.1.0",
"description": "Base preset for creating extensible presets for BBob",
"keywords": [
"bbcode",
"preset",
"html5",
"bbode",
"transform"
],
"dependencies": {
"@bbob/plugin-helper": "^1.1.0"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobPreset",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
+27
View File
@@ -0,0 +1,27 @@
/* eslint-disable indent */
import { isTagNode } from '@bbob/plugin-helper';
function process(tags, tree, ...rest) {
tree.walk(node => (isTagNode(node) && tags[node.tag]
? tags[node.tag](node, ...rest)
: node));
}
/**
* @param tags
* @return {function(*=, *=)}
*/
function createPreset(tags) {
const instance = (tree, ...rest) => process(tags, tree, ...rest);
instance.extend = (callback) => {
const newTags = callback(tags);
return () => createPreset(newTags);
};
return instance;
}
export { createPreset };
export default createPreset;
+17
View File
@@ -0,0 +1,17 @@
import {createPreset} from "../src/index";
describe('@bbob/preset', () => {
test('create', () => {
const preset = createPreset({ test: true });
expect(preset.extend).toBeDefined();
expect(preset).toBeInstanceOf(Function);
});
test('extend', () => {
const preset = createPreset({ foo: true });
const newPreset = preset.extend(props => ({ bar: true }));
expect(preset).toBeInstanceOf(Function);
expect(newPreset).toBeInstanceOf(Function);
});
});
-5
View File
@@ -1,5 +0,0 @@
{
"presets": [
"react"
]
}
+2
View File
@@ -1,2 +1,4 @@
dist
es
lib
test
+3 -1
View File
@@ -1,3 +1,5 @@
package-lock.json
coverage
dist
dist
lib
es
+2 -1
View File
@@ -1,6 +1,7 @@
package-lock.json
coverage
src
dist
!dist
!lib
!es
*.test.js
+29 -9
View File
@@ -1,21 +1,41 @@
# @bbob/react
```js
```jsx
import React from 'react'
import BBCode from '@bbob/react';
import presetHTML5 from '@bbob/react/lib/preset-html5';
import presetReact from '@bbob/preset-react';
const plugins = [presetHTML5()];
const plugins = [presetReact()];
<BBCode plugins={plugins}>
export default () => (
<BBCode plugins={plugins}>
[table]
[tr]
[td]table 1[/td]
[td]table 2[/td]
[/tr]
[tr]
[td]table 3[/td]
[td]table 4[/td]
[/tr]
[/table]
</BBCode>
)
```
```jsx
import { render } from '@bbob/react'
export default () => render(`
[table]
[tr]
[td]table 1[/td]
[td]table 2[/td]
[td]table 1[/td]
[td]table 2[/td]
[/tr]
[tr]
[td]table 3[/td]
[td]table 4[/td]
[td]table 3[/td]
[td]table 4[/td]
[/tr]
[/table]
</BBCode>
`)
```
-2
View File
@@ -1,2 +0,0 @@
module.exports = require('./Component');
+42 -25
View File
@@ -2,48 +2,65 @@
"name": "@bbob/react",
"version": "1.1.0",
"description": "",
"main": "lib/index.js",
"directories": {
"lib": "lib"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JiLiZART/bbob.git"
},
"keywords": [
"bbob",
"react",
"helper"
],
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"homepage": "https://github.com/JiLiZART/bbob#readme",
"scripts": {
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint ."
},
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"@bbob/core": "^1.1.0",
"@bbob/html": "^1.1.0",
"@bbob/plugin-helper": "^1.1.0",
"@bbob/preset-html5": "^1.1.0",
"@bbob/preset-react": "^1.1.0",
"prop-types": "^15.6.1"
},
"peerDependencies": {
"react": "15.x"
},
"devDependencies": {
"babel-preset-react": "^6.24.1",
"enzyme": "^3.4.0",
"enzyme-adapter-react-15": "^1.0.6",
"react": "15.x",
"react-dom": "^15.6.2",
"react-test-renderer": "^15.6.2"
}
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobReact",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"size-limit": [
{
"path": "lib/index.js"
}
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"files": [
"dist",
"lib",
"src",
"es"
]
}
@@ -1,12 +1,10 @@
const React = require('react');
const PropTypes = require('prop-types');
const core = require('@bbob/core');
const render = require('./render');
const toAST = (source, plugins) => core(plugins).process(source).tree;
const { render } = require('./render');
const content = (children, plugins) => React.Children.map(children, child =>
(typeof child === 'string' ? render(toAST(child, plugins)) : child));
(typeof child === 'string' ? render(child, plugins) : child));
const Component = props =>
React.createElement(props.container, {}, content(props.children, props.plugins));
@@ -24,4 +22,4 @@ Component.defaultProps = {
plugins: [],
};
module.exports = Component;
export default Component;
+2
View File
@@ -0,0 +1,2 @@
export { default } from './Component';
export { render } from './render';
@@ -1,5 +1,13 @@
const React = require('react');
const { isTagNode, isStringNode } = require('@bbob/plugin-helper');
import React from 'react';
import core from '@bbob/core';
import html from '@bbob/html';
import { isTagNode, isStringNode } from '@bbob/plugin-helper';
const toAST = (source, plugins) => core(plugins)
.process(source, {
render: input => html(input, { stripTags: true }),
}).tree;
function tagToReactElement(node) {
if (node.content === null) {
@@ -14,11 +22,11 @@ function tagToReactElement(node) {
node.tag,
node.attrs,
// eslint-disable-next-line no-use-before-define
render(node.content),
renderToReactNodes(node.content),
);
}
function render(nodes) {
function renderToReactNodes(nodes) {
const els = nodes.reduce((arr, node) => {
if (isTagNode(node)) {
arr.push(tagToReactElement(node));
@@ -32,4 +40,9 @@ function render(nodes) {
return els;
}
module.exports = render;
function render(source, plugins) {
return renderToReactNodes(toAST(source, plugins));
}
export { render };
export default render;
+8 -7
View File
@@ -1,14 +1,15 @@
const React = require('react');
const { shallow } = require('enzyme');
const BBCode = require('../lib');
const presetHTML5 = require('../lib/preset-html5');
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-15');
import React from 'react';
import preset from '@bbob/preset-react';
import { shallow } from 'enzyme';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import BBCode from '../src';
Enzyme.configure({ adapter: new Adapter() });
const renderBBCode = input => shallow(
<BBCode plugins={[presetHTML5()]}>{input}</BBCode>
<BBCode plugins={[preset()]}>{input}</BBCode>
).html();
describe('@bbob/react', () => {
+66
View File
@@ -0,0 +1,66 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace';
import commonjs from 'rollup-plugin-commonjs';
import { uglify } from 'rollup-plugin-uglify';
const pkg = require(`${process.cwd()}/package.json`);
const env = process.env.NODE_ENV;
const globals = {
react: 'React',
vue: 'Vue',
};
const external = ['react', 'vue'];
const input = 'src/index.js';
const plugins = [
nodeResolve(),
babel({
exclude: '**/node_modules/**',
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env),
}),
commonjs(),
];
export default [
{
input,
external,
output: {
file: pkg.browser,
format: 'umd',
name: pkg.browserName,
globals: {
react: 'React',
vue: 'Vue',
},
},
plugins,
},
{
input,
external,
output: {
file: pkg.browser.replace('.js', '.min.js'),
format: 'umd',
name: pkg.browserName,
globals,
},
plugins: [
...plugins,
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
}),
],
},
];