Skip to content

Commit

Permalink
added first lib (nrwl#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
juampirossetti committed May 6, 2024
1 parent 3d946e5 commit fbfe089
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 75 deletions.
76 changes: 4 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,8 @@
# LearningPlat

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
Nx project for a learning platform

**This workspace has been generated by [Nx, Smart Monorepos · Fast CI.](https://nx.dev)**
# Commands

## Integrate with editors

Enhance your Nx experience by installing [Nx Console](https://nx.dev/nx-console) for your favorite editor. Nx Console
provides an interactive UI to view your projects, run tasks, generate code, and more! Available for VSCode, IntelliJ and
comes with a LSP for Vim users.

## Nx plugins and code generators

Add Nx plugins to leverage their code generators and automated, inferred tasks.

```
# Add plugin
npx nx add @nx/react
# Use code generator
npx nx generate @nx/react:app demo
# Run development server
npx nx serve demo
# View project details
npx nx show project demo --web
```

Run `npx nx list` to get a list of available plugins and whether they have generators. Then run `npx nx list <plugin-name>` to see what generators are available.

Learn more about [code generators](https://nx.dev/features/generate-code) and [inferred tasks](https://nx.dev/concepts/inferred-tasks) in the docs.

## Running tasks

To execute tasks with Nx use the following syntax:

```
npx nx <target> <project> <...options>
```

You can also run multiple targets:

```
npx nx run-many -t <target1> <target2>
```

..or add `-p` to filter specific projects

```
npx nx run-many -t <target1> <target2> -p <proj1> <proj2>
```

Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/features/run-tasks).

## Set up CI!

Nx comes with local caching already built-in (check your `nx.json`). On CI you might want to go a step further.

- [Set up remote caching](https://nx.dev/features/share-your-cache)
- [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution)
- [Learn more how to setup CI](https://nx.dev/recipes/ci)

## Explore the project graph

Run `npx nx graph` to show the graph of the workspace.
It will show tasks that you can run with Nx.

- [Learn more about Exploring the Project Graph](https://nx.dev/core-features/explore-graph)

## Connect with us!

- [Join the community](https://nx.dev/community)
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
- [Follow us on Twitter](https://twitter.com/nxdevtools)
Run the backend
`npx nx serve api`
3 changes: 2 additions & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import express from 'express';
import * as path from 'path';
import { someFunction } from '@learning-plat/test-lib';

const app = express();

app.use('/assets', express.static(path.join(__dirname, 'assets')));

app.get('/api', (req, res) => {
res.send({ message: 'Welcome to api!' });
res.send({ message: `Welcome to my-express-app! ${someFunction()}` });
});

const port = process.env.PORT || 3333;
Expand Down
25 changes: 25 additions & 0 deletions libs/test-lib/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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"
}
}
]
}
11 changes: 11 additions & 0 deletions libs/test-lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# test-lib

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build test-lib` to build the library.

## Running unit tests

Run `nx test test-lib` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/test-lib/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'test-lib',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/test-lib',
};
11 changes: 11 additions & 0 deletions libs/test-lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@learning-plat/test-lib",
"version": "0.0.1",
"dependencies": {
"tslib": "^2.3.0"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"private": true
}
19 changes: 19 additions & 0 deletions libs/test-lib/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "test-lib",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/test-lib/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/test-lib",
"main": "libs/test-lib/src/index.ts",
"tsConfig": "libs/test-lib/tsconfig.lib.json",
"assets": ["libs/test-lib/*.md"]
}
}
}
}
1 change: 1 addition & 0 deletions libs/test-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/test-lib';
7 changes: 7 additions & 0 deletions libs/test-lib/src/lib/test-lib.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { testLib } from './test-lib';

describe('testLib', () => {
it('should work', () => {
expect(testLib()).toEqual('test-lib');
});
});
3 changes: 3 additions & 0 deletions libs/test-lib/src/lib/test-lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function someFunction(): string {
return 'some function';
}
22 changes: 22 additions & 0 deletions libs/test-lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
10 changes: 10 additions & 0 deletions libs/test-lib/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
14 changes: 14 additions & 0 deletions libs/test-lib/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
9 changes: 8 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@
},
"exclude": ["apps/api-e2e/**/*"]
}
]
],
"targetDefaults": {
"@nx/js:tsc": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
}
}
}
4 changes: 3 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {}
"paths": {
"@learning-plat/test-lib": ["libs/test-lib/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
}

0 comments on commit fbfe089

Please sign in to comment.