From 15a7fd1fbafffdf5184f81b81884940f8cd3b4c3 Mon Sep 17 00:00:00 2001 From: MikaelNordberg Date: Fri, 15 Mar 2024 11:06:11 +0100 Subject: [PATCH 1/2] Generated Typescript library for the PXWeb2 API client. --- libs/pxweb2-api-client/.eslintrc.json | 30 +++++++++ libs/pxweb2-api-client/README.md | 11 ++++ libs/pxweb2-api-client/package.json | 8 +++ libs/pxweb2-api-client/project.json | 35 +++++++++++ libs/pxweb2-api-client/src/index.ts | 1 + .../src/lib/pxweb2-api-client.spec.ts | 7 +++ .../src/lib/pxweb2-api-client.ts | 3 + libs/pxweb2-api-client/tsconfig.json | 22 +++++++ libs/pxweb2-api-client/tsconfig.lib.json | 10 +++ libs/pxweb2-api-client/tsconfig.spec.json | 26 ++++++++ libs/pxweb2-api-client/vite.config.ts | 62 +++++++++++++++++++ nx.json | 5 ++ tsconfig.base.json | 1 + 13 files changed, 221 insertions(+) create mode 100644 libs/pxweb2-api-client/.eslintrc.json create mode 100644 libs/pxweb2-api-client/README.md create mode 100644 libs/pxweb2-api-client/package.json create mode 100644 libs/pxweb2-api-client/project.json create mode 100644 libs/pxweb2-api-client/src/index.ts create mode 100644 libs/pxweb2-api-client/src/lib/pxweb2-api-client.spec.ts create mode 100644 libs/pxweb2-api-client/src/lib/pxweb2-api-client.ts create mode 100644 libs/pxweb2-api-client/tsconfig.json create mode 100644 libs/pxweb2-api-client/tsconfig.lib.json create mode 100644 libs/pxweb2-api-client/tsconfig.spec.json create mode 100644 libs/pxweb2-api-client/vite.config.ts diff --git a/libs/pxweb2-api-client/.eslintrc.json b/libs/pxweb2-api-client/.eslintrc.json new file mode 100644 index 00000000..0dc93dd7 --- /dev/null +++ b/libs/pxweb2-api-client/.eslintrc.json @@ -0,0 +1,30 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": [ + "error", + { + "ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"] + } + ] + } + } + ] +} diff --git a/libs/pxweb2-api-client/README.md b/libs/pxweb2-api-client/README.md new file mode 100644 index 00000000..0dc34b3b --- /dev/null +++ b/libs/pxweb2-api-client/README.md @@ -0,0 +1,11 @@ +# pxweb2-api-client + +This library was generated with [Nx](https://nx.dev). + +## Building + +Run `nx build pxweb2-api-client` to build the library. + +## Running unit tests + +Run `nx test pxweb2-api-client` to execute the unit tests via [Vitest](https://vitest.dev/). diff --git a/libs/pxweb2-api-client/package.json b/libs/pxweb2-api-client/package.json new file mode 100644 index 00000000..b6c9e369 --- /dev/null +++ b/libs/pxweb2-api-client/package.json @@ -0,0 +1,8 @@ +{ + "name": "@pxweb2/pxweb2-api-client", + "version": "0.0.1", + "dependencies": {}, + "main": "./index.js", + "module": "./index.mjs", + "typings": "./index.d.ts" +} diff --git a/libs/pxweb2-api-client/project.json b/libs/pxweb2-api-client/project.json new file mode 100644 index 00000000..d2ea6ce1 --- /dev/null +++ b/libs/pxweb2-api-client/project.json @@ -0,0 +1,35 @@ +{ + "name": "pxweb2-api-client", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/pxweb2-api-client/src", + "projectType": "library", + "targets": { + "build": { + "executor": "@nx/vite:build", + "outputs": ["{options.outputPath}"], + "defaultConfiguration": "production", + "options": { + "outputPath": "dist/libs/pxweb2-api-client" + }, + "configurations": { + "development": { + "mode": "development" + }, + "production": { + "mode": "production" + } + } + }, + "test": { + "executor": "@nx/vite:test", + "outputs": ["{options.reportsDirectory}"], + "options": { + "reportsDirectory": "../../coverage/libs/pxweb2-api-client" + } + }, + "lint": { + "executor": "@nx/eslint:lint" + } + }, + "tags": [] +} diff --git a/libs/pxweb2-api-client/src/index.ts b/libs/pxweb2-api-client/src/index.ts new file mode 100644 index 00000000..ae121785 --- /dev/null +++ b/libs/pxweb2-api-client/src/index.ts @@ -0,0 +1 @@ +export * from './lib/pxweb2-api-client'; diff --git a/libs/pxweb2-api-client/src/lib/pxweb2-api-client.spec.ts b/libs/pxweb2-api-client/src/lib/pxweb2-api-client.spec.ts new file mode 100644 index 00000000..9336be63 --- /dev/null +++ b/libs/pxweb2-api-client/src/lib/pxweb2-api-client.spec.ts @@ -0,0 +1,7 @@ +import { pxweb2ApiClient } from './pxweb2-api-client'; + +describe('pxweb2ApiClient', () => { + it('should work', () => { + expect(pxweb2ApiClient()).toEqual('pxweb2-api-client'); + }); +}); diff --git a/libs/pxweb2-api-client/src/lib/pxweb2-api-client.ts b/libs/pxweb2-api-client/src/lib/pxweb2-api-client.ts new file mode 100644 index 00000000..fc9994b9 --- /dev/null +++ b/libs/pxweb2-api-client/src/lib/pxweb2-api-client.ts @@ -0,0 +1,3 @@ +export function pxweb2ApiClient(): string { + return 'pxweb2-api-client'; +} diff --git a/libs/pxweb2-api-client/tsconfig.json b/libs/pxweb2-api-client/tsconfig.json new file mode 100644 index 00000000..f5b85657 --- /dev/null +++ b/libs/pxweb2-api-client/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/pxweb2-api-client/tsconfig.lib.json b/libs/pxweb2-api-client/tsconfig.lib.json new file mode 100644 index 00000000..56bc5e5c --- /dev/null +++ b/libs/pxweb2-api-client/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node", "vite/client"] + }, + "include": ["src/**/*.ts"], + "exclude": ["vite.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/libs/pxweb2-api-client/tsconfig.spec.json b/libs/pxweb2-api-client/tsconfig.spec.json new file mode 100644 index 00000000..3c002c21 --- /dev/null +++ b/libs/pxweb2-api-client/tsconfig.spec.json @@ -0,0 +1,26 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [ + "vitest/globals", + "vitest/importMeta", + "vite/client", + "node", + "vitest" + ] + }, + "include": [ + "vite.config.ts", + "vitest.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/pxweb2-api-client/vite.config.ts b/libs/pxweb2-api-client/vite.config.ts new file mode 100644 index 00000000..bc092149 --- /dev/null +++ b/libs/pxweb2-api-client/vite.config.ts @@ -0,0 +1,62 @@ +/// +import { defineConfig } from 'vite'; +import dts from 'vite-plugin-dts'; +import * as path from 'path'; +import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; + +export default defineConfig({ + root: __dirname, + cacheDir: '../../node_modules/.vite/libs/pxweb2-api-client', + + plugins: [ + nxViteTsPaths(), + dts({ + entryRoot: 'src', + tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'), + skipDiagnostics: true, + }), + ], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ nxViteTsPaths() ], + // }, + + // Configuration for building your library. + // See: https://vitejs.dev/guide/build.html#library-mode + build: { + outDir: '../../dist/libs/pxweb2-api-client', + reportCompressedSize: true, + commonjsOptions: { + transformMixedEsModules: true, + }, + lib: { + // Could also be a dictionary or array of multiple entry points. + entry: 'src/index.ts', + name: 'pxweb2-api-client', + 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: [], + }, + }, + + test: { + globals: true, + cache: { + dir: '../../node_modules/.vitest', + }, + environment: 'node', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + + reporters: ['default'], + coverage: { + reportsDirectory: '../../coverage/libs/pxweb2-api-client', + provider: 'v8', + }, + }, +}); diff --git a/nx.json b/nx.json index 7d71fe45..04053ac7 100644 --- a/nx.json +++ b/nx.json @@ -31,6 +31,11 @@ "{workspaceRoot}/.eslintignore", "{workspaceRoot}/eslint.config.js" ] + }, + "@nx/vite:build": { + "cache": true, + "dependsOn": ["^build"], + "inputs": ["production", "^production"] } }, "namedInputs": { diff --git a/tsconfig.base.json b/tsconfig.base.json index ec7e2a52..13a60877 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -15,6 +15,7 @@ "skipDefaultLibCheck": true, "baseUrl": ".", "paths": { + "@pxweb2/pxweb2-api-client": ["libs/pxweb2-api-client/src/index.ts"], "@pxweb2/pxweb2-ui": ["libs/pxweb2-ui/src/index.ts"] } }, From cc74733d2dbec976f881dc6ff19b706f948b196a Mon Sep 17 00:00:00 2001 From: MikaelNordberg Date: Fri, 15 Mar 2024 11:29:18 +0100 Subject: [PATCH 2/2] Added folders for mappers and shared types --- apps/pxweb2/src/mappers/.gitkeep | 0 libs/pxweb2-ui/src/lib/shared-types/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 apps/pxweb2/src/mappers/.gitkeep create mode 100644 libs/pxweb2-ui/src/lib/shared-types/.gitkeep diff --git a/apps/pxweb2/src/mappers/.gitkeep b/apps/pxweb2/src/mappers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/libs/pxweb2-ui/src/lib/shared-types/.gitkeep b/libs/pxweb2-ui/src/lib/shared-types/.gitkeep new file mode 100644 index 00000000..e69de29b