stonyx 0.0.5 → 0.0.7

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 CHANGED
@@ -28,7 +28,8 @@ db: {
28
28
  ```
29
29
  The above setting will expose the `log.db()` method, which will output in white.
30
30
  Alternatively you can provide a `logMethod` setting if you would rather use a different alias that
31
- does not match the class name.
31
+ does not match the class name, and `logTimestamp` as a true if you wish your log to include timestamp.
32
+ `stonyx/log` fully exposes the `chronicle` object. See Chronicle documentation for more information.
32
33
 
33
34
  ```js
34
35
  // environment.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stonyx",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "main.js",
6
6
  "type": "module",
@@ -28,7 +28,9 @@
28
28
  "url": "https://github.com/abofs/stonyx/issues"
29
29
  },
30
30
  "dependencies": {
31
- "@stonyx/utils": "^0.0.2",
32
31
  "node-chronicle": "^0.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@stonyx/utils": "^0.0.4"
33
35
  }
34
36
  }
package/src/main.js CHANGED
@@ -32,25 +32,37 @@ export default class Stonyx {
32
32
  if (!rootPath) throw new Error('Stonyx requires root project\'s path on startup');
33
33
 
34
34
  this.config = config;
35
+ this.chronicle = new Chronicle({ additionalLogs: { title: 'green' }});
35
36
 
36
37
  Stonyx.initialized = true;
37
38
 
38
- this.modules = await loadModules(config, rootPath);
39
- this.chronicle = new Chronicle({ additionalLogs: { title: 'green', ...this.classColorConfigs }});
39
+ this.modules = await loadModules(config, rootPath, this.chronicle);
40
+ this.configureUserLogs();
40
41
  }
41
42
 
42
- get classColorConfigs() {
43
- const colors = {};
43
+ /**
44
+ * Allows users to define their own log for any extra class via environment config
45
+ * {
46
+ * myClass: {
47
+ * logColor: 'purple',
48
+ * logMethod: 'highlight'
49
+ * logTimestamp: true
50
+ * }
51
+ & }
52
+ */
53
+ configureUserLogs() {
54
+ const { chronicle } = this;
44
55
 
45
56
  for (const [ className, config ] of Object.entries(this.config)) {
46
57
  if (!config || typeof config !== 'object') continue;
47
- if (!config.logColor) continue;
58
+ if (chronicle[className]) continue;
48
59
 
49
- const logMethod = config.logMethod || className;
50
- colors[logMethod] = config.logColor;
51
- }
60
+ const { logColor, logMethod, logTimestamp } = config;
61
+
62
+ if (!logColor) continue;
52
63
 
53
- return colors;
64
+ chronicle.defineType(logMethod || className, logColor, { logTimestamp: !!logTimestamp });
65
+ }
54
66
  }
55
67
 
56
68
  static get log() {
package/src/modules.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { readFile } from '@stonyx/utils/file';
6
6
 
7
- export default async (config, rootPath) => {
7
+ export default async (config, rootPath, chronicle) => {
8
8
  const modules = [];
9
9
  const initPromises = [];
10
10
  const rootPackage = await readFile(`${rootPath}/package.json`, { json: true });
@@ -30,12 +30,18 @@ export default async (config, rootPath) => {
30
30
  if (!keywords.includes('stonyx-async')) continue;
31
31
 
32
32
  try {
33
+
33
34
  // Load & Configure Async Modules
34
35
  const { default: moduleConfig } = await import(`${rootPath}/node_modules/${moduleName}/config/environment.js`);
35
36
 
36
37
  const module = moduleName.split('/').pop();
37
38
  const userConfig = config[module] || {};
38
- config[module] = { ...moduleConfig, ...userConfig };
39
+ const finalConfig = { ...moduleConfig, ...userConfig };
40
+ config[module] = finalConfig;
41
+
42
+ // Configure module-specific logging
43
+ const { logColor, logMethod, logTimestamp } = finalConfig;
44
+ if (logColor) chronicle.defineType(logMethod || module, logColor, { logTimestamp: !!logTimestamp });
39
45
 
40
46
  const { main: entryPoint } = modulePackage;
41
47
  const { default: moduleClass } = await import(`${rootPath}/node_modules/${moduleName}/${entryPoint}`);