mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +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:
committed by
GitHub
parent
d22a2895a4
commit
32a7fb51da
@@ -1,2 +1,4 @@
|
||||
dist
|
||||
es
|
||||
lib
|
||||
test
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
package-lock.json
|
||||
coverage
|
||||
dist
|
||||
dist
|
||||
lib
|
||||
es
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package-lock.json
|
||||
coverage
|
||||
src
|
||||
dist
|
||||
!dist
|
||||
!lib
|
||||
!es
|
||||
*.test.js
|
||||
|
||||
@@ -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>
|
||||
```
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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,4 +1,4 @@
|
||||
const { iterate } = require('../lib/utils');
|
||||
import { iterate } from '../src/utils';
|
||||
|
||||
describe('@bbob/core utils', () => {
|
||||
test('iterate', () => {
|
||||
|
||||
Reference in New Issue
Block a user