Skip to content

Commit

Permalink
Add proxy logs
Browse files Browse the repository at this point in the history
  • Loading branch information
whalemare committed Jan 22, 2023
1 parent 0668c0c commit 2b0b735
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/node-example/src/app/endlessApp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { workflow } from '@ts-pipeline/core'
import { logs } from '@ts-pipeline/step-logs'

import { ticker } from '../steps/ticker'

export async function endlessApp() {
await workflow(async () => {
await Promise.all([ticker(1000), ticker(500)])
await Promise.all([logs(), ticker(1000), ticker(500)])
})
}
3 changes: 3 additions & 0 deletions libs/steps/logs/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
}
18 changes: 18 additions & 0 deletions libs/steps/logs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/steps/logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# steps-logs

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

## Running unit tests

Run `nx test steps-logs` to execute the unit tests via [Jest](https://jestjs.io).

## Running lint

Run `nx lint steps-logs` to execute the lint via [ESLint](https://eslint.org/).
16 changes: 16 additions & 0 deletions libs/steps/logs/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: 'steps-logs',
preset: '../../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../../coverage/libs/steps/logs',
}
4 changes: 4 additions & 0 deletions libs/steps/logs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@ts-pipeline/step-logs",
"version": "0.0.1"
}
35 changes: 35 additions & 0 deletions libs/steps/logs/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "steps-logs",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/steps/logs/src",
"projectType": "library",
"targets": {
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/steps/logs/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/steps/logs/jest.config.ts",
"passWithNoTests": true
}
},
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/steps/logs",
"tsConfig": "libs/steps/logs/tsconfig.lib.json",
"packageJson": "libs/steps/logs/package.json",
"main": "libs/steps/logs/src/index.ts",
"assets": ["libs/steps/logs/*.md"]
}
}
},
"tags": ["step"]
}
3 changes: 3 additions & 0 deletions libs/steps/logs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @index(['./shared/**/*.(ts|tsx)', '!./**/*.d.(ts|tsx)'], f => `export * from '${f.path}'`)
export * from './shared/logs'
// @endindex
17 changes: 17 additions & 0 deletions libs/steps/logs/src/shared/logs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable no-console */
import { createStep } from '@ts-pipeline/core'

export const logs = createStep({
name: 'logs',
historySize: 50,
action: async ui => {
console.log = new Proxy(console.log, {
apply: (target, thisArg, argArray) => {
ui.onData(argArray.join(' '))
},
})
return new Promise(() => {
// endless
})
},
})
19 changes: 19 additions & 0 deletions libs/steps/logs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
11 changes: 11 additions & 0 deletions libs/steps/logs/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
20 changes: 20 additions & 0 deletions libs/steps/logs/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"baseUrl": ".",
"paths": {
"@ts-pipeline/core": ["libs/core/src/index.ts"],
"@ts-pipeline/step-logs": ["libs/steps/logs/src/index.ts"],
"@ts-pipeline/step-shell": ["libs/steps/shell/src/index.ts"],
"@ts-pipeline/ts-core": ["libs/ts-core/src/index.ts"]
}
Expand Down
1 change: 1 addition & 0 deletions workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": 2,
"projects": {
"core": "libs/core",
"steps-logs": "libs/steps/logs",
"steps-shell": "libs/steps/shell",
"ts-core": "libs/ts-core"
}
Expand Down

0 comments on commit 2b0b735

Please sign in to comment.