@cocreate/config 1.13.3 → 1.14.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/.github/workflows/automated.yml +23 -10
- package/.github/workflows/manual.yml +1 -2
- package/CHANGELOG.md +28 -0
- package/package.json +20 -13
- package/release.config.js +12 -4
- package/src/client.js +35 -16
- package/src/server.js +112 -82
- package/src/index.js +0 -14
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
name: Automated Workflow
|
|
2
|
+
|
|
2
3
|
on:
|
|
3
4
|
push:
|
|
4
5
|
branches:
|
|
5
6
|
- master
|
|
7
|
+
|
|
6
8
|
jobs:
|
|
7
9
|
about:
|
|
8
10
|
runs-on: ubuntu-latest
|
|
@@ -18,26 +20,37 @@ jobs:
|
|
|
18
20
|
with:
|
|
19
21
|
direction: overwrite-github
|
|
20
22
|
githubToken: "${{ secrets.GITHUB }}"
|
|
23
|
+
|
|
21
24
|
release:
|
|
22
25
|
runs-on: ubuntu-latest
|
|
23
26
|
steps:
|
|
24
27
|
- name: Checkout
|
|
25
28
|
uses: actions/checkout@v4
|
|
29
|
+
with:
|
|
30
|
+
fetch-depth: 0 # Required so semantic-release can trace git tags/history
|
|
31
|
+
|
|
26
32
|
- name: Setup Node.js
|
|
27
33
|
uses: actions/setup-node@v4
|
|
28
34
|
with:
|
|
29
|
-
node-version: 22
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@semantic-release/changelog
|
|
35
|
+
node-version: 22
|
|
36
|
+
|
|
37
|
+
- name: Install Semantic Release & Plugins
|
|
38
|
+
# Installs semantic-release and its plugins on the runner
|
|
39
|
+
run: |
|
|
40
|
+
npm install -g semantic-release \
|
|
41
|
+
@semantic-release/changelog \
|
|
42
|
+
@semantic-release/npm \
|
|
43
|
+
@semantic-release/github \
|
|
36
44
|
@semantic-release/git
|
|
37
|
-
|
|
45
|
+
|
|
46
|
+
- name: Run Semantic Release (Native)
|
|
47
|
+
id: semantic
|
|
48
|
+
# This will automatically pick up your export default config file in the repository root
|
|
49
|
+
run: npx semantic-release
|
|
38
50
|
env:
|
|
39
|
-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
|
51
|
+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
|
40
52
|
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
|
|
53
|
+
|
|
41
54
|
outputs:
|
|
42
55
|
new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
|
|
43
|
-
new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
|
|
56
|
+
new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.14.0](https://github.com/CoCreate-app/CoCreate-config/compare/v1.13.5...v1.14.0) (2026-07-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* update automated workflow and release configuration for improved semantic release handling ([6b991f0](https://github.com/CoCreate-app/CoCreate-config/commit/6b991f0a58b23964e22b64d4b780d5da16b0a59e))
|
|
7
|
+
|
|
8
|
+
## [1.13.5](https://github.com/CoCreate-app/CoCreate-config/compare/v1.13.4...v1.13.5) (2026-07-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* bump package versions ([4e62321](https://github.com/CoCreate-app/CoCreate-config/commit/4e623217d7355e95639c406dc2737f72c0270fb3))
|
|
14
|
+
* improve localStorage and cookie handling in get, set, and remove functions ([e6e4569](https://github.com/CoCreate-app/CoCreate-config/commit/e6e45699ee9e43ce8a7d452b9f287a83d76637c5))
|
|
15
|
+
* remove deprecated index.js file ([5e07438](https://github.com/CoCreate-app/CoCreate-config/commit/5e074389edb3b6b69c22211e1efaf94cb1874e6b))
|
|
16
|
+
* removed post install and add add packages to apprved list ([5ff4040](https://github.com/CoCreate-app/CoCreate-config/commit/5ff4040b39e2d346e21206304b603397dd40a029))
|
|
17
|
+
* semantic version handling ([d349cef](https://github.com/CoCreate-app/CoCreate-config/commit/d349cef4f4644ee53ea96f9a50a3fabbc5e46c7a))
|
|
18
|
+
* standardize cookie string concatenation in set and remove functions ([1a0dda3](https://github.com/CoCreate-app/CoCreate-config/commit/1a0dda32255fa3b523a49915262c4a897d29fdf0))
|
|
19
|
+
* update module export to ES6 syntax in release.config.js ([26284e2](https://github.com/CoCreate-app/CoCreate-config/commit/26284e2bcef427c9b260bef7b5996b24a77bf573))
|
|
20
|
+
* update package.json and refactor for module compatibility ([88b9a9c](https://github.com/CoCreate-app/CoCreate-config/commit/88b9a9c3047694d81d3b212ade49cd546d7aaebe))
|
|
21
|
+
|
|
22
|
+
## [1.13.4](https://github.com/CoCreate-app/CoCreate-config/compare/v1.13.3...v1.13.4) (2026-02-09)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* root factory variable Module ([d84e48b](https://github.com/CoCreate-app/CoCreate-config/commit/d84e48bd96ce77643f596a6a9a0cb483c8b45119))
|
|
28
|
+
|
|
1
29
|
## [1.13.3](https://github.com/CoCreate-app/CoCreate-config/compare/v1.13.2...v1.13.3) (2026-01-19)
|
|
2
30
|
|
|
3
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/config",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.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",
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "npx webpack --config webpack.config.js",
|
|
20
20
|
"build": "npx webpack --mode=production --config webpack.config.js",
|
|
21
|
-
"dev": "npx webpack --config webpack.config.js --watch"
|
|
22
|
-
"postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
|
|
21
|
+
"dev": "npx webpack --config webpack.config.js --watch"
|
|
23
22
|
},
|
|
24
23
|
"repository": {
|
|
25
24
|
"type": "git",
|
|
@@ -35,17 +34,25 @@
|
|
|
35
34
|
"type": "GitHub Sponsors ❤",
|
|
36
35
|
"url": "https://github.com/sponsors/CoCreate-app"
|
|
37
36
|
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
"type": "module",
|
|
38
|
+
"main": "./src/server.js",
|
|
39
|
+
"browser": "./src/client.js",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"node": "./src/server.js",
|
|
43
|
+
"deno": "./src/server.js",
|
|
44
|
+
"browser": "./src/client.js",
|
|
45
|
+
"default": "./src/server.js"
|
|
46
|
+
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@cocreate/utils": "^1.
|
|
49
|
+
"@cocreate/utils": "^1.42.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@cocreate/webpack": "^1.4.3"
|
|
53
|
+
},
|
|
54
|
+
"allowScripts": {
|
|
55
|
+
"@cocreate/utils@1.42.2": true,
|
|
56
|
+
"@cocreate/webpack@1.4.3": true
|
|
50
57
|
}
|
|
51
58
|
}
|
package/release.config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export default {
|
|
2
2
|
dryRun: false,
|
|
3
3
|
branches: ["master"],
|
|
4
4
|
plugins: [
|
|
@@ -10,12 +10,20 @@ module.exports = {
|
|
|
10
10
|
changelogFile: "CHANGELOG.md",
|
|
11
11
|
},
|
|
12
12
|
],
|
|
13
|
-
"@semantic-release/npm",
|
|
14
|
-
"@semantic-release/github",
|
|
13
|
+
"@semantic-release/npm",
|
|
15
14
|
[
|
|
16
|
-
"@semantic-release/
|
|
15
|
+
"@semantic-release/github",
|
|
17
16
|
{
|
|
17
|
+
successComment: false,
|
|
18
|
+
failTitle: false,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
"@semantic-release/git",
|
|
23
|
+
{
|
|
24
|
+
// Only stage and commit the changelog and package.json
|
|
18
25
|
assets: ["CHANGELOG.md", "package.json"],
|
|
26
|
+
message: "chore(release): ${nextRelease.version} [skip ci]",
|
|
19
27
|
},
|
|
20
28
|
],
|
|
21
29
|
],
|
package/src/client.js
CHANGED
|
@@ -2,22 +2,24 @@ import localStorage from '@cocreate/local-storage'
|
|
|
2
2
|
|
|
3
3
|
// Function to get a value by key from localStorage or cookies
|
|
4
4
|
function get(key) {
|
|
5
|
-
let value
|
|
6
|
-
value = localStorage.getItem(key)
|
|
7
|
-
|
|
8
5
|
if (window.CoCreateConfig && window.CoCreateConfig[key])
|
|
9
6
|
return window.CoCreateConfig[key]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
|
|
8
|
+
// try localStorage first
|
|
9
|
+
let value = localStorage.getItem(key)
|
|
10
|
+
if (value !== null && value !== undefined) return value
|
|
11
|
+
|
|
12
|
+
// fallback to cookie for server-read or legacy support
|
|
13
|
+
const cookies = (typeof document !== 'undefined' && document.cookie) ? document.cookie.split('; ') : [];
|
|
14
|
+
for (const cookie of cookies) {
|
|
15
|
+
const [cookieName, cookieValue] = cookie.split('=');
|
|
16
|
+
if (cookieName === key) {
|
|
17
|
+
// treat empty value as not present
|
|
18
|
+
if (!cookieValue || cookieValue === '') return null;
|
|
19
|
+
return decodeURIComponent(cookieValue || '');
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
return null
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// Function to set a key-value pair in localStorage or cookies
|
|
@@ -27,15 +29,32 @@ function set(key, value) {
|
|
|
27
29
|
else
|
|
28
30
|
window.CoCreateConfig[key] = value
|
|
29
31
|
localStorage.setItem(key, value)
|
|
30
|
-
|
|
32
|
+
// also set cookie for server-read or legacy support
|
|
33
|
+
try {
|
|
34
|
+
let cookie = key + "=" + encodeURIComponent(value) + "; path=/; SameSite=Lax";
|
|
35
|
+
if (typeof window !== "undefined" && window.location && window.location.protocol === "https:") {
|
|
36
|
+
cookie += "; Secure";
|
|
37
|
+
}
|
|
38
|
+
document.cookie = cookie;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
// ignore if document not available (e.g., SSR)
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
// Function to delete a key-value pair from localStorage or cookies
|
|
34
45
|
function remove(key) {
|
|
35
|
-
if
|
|
36
|
-
|
|
46
|
+
// remove from in-memory config if present
|
|
47
|
+
if (window.CoCreateConfig) delete window.CoCreateConfig[key]
|
|
48
|
+
// remove from localStorage
|
|
37
49
|
localStorage.removeItem(key)
|
|
38
|
-
|
|
50
|
+
// remove cookie as well
|
|
51
|
+
try {
|
|
52
|
+
const secure = (typeof window !== "undefined" && window.location && window.location.protocol === "https:") ? "; Secure" : "";
|
|
53
|
+
// overwrite with empty value first
|
|
54
|
+
document.cookie = key + "=; path=/; SameSite=Lax" + secure;
|
|
55
|
+
// then expire using Max-Age=0 for reliable deletion
|
|
56
|
+
document.cookie = key + "=; Max-Age=0; path=/; SameSite=Lax" + secure;
|
|
57
|
+
} catch (e) {}
|
|
39
58
|
}
|
|
40
59
|
|
|
41
60
|
export default { get, set, remove }
|
package/src/server.js
CHANGED
|
@@ -1,11 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2023 CoCreate and Contributors.
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
6
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*
|
|
17
|
+
********************************************************************************/
|
|
18
|
+
|
|
19
|
+
// Commercial Licensing Information:
|
|
20
|
+
// For commercial use of this software without the copyleft provisions of the AGPLv3,
|
|
21
|
+
// you must obtain a commercial license from CoCreate LLC.
|
|
22
|
+
// For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
|
|
23
|
+
|
|
24
|
+
import readline from 'node:readline';
|
|
25
|
+
import os from 'node:os';
|
|
26
|
+
import path from 'node:path';
|
|
27
|
+
import fs from 'node:fs';
|
|
28
|
+
import { promisify } from 'node:util';
|
|
29
|
+
import { exec as childExec } from 'node:child_process';
|
|
30
|
+
import { pathToFileURL } from 'node:url';
|
|
31
|
+
import { createRequire } from 'node:module';
|
|
7
32
|
|
|
8
|
-
|
|
33
|
+
import { dotNotationToObject, getValueFromObject } from '@cocreate/utils';
|
|
34
|
+
|
|
35
|
+
const exec = promisify(childExec);
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Helper function to dynamically load configurations.
|
|
40
|
+
* Handles both native ES modules and legacy CommonJS/JSON files safely.
|
|
41
|
+
* @param {string} filePath - Absolute path to the config file
|
|
42
|
+
* @returns {Promise<Object>} Evaluated configuration object
|
|
43
|
+
*/
|
|
44
|
+
async function loadConfig(filePath) {
|
|
45
|
+
if (!fs.existsSync(filePath)) return {};
|
|
46
|
+
try {
|
|
47
|
+
// Attempt native ESM dynamic import
|
|
48
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
49
|
+
const module = await import(fileUrl);
|
|
50
|
+
return module.default || module;
|
|
51
|
+
} catch (esmError) {
|
|
52
|
+
try {
|
|
53
|
+
// Fallback to Classic CommonJS / JSON Require compatibility
|
|
54
|
+
return require(filePath);
|
|
55
|
+
} catch (cjsError) {
|
|
56
|
+
console.error(`[@cocreate/config] Failed to load configuration at ${filePath}:`, esmError.message);
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
9
61
|
|
|
10
62
|
/**
|
|
11
63
|
* Asynchronously retrieves configuration values. This function allows for
|
|
@@ -15,35 +67,15 @@ const { dotNotationToObject, getValueFromObject } = require('@cocreate/utils');
|
|
|
15
67
|
* from the user if they are not already defined in the configuration.
|
|
16
68
|
*
|
|
17
69
|
* @async
|
|
18
|
-
* @param {Object} items - An object representing the configuration items to retrieve.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
70
|
+
* @param {Object|string} items - An object representing the configuration items to retrieve.
|
|
71
|
+
* The keys are the config paths, and the values are objects
|
|
72
|
+
* specifying the prompt and any variable substitutions.
|
|
21
73
|
* @param {boolean} [env=true] - Flag to consider environment variables during config lookup.
|
|
22
74
|
* @param {boolean} [global=true] - Flag to consider global configuration during config lookup.
|
|
23
75
|
* @param {string} [configPath='CoCreate.config.js'] - Path to the project-specific configuration file.
|
|
24
76
|
* @returns {Promise<Object>} A promise that resolves with the configuration object.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* // Usage of the Config function
|
|
28
|
-
* async function initConfig() {
|
|
29
|
-
* this.config = await Config({
|
|
30
|
-
* 'organization_id': { prompt: 'Enter your organization_id: ' },
|
|
31
|
-
* 'storage': {
|
|
32
|
-
* prompt: 'Enter a friendly name for the new storage: ',
|
|
33
|
-
* variable: 'name'
|
|
34
|
-
* },
|
|
35
|
-
* 'storage.{{name}}.provider': {
|
|
36
|
-
* prompt: 'Enter the storage provider, ex mongodb: '
|
|
37
|
-
* },
|
|
38
|
-
* 'storage.{{name}}.url': {
|
|
39
|
-
* prompt: 'Enter the storage providers url: '
|
|
40
|
-
* }
|
|
41
|
-
* });
|
|
42
|
-
*
|
|
43
|
-
* const lazyLoadConfig = await Config('lazyload', false, false);
|
|
44
|
-
* }
|
|
45
77
|
*/
|
|
46
|
-
|
|
78
|
+
export default async function config(items, env = true, global = true, configPath = 'CoCreate.config.js') {
|
|
47
79
|
async function promptForInput(question) {
|
|
48
80
|
const rl = readline.createInterface({
|
|
49
81
|
input: process.stdin,
|
|
@@ -81,50 +113,51 @@ module.exports = async function (items, env = true, global = true, configPath =
|
|
|
81
113
|
return value.$branch[stdout.trim()];
|
|
82
114
|
} catch (error) {
|
|
83
115
|
console.error(`exec error: ${error}`);
|
|
84
|
-
|
|
85
|
-
return null; // or a default value as per your logic
|
|
116
|
+
return null;
|
|
86
117
|
}
|
|
87
118
|
} else {
|
|
88
119
|
return value;
|
|
89
120
|
}
|
|
90
121
|
}
|
|
91
122
|
|
|
92
|
-
|
|
93
|
-
let config = {};
|
|
123
|
+
let configData = {};
|
|
94
124
|
let update = false;
|
|
95
125
|
let variables = {};
|
|
96
126
|
|
|
97
|
-
async function getConfig(
|
|
98
|
-
if (typeof
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
async function getConfig(targetItems) {
|
|
128
|
+
if (typeof targetItems === 'string') {
|
|
129
|
+
targetItems = { [targetItems]: '' };
|
|
130
|
+
}
|
|
131
|
+
for (let key of Object.keys(targetItems)) {
|
|
132
|
+
let { value, prompt, choices, variable } = targetItems[key];
|
|
102
133
|
|
|
103
134
|
const placeholders = key.match(/{{\s*([\w\W]+?)\s*}}/g);
|
|
104
135
|
if (placeholders && placeholders.length) {
|
|
105
136
|
for (let placeholder of placeholders) {
|
|
106
|
-
placeholder.trim()
|
|
107
|
-
if (variables[placeholder])
|
|
108
|
-
key = key.replace(placeholder, variables[placeholder])
|
|
137
|
+
placeholder.trim();
|
|
138
|
+
if (variables[placeholder]) {
|
|
139
|
+
key = key.replace(placeholder, variables[placeholder]);
|
|
140
|
+
}
|
|
109
141
|
}
|
|
110
142
|
}
|
|
111
143
|
|
|
112
144
|
if (choices) {
|
|
113
145
|
if (!prompt && prompt !== '') continue;
|
|
114
146
|
|
|
115
|
-
let isAnswered = false
|
|
147
|
+
let isAnswered = false;
|
|
116
148
|
for (let choice of Object.keys(choices)) {
|
|
117
|
-
let isAnsweredChoice = true
|
|
149
|
+
let isAnsweredChoice = true;
|
|
118
150
|
for (let choicekey of Object.keys(choices[choice])) {
|
|
119
|
-
let choiceValue = localConfig[choicekey] || globalConfig[choicekey]
|
|
151
|
+
let choiceValue = localConfig[choicekey] || globalConfig[choicekey];
|
|
120
152
|
if (choiceValue) {
|
|
121
|
-
|
|
122
|
-
} else
|
|
123
|
-
isAnsweredChoice = false
|
|
124
|
-
|
|
153
|
+
configData[choicekey] = choiceValue;
|
|
154
|
+
} else {
|
|
155
|
+
isAnsweredChoice = false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (isAnsweredChoice) {
|
|
159
|
+
isAnswered = true;
|
|
125
160
|
}
|
|
126
|
-
if (isAnsweredChoice)
|
|
127
|
-
isAnswered = true
|
|
128
161
|
}
|
|
129
162
|
|
|
130
163
|
if (!isAnswered) {
|
|
@@ -135,71 +168,68 @@ module.exports = async function (items, env = true, global = true, configPath =
|
|
|
135
168
|
}
|
|
136
169
|
}
|
|
137
170
|
} else if (variable) {
|
|
138
|
-
let variableValue = localConfig[key] || globalConfig[key]
|
|
171
|
+
let variableValue = localConfig[key] || globalConfig[key];
|
|
139
172
|
if (!variableValue) {
|
|
140
173
|
variables[`{{${variable}}}`] = value || await promptForInput(prompt || `${variable}: `);
|
|
141
174
|
} else {
|
|
142
|
-
variables[`{{${variable}}}`] = Object.keys(variableValue)[0]
|
|
175
|
+
variables[`{{${variable}}}`] = Object.keys(variableValue)[0];
|
|
143
176
|
}
|
|
144
177
|
} else {
|
|
145
178
|
if (value || value === "") {
|
|
146
|
-
|
|
147
|
-
if (global)
|
|
179
|
+
configData[key] = value;
|
|
180
|
+
if (global) {
|
|
148
181
|
update = true;
|
|
182
|
+
}
|
|
149
183
|
} else if (process.env[key]) {
|
|
150
|
-
|
|
151
|
-
config[key] = process.env[key];
|
|
184
|
+
configData[key] = process.env[key];
|
|
152
185
|
} else {
|
|
153
|
-
let localKey, globalKey
|
|
154
|
-
if (localKey = getValueFromObject(localConfig, key)) {
|
|
155
|
-
|
|
156
|
-
} else if (globalKey = getValueFromObject(globalConfig, key)) {
|
|
157
|
-
|
|
186
|
+
let localKey, globalKey;
|
|
187
|
+
if ((localKey = getValueFromObject(localConfig, key))) {
|
|
188
|
+
configData[key] = await getValue(localKey);
|
|
189
|
+
} else if ((globalKey = getValueFromObject(globalConfig, key))) {
|
|
190
|
+
configData[key] = await getValue(globalKey);
|
|
158
191
|
} else if (prompt || prompt === '') {
|
|
159
|
-
|
|
192
|
+
configData[key] = await promptForInput(prompt || `${key}: `);
|
|
160
193
|
if (global) update = true;
|
|
161
194
|
}
|
|
162
195
|
if (env) {
|
|
163
|
-
if (typeof
|
|
164
|
-
process.env[key] = JSON.stringify(
|
|
165
|
-
else
|
|
166
|
-
process.env[key] =
|
|
196
|
+
if (typeof configData[key] === 'object') {
|
|
197
|
+
process.env[key] = JSON.stringify(configData[key]);
|
|
198
|
+
} else {
|
|
199
|
+
process.env[key] = configData[key];
|
|
200
|
+
}
|
|
167
201
|
}
|
|
168
202
|
}
|
|
169
203
|
}
|
|
170
204
|
}
|
|
171
205
|
}
|
|
172
206
|
|
|
173
|
-
|
|
207
|
+
// Resolving paths and dynamically loading configurations with ESM wrappers
|
|
174
208
|
const localConfigPath = path.resolve(process.cwd(), configPath);
|
|
175
|
-
|
|
176
|
-
localConfig = require(localConfigPath);
|
|
177
|
-
}
|
|
209
|
+
const localConfig = await loadConfig(localConfigPath);
|
|
178
210
|
|
|
179
|
-
let globalConfig = {};
|
|
180
211
|
const globalConfigPath = path.resolve(os.homedir(), 'CoCreate.config.js');
|
|
181
|
-
|
|
182
|
-
globalConfig = require(globalConfigPath);
|
|
183
|
-
}
|
|
212
|
+
const globalConfig = await loadConfig(globalConfigPath);
|
|
184
213
|
|
|
185
214
|
if (items) {
|
|
186
215
|
await getConfig(items);
|
|
187
216
|
|
|
188
217
|
if (update) {
|
|
189
218
|
let updatedGlobalConfig = filterEmptyValues(
|
|
190
|
-
dotNotationToObject(
|
|
219
|
+
dotNotationToObject(configData, globalConfig)
|
|
191
220
|
);
|
|
192
221
|
|
|
193
|
-
|
|
222
|
+
// Updated to write modern ES module syntax "export default" instead of "module.exports"
|
|
223
|
+
const globalConfigString = `export default ${JSON.stringify(updatedGlobalConfig, null, 2)};\n`;
|
|
194
224
|
fs.writeFileSync(globalConfigPath, globalConfigString);
|
|
195
225
|
}
|
|
196
226
|
} else {
|
|
197
|
-
|
|
227
|
+
configData = {
|
|
198
228
|
...filterEmptyValues(globalConfig),
|
|
199
229
|
...filterEmptyValues(localConfig)
|
|
200
230
|
};
|
|
201
231
|
}
|
|
202
232
|
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
}
|
|
233
|
+
configData = dotNotationToObject(configData);
|
|
234
|
+
return configData;
|
|
235
|
+
}
|
package/src/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
(function (root, factory) {
|
|
2
|
-
if (typeof define === 'function' && define.amd) {
|
|
3
|
-
define(["./client"], function (CoCreateConfig) {
|
|
4
|
-
return factory(CoCreateConfig)
|
|
5
|
-
});
|
|
6
|
-
} else if (typeof module === 'object' && module.exports) {
|
|
7
|
-
const CoCreateConfig = require("./server.js")
|
|
8
|
-
module.exports = factory(CoCreateConfig);
|
|
9
|
-
} else {
|
|
10
|
-
root.returnExports = factory(root["./client.js"]);
|
|
11
|
-
}
|
|
12
|
-
}(typeof self !== 'undefined' ? self : this, function (CoCreateConfig) {
|
|
13
|
-
return CoCreateConfig;
|
|
14
|
-
}));
|