From 05b9705be975339cf24ffc2bf7a8d07a58c9acc4 Mon Sep 17 00:00:00 2001 From: Artem-Darius Atlas Date: Mon, 24 Jul 2023 20:44:46 +0300 Subject: [PATCH] feat: added react pages lib --- README.md | 4 ++ libs/site-pages/.babelrc | 12 +++++ libs/site-pages/.eslintrc.json | 18 +++++++ libs/site-pages/README.md | 7 +++ libs/site-pages/jest.config.ts | 11 +++++ libs/site-pages/package.json | 12 +++++ libs/site-pages/project.json | 46 +++++++++++++++++ libs/site-pages/src/index.ts | 1 + .../site-pages/src/lib/site-pages.module.scss | 7 +++ libs/site-pages/src/lib/site-pages.spec.tsx | 10 ++++ libs/site-pages/src/lib/site-pages.tsx | 14 ++++++ libs/site-pages/tsconfig.json | 21 ++++++++ libs/site-pages/tsconfig.lib.json | 22 +++++++++ libs/site-pages/tsconfig.spec.json | 20 ++++++++ libs/site-pages/vite.config.ts | 49 +++++++++++++++++++ tsconfig.base.json | 1 + 16 files changed, 255 insertions(+) create mode 100644 libs/site-pages/.babelrc create mode 100644 libs/site-pages/.eslintrc.json create mode 100644 libs/site-pages/README.md create mode 100644 libs/site-pages/jest.config.ts create mode 100644 libs/site-pages/package.json create mode 100644 libs/site-pages/project.json create mode 100644 libs/site-pages/src/index.ts create mode 100644 libs/site-pages/src/lib/site-pages.module.scss create mode 100644 libs/site-pages/src/lib/site-pages.spec.tsx create mode 100644 libs/site-pages/src/lib/site-pages.tsx create mode 100644 libs/site-pages/tsconfig.json create mode 100644 libs/site-pages/tsconfig.lib.json create mode 100644 libs/site-pages/tsconfig.spec.json create mode 100644 libs/site-pages/vite.config.ts diff --git a/README.md b/README.md index ce36216..d716fad 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,10 @@ Just run `nx build demoapp` to build the application. The build artifacts will b ```bash nx g @nx/react:component NAME --project site-layouts ``` +## Create a new Page +```bash +nx g @nx/react:component NAME --project site-pages +``` # Стиль кода ## Коммиты diff --git a/libs/site-pages/.babelrc b/libs/site-pages/.babelrc new file mode 100644 index 0000000..1ea870e --- /dev/null +++ b/libs/site-pages/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/site-pages/.eslintrc.json b/libs/site-pages/.eslintrc.json new file mode 100644 index 0000000..a39ac5d --- /dev/null +++ b/libs/site-pages/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["plugin:@nx/react", "../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/site-pages/README.md b/libs/site-pages/README.md new file mode 100644 index 0000000..5ce2cf0 --- /dev/null +++ b/libs/site-pages/README.md @@ -0,0 +1,7 @@ +# site-pages + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test site-pages` to execute the unit tests via [Vitest](https://vitest.dev/). diff --git a/libs/site-pages/jest.config.ts b/libs/site-pages/jest.config.ts new file mode 100644 index 0000000..ffe4073 --- /dev/null +++ b/libs/site-pages/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: 'site-pages', + preset: '../../jest.preset.js', + transform: { + '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest', + '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }], + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + coverageDirectory: '../../coverage/libs/site-pages', +}; diff --git a/libs/site-pages/package.json b/libs/site-pages/package.json new file mode 100644 index 0000000..bc6dfed --- /dev/null +++ b/libs/site-pages/package.json @@ -0,0 +1,12 @@ +{ + "name": "@platform/site-pages", + "version": "0.0.1", + "main": "./index.js", + "types": "./index.d.ts", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } +} diff --git a/libs/site-pages/project.json b/libs/site-pages/project.json new file mode 100644 index 0000000..1f4f430 --- /dev/null +++ b/libs/site-pages/project.json @@ -0,0 +1,46 @@ +{ + "name": "site-pages", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/site-pages/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/site-pages/**/*.{ts,tsx,js,jsx}"] + } + }, + "build": { + "executor": "@nx/vite:build", + "outputs": ["{options.outputPath}"], + "defaultConfiguration": "production", + "options": { + "outputPath": "dist/libs/site-pages" + }, + "configurations": { + "development": { + "mode": "development" + }, + "production": { + "mode": "production" + } + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/site-pages/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + } + } +} diff --git a/libs/site-pages/src/index.ts b/libs/site-pages/src/index.ts new file mode 100644 index 0000000..2e9ed09 --- /dev/null +++ b/libs/site-pages/src/index.ts @@ -0,0 +1 @@ +export * from './lib/site-pages'; diff --git a/libs/site-pages/src/lib/site-pages.module.scss b/libs/site-pages/src/lib/site-pages.module.scss new file mode 100644 index 0000000..45c2aa4 --- /dev/null +++ b/libs/site-pages/src/lib/site-pages.module.scss @@ -0,0 +1,7 @@ +/* + * Replace this with your own classes + * + * e.g. + * .container { + * } +*/ diff --git a/libs/site-pages/src/lib/site-pages.spec.tsx b/libs/site-pages/src/lib/site-pages.spec.tsx new file mode 100644 index 0000000..3b399c2 --- /dev/null +++ b/libs/site-pages/src/lib/site-pages.spec.tsx @@ -0,0 +1,10 @@ +import { render } from '@testing-library/react'; + +import SitePages from './site-pages'; + +describe('SitePages', () => { + it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); + }); +}); diff --git a/libs/site-pages/src/lib/site-pages.tsx b/libs/site-pages/src/lib/site-pages.tsx new file mode 100644 index 0000000..0815b60 --- /dev/null +++ b/libs/site-pages/src/lib/site-pages.tsx @@ -0,0 +1,14 @@ +import styles from './site-pages.module.scss'; + +/* eslint-disable-next-line */ +export interface SitePagesProps {} + +export function SitePages(props: SitePagesProps) { + return ( +
+

Welcome to SitePages!

+
+ ); +} + +export default SitePages; diff --git a/libs/site-pages/tsconfig.json b/libs/site-pages/tsconfig.json new file mode 100644 index 0000000..bab74ff --- /dev/null +++ b/libs/site-pages/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true, + "types": ["vite/client"] + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../tsconfig.base.json" +} diff --git a/libs/site-pages/tsconfig.lib.json b/libs/site-pages/tsconfig.lib.json new file mode 100644 index 0000000..3d8276e --- /dev/null +++ b/libs/site-pages/tsconfig.lib.json @@ -0,0 +1,22 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["node", "vite/client"] + }, + "files": [ + "../../node_modules/@nx/react/typings/cssmodule.d.ts", + "../../node_modules/@nx/react/typings/image.d.ts" + ], + "exclude": [ + "**/*.spec.ts", + "**/*.test.ts", + "**/*.spec.tsx", + "**/*.test.tsx", + "**/*.spec.js", + "**/*.test.js", + "**/*.spec.jsx", + "**/*.test.jsx" + ], + "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"] +} diff --git a/libs/site-pages/tsconfig.spec.json b/libs/site-pages/tsconfig.spec.json new file mode 100644 index 0000000..26ef046 --- /dev/null +++ b/libs/site-pages/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/libs/site-pages/vite.config.ts b/libs/site-pages/vite.config.ts new file mode 100644 index 0000000..37656ce --- /dev/null +++ b/libs/site-pages/vite.config.ts @@ -0,0 +1,49 @@ +/// +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; +import viteTsConfigPaths from 'vite-tsconfig-paths'; +import dts from 'vite-plugin-dts'; +import * as path from 'path'; + +export default defineConfig({ + cacheDir: '../../node_modules/.vite/site-pages', + + plugins: [ + dts({ + entryRoot: 'src', + tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'), + skipDiagnostics: true, + }), + react(), + viteTsConfigPaths({ + root: '../../', + }), + ], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ + // viteTsConfigPaths({ + // root: '../../', + // }), + // ], + // }, + + // Configuration for building your library. + // See: https://vitejs.dev/guide/build.html#library-mode + build: { + lib: { + // Could also be a dictionary or array of multiple entry points. + entry: 'src/index.ts', + name: 'site-pages', + fileName: 'index', + // Change this to the formats you want to support. + // Don't forget to update your package.json as well. + formats: ['es', 'cjs'], + }, + rollupOptions: { + // External packages that should not be bundled into your library. + external: ['react', 'react-dom', 'react/jsx-runtime'], + }, + }, +}); diff --git a/tsconfig.base.json b/tsconfig.base.json index df5872c..8ce9327 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -19,6 +19,7 @@ "@platform/prisma-clients": ["libs/prisma-clients/index.ts"], "@platform/prisma-generator": ["libs/prisma-generator/src/index.ts"], "@platform/site-layouts": ["libs/site-layouts/src/index.ts"], + "@platform/site-pages": ["libs/site-pages/src/index.ts"], "@platform/ui": ["libs/ui/src/index.ts"] } },