mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-11 18:02:26 +03:00
feat: typescript support (#185)
* feat: initial typescript support * feat: typescript support * feat(plugin-helper): move files to typescript * chore: update lock files * feat: preset types * fix: build * fix: benchmark * fix: remove pnpm cache * fix: bench action * fix: pnpm recursive install * fix: nx cache * fix: lock file * fix: workflows * fix: lerna support in pnpm * fix: pnpm workspace * fix: remove unused files * fix: pnpm lock file * fix: update lerna for support pnpm * fix: lerna bootstrap * fix: rollup build * fix: update nx * fix: build * fix: add nx dep target * fix: remove nx cache * fix: workflow run on push only for master * fix: test workflow run on push only for master * fix: remove parallel for gen types * fix: benchmark * fix: benchmark imports * fix: pnpm * fix: types errors and pnpm * fix: types * fix: types * refactor: parser * fix(parser): tests * fix: preset tests * fix: react types * fix: react type declarations * fix: pnpm lock file * fix: react preset types * fix: lock file * fix: vue2 types * feat: dev container support * fix: types * fix: types * refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts * refactor: types * fix: types * fix: rename gen-types to types * fix: nx build order * fix: nx reset * fix: define nx deps explicit * fix: build * fix: nx * fix: nx order build * fix: nx deps * fix: bbob cli tests * fix: tests * fix: cli tests and import * fix: test cover * fix: cli cover
This commit is contained in:
@@ -1,2 +1,7 @@
|
||||
coverage
|
||||
dist
|
||||
lib
|
||||
es
|
||||
types
|
||||
test/*.d.ts
|
||||
test/*.map
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
coverage
|
||||
src
|
||||
dist
|
||||
!lib
|
||||
!dist
|
||||
!lib
|
||||
!es
|
||||
*.test.js
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
#@bbob/cli
|
||||
# @bbob/cli
|
||||
[](https://packagephobia.now.sh/result?p=@bbob/html) [](https://snyk.io/test/github/JiLiZART/bbob?targetFile=packages%2Fbbob-cli%2Fpackage.json)
|
||||
|
||||
Convert BBCode to HTML
|
||||
> Converts bbcode string to html
|
||||
|
||||
```shell
|
||||
npm i -g @bbob/cli
|
||||
```
|
||||
|
||||
```shell
|
||||
echo "[i]Text[/i]" | bbob
|
||||
|
||||
# prints
|
||||
<span style="font-style: italic;">Text</span>
|
||||
```
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('../lib/cli');
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('../lib/cli');
|
||||
@@ -1,25 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const program = require('commander');
|
||||
const { version } = require('../package.json');
|
||||
|
||||
program
|
||||
.version(version)
|
||||
.parse(process.argv);
|
||||
|
||||
const options = {};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function readFile(filename, encoding, callback) {
|
||||
if (options.file === '-') {
|
||||
// read from stdin
|
||||
const chunks = [];
|
||||
|
||||
process.stdin.on('data', (chunk) => {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
process.stdin.on('end', () => callback(null, Buffer.concat(chunks).toString(encoding)));
|
||||
} else {
|
||||
fs.readFile(filename, encoding, callback);
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,30 @@
|
||||
"name": "@bbob/cli",
|
||||
"version": "3.0.2",
|
||||
"description": "Comand line bbcode parser",
|
||||
"main": "lib/cli.js",
|
||||
"bin": {
|
||||
"bbob": "bin/bbob"
|
||||
"bbob": "lib/cli.js"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
"main": "lib/index.js",
|
||||
"module": "es/index.js",
|
||||
"jsnext:main": "es/index.js",
|
||||
"browser": "dist/index.js",
|
||||
"browserName": "BbobCli",
|
||||
"types": "types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/index.d.ts",
|
||||
"import": "./es/index.js",
|
||||
"require": "./lib/index.js",
|
||||
"browser": "./dist/index.min.js",
|
||||
"umd": "./dist/index.min.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@bbob/html": "workspace:*",
|
||||
"@bbob/preset-html5": "workspace:*",
|
||||
"commander": "^2.15.1"
|
||||
"@bbob/html": "*",
|
||||
"@bbob/preset-html5": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "20.11.30"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -29,9 +42,16 @@
|
||||
},
|
||||
"homepage": "https://github.com/JiLiZART/bbob#readme",
|
||||
"scripts": {
|
||||
"test": "../../scripts/pkg-task test",
|
||||
"cover": "../../scripts/pkg-task cover",
|
||||
"lint": "../../scripts/pkg-task lint"
|
||||
"build:commonjs": "pkg-task",
|
||||
"build:es": "pkg-task",
|
||||
"build:umd": "pkg-task",
|
||||
"build": "pkg-task",
|
||||
"test": "pkg-task",
|
||||
"lint": "pkg-task",
|
||||
"size": "pkg-task",
|
||||
"bundlesize": "pkg-task",
|
||||
"types": "pkg-task",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||
"license": "MIT",
|
||||
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
import { run } from './index';
|
||||
|
||||
run(process.stdin, process.stdout);
|
||||
@@ -0,0 +1,24 @@
|
||||
import html from '@bbob/html'
|
||||
import presetHTML5 from '@bbob/preset-html5'
|
||||
|
||||
export function run(stdin = process.stdin, stdout = process.stdout) {
|
||||
stdin.setEncoding('utf8');
|
||||
|
||||
let inputData = '';
|
||||
|
||||
// Read data from stdin
|
||||
stdin.on('readable', () => {
|
||||
const chunk = stdin.read();
|
||||
|
||||
if (chunk !== null) {
|
||||
inputData += chunk;
|
||||
}
|
||||
});
|
||||
|
||||
// Once there's no more data to read, reverse the input and write it to stdout
|
||||
stdin.on('end', () => {
|
||||
const reversedData = html(inputData, presetHTML5()).toString();
|
||||
|
||||
stdout.write(reversedData);
|
||||
});
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
|
||||
|
||||
describe('CLI Interface', () => {
|
||||
test('read from file', () => {
|
||||
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const pathToBin = path.resolve(__dirname, '../lib/cli.js')
|
||||
|
||||
describe('@bbob/cli', () => {
|
||||
test('simple string', () => {
|
||||
const stdout = execSync(`echo "hello" | ${pathToBin}`);
|
||||
|
||||
expect(String(stdout).trim()).toBe('hello');
|
||||
});
|
||||
|
||||
test('string with bbcodes', () => {
|
||||
const stdout = execSync(`echo "[i]Text[/i]" | ${pathToBin}`);
|
||||
|
||||
expect(String(stdout).trim()).toBe('<span style="font-style: italic;">Text</span>');
|
||||
});
|
||||
|
||||
test('empty string', () => {
|
||||
const stdout = execSync(`echo "" | ${pathToBin}`);
|
||||
|
||||
expect(String(stdout).trim()).toBe('');
|
||||
});
|
||||
|
||||
test('multiline string', () => {
|
||||
const stdout = execSync(`echo "[i]Text[/i]\n[i]Text[/i]" | ${pathToBin}`);
|
||||
|
||||
expect(String(stdout).trim()).toBe('<span style="font-style: italic;">Text</span>\n<span style="font-style: italic;">Text</span>');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "./types"
|
||||
},
|
||||
"include": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user