Skip to content

Commit

Permalink
refactor: move react parser in dedicated folder (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrith authored Sep 21, 2024
1 parent ee403a8 commit 74c3f91
Show file tree
Hide file tree
Showing 42 changed files with 841 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "functions",
"request": "launch",
"program": "${workspaceFolder}/packages/node-react-parser/node_modules/jest/bin/jest",
"args": [
"--runInBand"
],
"cwd": "${workspaceFolder}/packages/node-react-parser",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"

},
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"eslint.workingDirectories": [
"./apps/node-cli",
"./apps/node-cli",
"./packages/node-react-parser"
],
}
72 changes: 72 additions & 0 deletions packages/node-react-parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock*
package-lock.json
Cargo.lock

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Parcel related files
dist/
.cache/
.parcel-cache/

.DS_Store

playwright-report/
**/dist/
*.gif
10 changes: 10 additions & 0 deletions packages/node-react-parser/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
build
old
CHANGELOG.md
public/icons/*.json
.cache
coverage
playwright-report
pnpm-lock.yaml
dist
templates
7 changes: 7 additions & 0 deletions packages/node-react-parser/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
}
34 changes: 34 additions & 0 deletions packages/node-react-parser/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import typescriptParser from '@typescript-eslint/parser'
import js from '@eslint/js'
import jest from 'eslint-plugin-jest'
import tseslint from 'typescript-eslint'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'

// Following this article: https://www.raulmelo.me/en/blog/migration-eslint-to-flat-config

export default tseslint.config(
{
ignores: ['dist/**', 'node_modules/**'],
},
js.configs.recommended,
{
files: ['**/*.js', '**/*.ts', '**/*.tsx'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser: typescriptParser,
globals: {
document: 'readonly',
},
},
rules: {
'no-console': ['error', { allow: ['warn', 'error'] }],
},
},
{
files: ['**/*.{test,spec}.tsx?'],
...jest.configs['flat/recommended'],
},
...tseslint.configs.recommended,
eslintPluginPrettierRecommended,
)
12 changes: 12 additions & 0 deletions packages/node-react-parser/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from 'jest'

const config: Config = {
testMatch: ['<rootDir>/src/**/*.test.{tsx,ts}'],
preset: 'ts-jest',
moduleNameMapper: {
'~/(.*)$': '<rootDir>/$1',
},
verbose: true,
}

export default config
39 changes: 39 additions & 0 deletions packages/node-react-parser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "node-react-parser",
"description": "A library to parse react components",
"keywords": [
"react",
"parser",
"react parser"
],
"type": "module",
"main": "./src/index.ts",
"version": "0.1.0",
"scripts": {
"cli": "tsx ./src/cli.ts",
"build": "ncc build ./src/cli.ts -o dist",
"test": "jest",
"lint": "eslint .",
"format": "prettier --check ."
},
"dependencies": {
"typescript": "^5.4.5"
},
"devDependencies": {
"@eslint/js": "^8.57.0",
"@tsconfig/node20": "^20.1.2",
"@tsconfig/strictest": "^2.0.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@typescript-eslint/parser": "^7.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript-eslint": "^7.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Foo",
"path": "arrow-function/component-with-basic-properties.tsx",
"description": "",
"properties": [
{
"name": "one",
"type": "string"
},
{
"name": "two",
"type": "number"
},
{
"name": "three",
"type": "boolean"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const Foo = ({
one,
two,
three,
}: {
one: string
two: number
three: boolean
}) => {
return <div>Foo</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Foo",
"path": "arrow-function/component-without-properties.tsx",
"description": "",
"properties": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const Foo = () => {
return <div>Foo</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Foo",
"path": "function/default-exported-component.tsx",
"description": "",
"properties": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Foo = () => {
return <div>Foo</div>
}

export default Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Foo",
"path": "function/component-with-basic-properties.tsx",
"description": "",
"properties": [
{
"name": "one",
"type": "string"
},
{
"name": "two",
"type": "number"
},
{
"name": "three",
"type": "boolean"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function Foo({
one,
two,
three,
}: {
one: string
two: number
three: boolean
}) {
return <div>Foo</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Foo",
"path": "function/component-without-properties.tsx",
"description": "",
"properties": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Foo() {
return <div>Foo</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Foo",
"path": "function/default-exported-component.tsx",
"description": "",
"properties": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Foo() {
return <div>Foo</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES2017",
"moduleResolution": "bundler",
"typeRoots": ["node_modules/@types", "src/types"],
"types": ["node", "jest", "@testing-library/jest-dom"],
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"~/*": ["./*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES2017",
"moduleResolution": "bundler",
"typeRoots": ["node_modules/@types", "src/types"],
"types": ["node", "jest", "@testing-library/jest-dom"],
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"~/*": ["./*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function Foo({
one,
two,
three,
}: {
one: string
two: number
three: boolean
}) {
return <div>Foo</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES2017",
"moduleResolution": "bundler",
"typeRoots": ["node_modules/@types", "src/types"],
"types": ["node", "jest", "@testing-library/jest-dom"],
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"~/*": ["./*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Foo() {
return <div>Foo</div>
}
Loading

0 comments on commit 74c3f91

Please sign in to comment.