modernx-logger 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # ModernX Logger
2
+
3
+ Redux logger plugin for ModernX applications, providing comprehensive debugging and state monitoring capabilities.
4
+
5
+ ## Features
6
+
7
+ - **Redux Integration**: Seamless integration with ModernX's Redux-based state management
8
+ - **Action Logging**: Real-time logging of all Redux actions with timestamps
9
+ - **State Visualization**: Visual display of state changes and diffs
10
+ - **Performance Monitoring**: Built-in performance tracking for actions
11
+ - **Customizable Options**: Configurable logging levels and formats
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install modernx-logger --save-dev
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Basic Setup
22
+
23
+ ```javascript
24
+ import modernx from 'modernx';
25
+ import logger from 'modernx-logger';
26
+
27
+ const app = modernx({
28
+ plugins: [logger()],
29
+ });
30
+ ```
31
+
32
+ ### Advanced Configuration
33
+
34
+ ```javascript
35
+ import modernx from 'modernx';
36
+ import logger from 'modernx-logger';
37
+
38
+ const app = modernx({
39
+ plugins: [
40
+ logger({
41
+ collapsed: true,
42
+ duration: true,
43
+ timestamp: true,
44
+ level: 'info',
45
+ colors: {
46
+ title: false,
47
+ prevState: false,
48
+ action: false,
49
+ nextState: false,
50
+ error: false,
51
+ },
52
+ }),
53
+ ],
54
+ });
55
+ ```
56
+
57
+ ### CLI Integration
58
+
59
+ When creating a new ModernX project, you can include the logger automatically:
60
+
61
+ ```bash
62
+ npx modernx create my-app --tools logger
63
+ ```
64
+
65
+ ## API Reference
66
+
67
+ ### Plugin Options
68
+
69
+ | Option | Type | Default | Description |
70
+ |--------|------|---------|-------------|
71
+ | `collapsed` | boolean | `true` | Collapse action groups |
72
+ | `duration` | boolean | `true` | Show action duration |
73
+ | `timestamp` | boolean | `true` | Include timestamp |
74
+ | `level` | string | `'log'` | Logging level |
75
+ | `colors` | object | `{}` | Custom color configuration |
76
+
77
+ ### Configuration Examples
78
+
79
+ #### Development Environment
80
+
81
+ ```javascript
82
+ logger({
83
+ collapsed: false,
84
+ duration: true,
85
+ timestamp: true,
86
+ level: 'debug',
87
+ colors: {
88
+ title: 'purple',
89
+ prevState: 'grey',
90
+ action: 'blue',
91
+ nextState: 'green',
92
+ error: 'red',
93
+ },
94
+ });
95
+ ```
96
+
97
+ #### Production Environment
98
+
99
+ ```javascript
100
+ logger({
101
+ collapsed: true,
102
+ duration: false,
103
+ timestamp: false,
104
+ level: 'error',
105
+ colors: false,
106
+ });
107
+ ```
108
+
109
+ ## Migration from DVA Logger
110
+
111
+ If you're migrating from DVA, the ModernX logger provides the same API:
112
+
113
+ ```javascript
114
+ // DVA Logger
115
+ import { createLogger } from 'dva-logger';
116
+
117
+ // ModernX Logger (API compatible)
118
+ import logger from 'modernx-logger';
119
+
120
+ // Usage is identical
121
+ const app = modernx({
122
+ plugins: [logger()],
123
+ });
124
+ ```
125
+
126
+ ## Development
127
+
128
+ ### Building
129
+
130
+ ```bash
131
+ npm run build
132
+ ```
133
+
134
+ ### Testing
135
+
136
+ ```bash
137
+ npm test
138
+ ```
139
+
140
+ ## License
141
+
142
+ MIT
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "modernx-logger",
3
+ "version": "1.1.1",
4
+ "description": "Redux logger plugin for modernx",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "sideEffects": false,
8
+ "dependencies": {
9
+ "@babel/runtime": "^7.20.0",
10
+ "redux-logger": "^3.0.6"
11
+ },
12
+ "peerDependencies": {
13
+ "modernx": "^1.0.0"
14
+ },
15
+ "devDependencies": {
16
+ "modernx": "1.1.1"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/perlinson/modernx/tree/master/packages/modernx-logger"
25
+ },
26
+ "homepage": "https://github.com/perlinson/modernx",
27
+ "author": "perlinson <perlinson2024@gmail.com>",
28
+ "keywords": [
29
+ "modernx",
30
+ "modernx-plugin",
31
+ "logger",
32
+ "redux"
33
+ ],
34
+ "license": "MIT",
35
+ "gitHead": "f14cf7c9309547fc2d9013ac8baa5495e2641750"
36
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { Middleware } from 'redux';
2
+
3
+ export interface LoggerOptions {
4
+ collapsed?: boolean;
5
+ duration?: boolean;
6
+ timestamp?: boolean;
7
+ level?: 'log' | 'debug' | 'info' | 'warn' | 'error';
8
+ colors?: {
9
+ title?: string | boolean;
10
+ prevState?: string | boolean;
11
+ action?: string | boolean;
12
+ nextState?: string | boolean;
13
+ error?: string | boolean;
14
+ };
15
+ logger?: {
16
+ log: (...args: any[]) => void;
17
+ warn: (...args: any[]) => void;
18
+ error: (...args: any[]) => void;
19
+ };
20
+ actionTransformer?: (action: any) => any;
21
+ stateTransformer?: (state: any) => any;
22
+ errorTransformer?: (error: any) => any;
23
+ predicate?: (getState: () => any, action: any) => boolean;
24
+ diffPredicate?: (getState: () => any, action: any) => boolean;
25
+ }
26
+
27
+ export interface ModernXLoggerPlugin {
28
+ _handleActions: (handlers: any, defaultState: any) => Middleware;
29
+ onAction: Middleware;
30
+ }
31
+
32
+ declare function modernxLogger(options?: LoggerOptions): ModernXLoggerPlugin;
33
+
34
+ export default modernxLogger;
package/src/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { createLogger } from 'redux-logger';
2
+
3
+ export default function(opts = {}) {
4
+ return {
5
+ _handleActions(handlers, defaultState) {
6
+ // Pass-through for action handlers
7
+ return (state = defaultState, action) => {
8
+ const { type } = action;
9
+ const handler = handlers[type];
10
+ if (handler) {
11
+ return handler(state, action);
12
+ }
13
+ return state;
14
+ };
15
+ },
16
+ onAction: createLogger({
17
+ collapsed: true,
18
+ duration: true,
19
+ timestamp: true,
20
+ ...opts,
21
+ }),
22
+ };
23
+ }