@cocreate/config 1.9.0 → 1.10.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.10.0](https://github.com/CoCreate-app/CoCreate-config/compare/v1.9.0...v1.10.0) (2023-12-01)
2
+
3
+
4
+ ### Features
5
+
6
+ * get config using CoCreate-config ([d6e0b22](https://github.com/CoCreate-app/CoCreate-config/commit/d6e0b2266674c34582cdddc0f36f6836ba1c11f1))
7
+
1
8
  # [1.9.0](https://github.com/CoCreate-app/CoCreate-config/compare/v1.8.0...v1.9.0) (2023-11-25)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/config",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "A convenient chain handler allows user to chain multiple CoCreate components together. When one action is complete next one will start. The sequence goes untill all config completed. Grounded on Vanilla javascript, easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "config",
package/src/server.js CHANGED
@@ -4,6 +4,42 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const { dotNotationToObject, getValueFromObject } = require('@cocreate/utils');
6
6
 
7
+ /**
8
+ * Asynchronously retrieves configuration values. This function allows for
9
+ * fetching values from project-specific configuration, global configuration, or
10
+ * environment variables. Project configuration takes precedence over global and
11
+ * environment settings. It also supports interactive prompts to gather critical values
12
+ * from the user if they are not already defined in the configuration.
13
+ *
14
+ * @async
15
+ * @param {Object} items - An object representing the configuration items to retrieve.
16
+ * The keys are the config paths, and the values are objects
17
+ * specifying the prompt and any variable substitutions.
18
+ * @param {boolean} [env=true] - Flag to consider environment variables during config lookup.
19
+ * @param {boolean} [global=true] - Flag to consider global configuration during config lookup.
20
+ * @param {string} [configPath='CoCreate.config.js'] - Path to the project-specific configuration file.
21
+ * @returns {Promise<Object>} A promise that resolves with the configuration object.
22
+ *
23
+ * @example
24
+ * // Usage of the Config function
25
+ * async function initConfig() {
26
+ * this.config = await Config({
27
+ * 'organization_id': { prompt: 'Enter your organization_id: ' },
28
+ * 'storage': {
29
+ * prompt: 'Enter a friendly name for the new storage: ',
30
+ * variable: 'name'
31
+ * },
32
+ * 'storage.{{name}}.provider': {
33
+ * prompt: 'Enter the storage provider, ex mongodb: '
34
+ * },
35
+ * 'storage.{{name}}.url': {
36
+ * prompt: 'Enter the storage providers url: '
37
+ * }
38
+ * });
39
+ *
40
+ * const lazyLoadConfig = await Config('lazyload', false, false);
41
+ * }
42
+ */
7
43
  module.exports = async function (items, env = true, global = true, configPath = 'CoCreate.config.js') {
8
44
  async function promptForInput(question) {
9
45
  const rl = readline.createInterface({
@@ -38,6 +74,8 @@ module.exports = async function (items, env = true, global = true, configPath =
38
74
  let variables = {};
39
75
 
40
76
  async function getConfig(items) {
77
+ if (typeof items === 'string')
78
+ items = { [items]: '' }
41
79
  for (let key of Object.keys(items)) {
42
80
  let { value, prompt, choices, variable } = items[key];
43
81