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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package-lock.json
|
||||
coverage
|
||||
dist
|
||||
lib
|
||||
es
|
||||
@@ -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);
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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="{"tag":"test"}"');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user